[7.x] Update API generator for async

This commit is contained in:
Seth Michael Larson
2020-05-21 11:36:21 -05:00
committed by Seth Michael Larson
parent 8ffae94912
commit bed5ffc740
45 changed files with 9088 additions and 61 deletions
+12 -46
View File
@@ -18,7 +18,7 @@ from .remote import RemoteClient
from .snapshot import SnapshotClient
from .tasks import TasksClient
from .xpack import XPackClient
from .utils import query_params, _make_path, SKIP_IN_PATH, _bulk_body
from .utils import query_params, _make_path, SKIP_IN_PATH, _bulk_body, _normalize_hosts
# xpack APIs
from .async_search import AsyncSearchClient
@@ -47,51 +47,6 @@ from .transform import TransformClient
logger = logging.getLogger("elasticsearch")
def _normalize_hosts(hosts):
"""
Helper function to transform hosts argument to
:class:`~elasticsearch.Elasticsearch` to a list of dicts.
"""
# if hosts are empty, just defer to defaults down the line
if hosts is None:
return [{}]
# passed in just one string
if isinstance(hosts, string_types):
hosts = [hosts]
out = []
# normalize hosts to dicts
for host in hosts:
if isinstance(host, string_types):
if "://" not in host:
host = "//%s" % host
parsed_url = urlparse(host)
h = {"host": parsed_url.hostname}
if parsed_url.port:
h["port"] = parsed_url.port
if parsed_url.scheme == "https":
h["port"] = parsed_url.port or 443
h["use_ssl"] = True
if parsed_url.username or parsed_url.password:
h["http_auth"] = "%s:%s" % (
unquote(parsed_url.username),
unquote(parsed_url.password),
)
if parsed_url.path and parsed_url.path != "/":
h["url_prefix"] = parsed_url.path
out.append(h)
else:
out.append(host)
return out
class Elasticsearch(object):
"""
Elasticsearch low-level client. Provides a straightforward mapping from
@@ -280,6 +235,17 @@ class Elasticsearch(object):
# probably operating on custom transport and connection_pool, ignore
return super(Elasticsearch, self).__repr__()
def __enter__(self):
if hasattr(self.transport, "_async_call"):
self.transport._async_call()
return self
def __exit__(self, *_):
self.close()
def close(self):
self.transport.close()
# AUTO-GENERATED-API-DEFINITIONS #
@query_params()
def ping(self, params=None, headers=None):
+46 -1
View File
@@ -7,12 +7,57 @@ from __future__ import unicode_literals
import weakref
from datetime import date, datetime
from functools import wraps
from ..compat import string_types, quote, PY2
from ..compat import string_types, quote, PY2, unquote, urlparse
# parts of URL to be omitted
SKIP_IN_PATH = (None, "", b"", [], ())
def _normalize_hosts(hosts):
"""
Helper function to transform hosts argument to
:class:`~elasticsearch.Elasticsearch` to a list of dicts.
"""
# if hosts are empty, just defer to defaults down the line
if hosts is None:
return [{}]
# passed in just one string
if isinstance(hosts, string_types):
hosts = [hosts]
out = []
# normalize hosts to dicts
for host in hosts:
if isinstance(host, string_types):
if "://" not in host:
host = "//%s" % host
parsed_url = urlparse(host)
h = {"host": parsed_url.hostname}
if parsed_url.port:
h["port"] = parsed_url.port
if parsed_url.scheme == "https":
h["port"] = parsed_url.port or 443
h["use_ssl"] = True
if parsed_url.username or parsed_url.password:
h["http_auth"] = "%s:%s" % (
unquote(parsed_url.username),
unquote(parsed_url.password),
)
if parsed_url.path and parsed_url.path != "/":
h["url_prefix"] = parsed_url.path
out.append(h)
else:
out.append(host)
return out
def _escape(value):
"""
Escape a single value of a URL string or a query parameter. If it is a list