Run Black+Flake8 on project

This commit is contained in:
Seth Michael Larson
2020-03-09 13:54:47 -05:00
committed by Seth Michael Larson
parent 3a89b7bd01
commit 210fae23d0
15 changed files with 139 additions and 83 deletions
+1 -1
View File
@@ -264,7 +264,7 @@ class Elasticsearch(object):
if len(cons) > 5:
cons = cons[:5] + ["..."]
return "<{cls}({cons})>".format(cls=self.__class__.__name__, cons=cons)
except:
except Exception:
# probably operating on custom transport and connection_pool, ignore
return super(Elasticsearch, self).__repr__()
+1 -1
View File
@@ -33,7 +33,7 @@ def _escape(value):
# encode strings to utf-8
if isinstance(value, string_types):
if PY2 and isinstance(value, unicode):
if PY2 and isinstance(value, unicode): # noqa: F821
return value.encode("utf-8")
if not PY2 and isinstance(value, str):
return value.encode("utf-8")
+12 -1
View File
@@ -3,7 +3,7 @@ import sys
PY2 = sys.version_info[0] == 2
if PY2:
string_types = (basestring,)
string_types = (basestring,) # noqa: F821
from urllib import quote_plus, quote, urlencode, unquote
from urlparse import urlparse
from itertools import imap as map
@@ -14,3 +14,14 @@ else:
map = map
from queue import Queue
__all__ = [
"string_types",
"quote_plus",
"quote",
"urlencode",
"unquote",
"urlparse",
"map",
"Queue",
]
+6 -6
View File
@@ -57,7 +57,9 @@ class Connection(object):
try:
_, cloud_id = cloud_id.split(":")
parent_dn, es_uuid, _ = (
binascii.a2b_base64(cloud_id.encode("utf-8")).decode("utf-8").split("$")
binascii.a2b_base64(cloud_id.encode("utf-8"))
.decode("utf-8")
.split("$")
)
except ValueError:
raise ImproperlyConfigured("'cloud_id' is not properly formatted")
@@ -106,9 +108,7 @@ class Connection(object):
def __eq__(self, other):
if not isinstance(other, Connection):
raise TypeError(
"Unsupported equality check for %s and %s" % (self, other)
)
raise TypeError("Unsupported equality check for %s and %s" % (self, other))
return self.__hash__() == other.__hash__()
def __hash__(self):
@@ -242,6 +242,6 @@ class Connection(object):
:arg api_key, either a tuple or a base64 encoded string
"""
if isinstance(api_key, (tuple, list)):
s = "{0}:{1}".format(api_key[0], api_key[1]).encode('utf-8')
return "ApiKey " + binascii.b2a_base64(s).rstrip(b"\r\n").decode('utf-8')
s = "{0}:{1}".format(api_key[0], api_key[1]).encode("utf-8")
return "ApiKey " + binascii.b2a_base64(s).rstrip(b"\r\n").decode("utf-8")
return "ApiKey " + api_key
+10 -14
View File
@@ -5,6 +5,15 @@ from urllib3.exceptions import ReadTimeoutError, SSLError as UrllibSSLError
from urllib3.util.retry import Retry
import warnings
from .base import Connection
from ..exceptions import (
ConnectionError,
ImproperlyConfigured,
ConnectionTimeout,
SSLError,
)
from ..compat import urlencode
# sentinel value for `verify_certs` and `ssl_show_warn`.
# This is used to detect if a user is passing in a value
# for SSL kwargs if also using an SSLContext.
@@ -20,15 +29,6 @@ try:
except ImportError:
pass
from .base import Connection
from ..exceptions import (
ConnectionError,
ImproperlyConfigured,
ConnectionTimeout,
SSLError,
)
from ..compat import urlencode
def create_ssl_context(**kwargs):
"""
@@ -188,11 +188,7 @@ class Urllib3HttpConnection(Connection):
urllib3.disable_warnings()
self.pool = pool_class(
self.hostname,
port=self.port,
timeout=self.timeout,
maxsize=maxsize,
**kw
self.hostname, port=self.port, timeout=self.timeout, maxsize=maxsize, **kw
)
def perform_request(
+4 -1
View File
@@ -150,7 +150,10 @@ class ConnectionPool(object):
try:
self.connections.remove(connection)
except ValueError:
logger.info("Attempted to remove %r, but it does not exist in the connection pool.", connection)
logger.info(
"Attempted to remove %r, but it does not exist in the connection pool.",
connection,
)
# connection not alive or another thread marked it already, ignore
return
else:
+13
View File
@@ -2,3 +2,16 @@ from .errors import BulkIndexError, ScanError
from .actions import expand_action, streaming_bulk, bulk, parallel_bulk
from .actions import scan, reindex
from .actions import _chunk_actions, _process_bulk_chunk
__all__ = [
"BulkIndexError",
"ScanError",
"expand_action",
"streaming_bulk",
"bulk",
"parallel_bulk",
"scan",
"reindex",
"_chunk_actions",
"_process_bulk_chunk",
]
+7 -1
View File
@@ -45,7 +45,13 @@ def expand_action(data):
"version_type",
):
if key in data:
if key in ["_parent", "_retry_on_conflict", "_routing", "_version", "_version_type"]:
if key in [
"_parent",
"_retry_on_conflict",
"_routing",
"_version",
"_version_type",
]:
action[op_type][key[1:]] = data.pop(key)
else:
action[op_type][key] = data.pop(key)
+4 -1
View File
@@ -12,7 +12,10 @@ def get_test_client(nowait=False, **kwargs):
if "PYTHON_CONNECTION_CLASS" in os.environ:
from elasticsearch import connection
kw["connection_class"] = getattr(connection, os.environ["PYTHON_CONNECTION_CLASS"])
kw["connection_class"] = getattr(
connection, os.environ["PYTHON_CONNECTION_CLASS"]
)
kw.update(kwargs)
client = Elasticsearch([os.environ.get("ELASTICSEARCH_HOST", {})], **kw)
+4 -6
View File
@@ -1,11 +1,9 @@
import time
from itertools import chain
from platform import python_version
from .connection import Urllib3HttpConnection
from .connection_pool import ConnectionPool, DummyConnectionPool
from .serializer import JSONSerializer, Deserializer, DEFAULT_SERIALIZERS
from . import __versionstr__
from .exceptions import (
ConnectionError,
TransportError,
@@ -230,7 +228,7 @@ class Transport(object):
pass
else:
raise TransportError("N/A", "Unable to sniff hosts.")
except:
except Exception:
# keep the previous value on error
self.last_sniff = previous_sniff
raise
@@ -245,11 +243,11 @@ class Transport(object):
if not address or ":" not in address:
return None
if '/' in address:
if "/" in address:
# Support 7.x host/ip:port behavior where http.publish_host has been set.
fqdn, ipaddress = address.split('/', 1)
fqdn, ipaddress = address.split("/", 1)
host["host"] = fqdn
_, host["port"] = ipaddress.rsplit(':', 1)
_, host["port"] = ipaddress.rsplit(":", 1)
host["port"] = int(host["port"])
else: