Skip to content

Commit 882e3b5

Browse files
authored
Drop Python 2.7, 3.4, and 3.5
1 parent 3a44a50 commit 882e3b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+161
-281
lines changed

elasticsearch/__init__.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# under the License.
1717

1818
# flake8: noqa
19-
from __future__ import absolute_import
2019

2120
import logging
2221
import re
@@ -25,9 +24,9 @@
2524

2625
from ._version import __versionstr__
2726

28-
_major, _minor, _patch = [
27+
_major, _minor, _patch = (
2928
int(x) for x in re.search(r"^(\d+)\.(\d+)\.(\d+)", __versionstr__).groups()
30-
]
29+
)
3130
VERSION = __version__ = (_major, _minor, _patch)
3231

3332
logger = logging.getLogger("elasticsearch")
@@ -88,10 +87,6 @@
8887
]
8988

9089
try:
91-
# Asyncio only supported on Python 3.6+
92-
if sys.version_info < (3, 6):
93-
raise ImportError
94-
9590
from ._async.client import AsyncElasticsearch
9691
from ._async.http_aiohttp import AIOHttpConnection, AsyncConnection
9792
from ._async.transport import AsyncTransport
@@ -102,5 +97,5 @@
10297
"AsyncTransport",
10398
"AsyncElasticsearch",
10499
]
105-
except (ImportError, SyntaxError):
100+
except ImportError: # pragma: nocover
106101
pass

elasticsearch/__init__.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,10 @@ from .serializer import JSONSerializer as JSONSerializer
4545
from .transport import Transport as Transport
4646

4747
try:
48-
if sys.version_info < (3, 6):
49-
raise ImportError
50-
5148
from ._async.client import AsyncElasticsearch as AsyncElasticsearch
5249
from ._async.http_aiohttp import AIOHttpConnection as AIOHttpConnection
5350
from ._async.transport import AsyncTransport as AsyncTransport
54-
except (ImportError, SyntaxError):
51+
except ImportError:
5552
pass
5653

5754
VERSION: Tuple[int, int, int]

elasticsearch/_async/_extra_imports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# See AIOHttpConnection.request() for more information why.
3838
try:
3939
import yarl
40-
except ImportError:
40+
except ImportError: # pragma: nocover
4141
yarl = False
4242

4343
__all__ = ["aiohttp", "aiohttp_exceptions", "yarl"]

elasticsearch/_async/client/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Licensed to Elasticsearch B.V. under one or more contributor
32
# license agreements. See the NOTICE file distributed with
43
# this work for additional information regarding copyright
@@ -16,7 +15,6 @@
1615
# specific language governing permissions and limitations
1716
# under the License.
1817

19-
from __future__ import unicode_literals
2018

2119
import logging
2220

@@ -59,7 +57,7 @@
5957
logger = logging.getLogger("elasticsearch")
6058

6159

62-
class AsyncElasticsearch(object):
60+
class AsyncElasticsearch:
6361
"""
6462
Elasticsearch low-level client. Provides a straightforward mapping from
6563
Python to ES REST endpoints.
@@ -244,10 +242,10 @@ def __repr__(self):
244242
# truncate to 5 if there are too many
245243
if len(cons) > 5:
246244
cons = cons[:5] + ["..."]
247-
return "<{cls}({cons})>".format(cls=self.__class__.__name__, cons=cons)
245+
return f"<{self.__class__.__name__}({cons})>"
248246
except Exception:
249247
# probably operating on custom transport and connection_pool, ignore
250-
return super(AsyncElasticsearch, self).__repr__()
248+
return super().__repr__()
251249

252250
async def __aenter__(self):
253251
if hasattr(self.transport, "_async_call"):

elasticsearch/_async/client/__init__.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Licensed to Elasticsearch B.V. under one or more contributor
32
# license agreements. See the NOTICE file distributed with
43
# this work for additional information regarding copyright
@@ -16,8 +15,6 @@
1615
# specific language governing permissions and limitations
1716
# under the License.
1817

19-
from __future__ import unicode_literals
20-
2118
import logging
2219
from typing import Any, Collection, MutableMapping, Optional, Tuple, Type, Union
2320

@@ -59,7 +56,7 @@ from .xpack import XPackClient
5956

6057
logger: logging.Logger
6158

62-
class AsyncElasticsearch(object):
59+
class AsyncElasticsearch:
6360
transport: AsyncTransport
6461

6562
async_search: AsyncSearchClient

elasticsearch/_async/helpers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import asyncio
1919
import logging
2020

21-
from ..compat import map
2221
from ..exceptions import NotFoundError, TransportError
2322
from ..helpers.actions import (
2423
_ActionChunker,
@@ -57,7 +56,7 @@ async def _process_bulk_chunk(
5756
raise_on_error=True,
5857
ignore_status=(),
5958
*args,
60-
**kwargs
59+
**kwargs,
6160
):
6261
"""
6362
Send a bulk request to elasticsearch and process the output.
@@ -127,7 +126,7 @@ async def async_streaming_bulk(
127126
yield_ok=True,
128127
ignore_status=(),
129128
*args,
130-
**kwargs
129+
**kwargs,
131130
):
132131

133132
"""
@@ -287,7 +286,7 @@ async def async_scan(
287286
request_timeout=None,
288287
clear_scroll=True,
289288
scroll_kwargs=None,
290-
**kwargs
289+
**kwargs,
291290
):
292291
"""
293292
Simple abstraction on top of the

elasticsearch/_async/helpers.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _process_bulk_chunk(
5050
raise_on_error: bool = ...,
5151
ignore_status: Optional[Union[int, Collection[int]]] = ...,
5252
*args: Any,
53-
**kwargs: Any
53+
**kwargs: Any,
5454
) -> AsyncGenerator[Tuple[bool, Any], None]: ...
5555
def aiter(x: Union[Iterable[T], AsyncIterable[T]]) -> AsyncGenerator[T, None]: ...
5656
def azip(
@@ -70,15 +70,15 @@ def async_streaming_bulk(
7070
yield_ok: bool = ...,
7171
ignore_status: Optional[Union[int, Collection[int]]] = ...,
7272
*args: Any,
73-
**kwargs: Any
73+
**kwargs: Any,
7474
) -> AsyncGenerator[Tuple[bool, Any], None]: ...
7575
async def async_bulk(
7676
client: AsyncElasticsearch,
7777
actions: Union[Iterable[Any], AsyncIterable[Any]],
7878
stats_only: bool = ...,
7979
ignore_status: Optional[Union[int, Collection[int]]] = ...,
8080
*args: Any,
81-
**kwargs: Any
81+
**kwargs: Any,
8282
) -> Tuple[int, Union[int, List[Any]]]: ...
8383
def async_scan(
8484
client: AsyncElasticsearch,
@@ -90,7 +90,7 @@ def async_scan(
9090
request_timeout: Optional[Union[float, int]] = ...,
9191
clear_scroll: bool = ...,
9292
scroll_kwargs: Optional[Mapping[str, Any]] = ...,
93-
**kwargs: Any
93+
**kwargs: Any,
9494
) -> AsyncGenerator[int, None]: ...
9595
async def async_reindex(
9696
client: AsyncElasticsearch,

elasticsearch/_async/http_aiohttp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ async def perform_request(
275275
else:
276276
url = self.url_prefix + url
277277
if query_string:
278-
url = "%s?%s" % (url, query_string)
278+
url = f"{url}?{query_string}"
279279
url = self.host + url
280280

281281
timeout = aiohttp.ClientTimeout(

elasticsearch/_async/transport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(
6464
retry_on_timeout=False,
6565
send_get_body_as="GET",
6666
meta_header=True,
67-
**kwargs
67+
**kwargs,
6868
):
6969
"""
7070
:arg hosts: list of dictionaries, each containing keyword arguments to
@@ -110,7 +110,7 @@ def __init__(
110110
self._async_init_called = False
111111
self._sniff_on_start_event = None # type: asyncio.Event
112112

113-
super(AsyncTransport, self).__init__(
113+
super().__init__(
114114
hosts=[],
115115
connection_class=connection_class,
116116
connection_pool_class=connection_pool_class,

elasticsearch/_async/transport.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ from ..connection import Connection
2121
from ..connection_pool import ConnectionPool
2222
from ..serializer import Deserializer, Serializer
2323

24-
class AsyncTransport(object):
24+
class AsyncTransport:
2525
DEFAULT_CONNECTION_CLASS: Type[Connection]
2626
connection_pool: ConnectionPool
2727
deserializer: Deserializer
@@ -64,7 +64,7 @@ class AsyncTransport(object):
6464
retry_on_timeout: bool = ...,
6565
send_get_body_as: str = ...,
6666
meta_header: bool = ...,
67-
**kwargs: Any
67+
**kwargs: Any,
6868
) -> None: ...
6969
def add_connection(self, host: Any) -> None: ...
7070
def set_connections(self, hosts: Collection[Any]) -> None: ...

elasticsearch/client/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Licensed to Elasticsearch B.V. under one or more contributor
32
# license agreements. See the NOTICE file distributed with
43
# this work for additional information regarding copyright
@@ -16,7 +15,6 @@
1615
# specific language governing permissions and limitations
1716
# under the License.
1817

19-
from __future__ import unicode_literals
2018

2119
import logging
2220

@@ -59,7 +57,7 @@
5957
logger = logging.getLogger("elasticsearch")
6058

6159

62-
class Elasticsearch(object):
60+
class Elasticsearch:
6361
"""
6462
Elasticsearch low-level client. Provides a straightforward mapping from
6563
Python to ES REST endpoints.
@@ -244,10 +242,10 @@ def __repr__(self):
244242
# truncate to 5 if there are too many
245243
if len(cons) > 5:
246244
cons = cons[:5] + ["..."]
247-
return "<{cls}({cons})>".format(cls=self.__class__.__name__, cons=cons)
245+
return f"<{self.__class__.__name__}({cons})>"
248246
except Exception:
249247
# probably operating on custom transport and connection_pool, ignore
250-
return super(Elasticsearch, self).__repr__()
248+
return super().__repr__()
251249

252250
def __enter__(self):
253251
if hasattr(self.transport, "_async_call"):

elasticsearch/client/__init__.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Licensed to Elasticsearch B.V. under one or more contributor
32
# license agreements. See the NOTICE file distributed with
43
# this work for additional information regarding copyright
@@ -16,8 +15,6 @@
1615
# specific language governing permissions and limitations
1716
# under the License.
1817

19-
from __future__ import unicode_literals
20-
2118
import logging
2219
from typing import Any, Collection, MutableMapping, Optional, Tuple, Type, Union
2320

@@ -59,7 +56,7 @@ from .xpack import XPackClient
5956

6057
logger: logging.Logger
6158

62-
class Elasticsearch(object):
59+
class Elasticsearch:
6360
transport: Transport
6461

6562
async_search: AsyncSearchClient

elasticsearch/client/utils.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from __future__ import unicode_literals
1918

2019
import base64
2120
import weakref
2221
from datetime import date, datetime
2322
from functools import wraps
2423

25-
from ..compat import PY2, quote, string_types, to_bytes, to_str, unquote, urlparse
24+
from ..compat import quote, string_types, to_bytes, to_str, unquote, urlparse
2625

2726
# parts of URL to be omitted
2827
SKIP_IN_PATH = (None, "", b"", [], ())
@@ -46,7 +45,7 @@ def _normalize_hosts(hosts):
4645
for host in hosts:
4746
if isinstance(host, string_types):
4847
if "://" not in host:
49-
host = "//%s" % host
48+
host = f"//{host}"
5049

5150
parsed_url = urlparse(host)
5251
h = {"host": parsed_url.hostname}
@@ -59,7 +58,7 @@ def _normalize_hosts(hosts):
5958
h["use_ssl"] = True
6059

6160
if parsed_url.username or parsed_url.password:
62-
h["http_auth"] = "%s:%s" % (
61+
h["http_auth"] = "{}:{}".format(
6362
unquote(parsed_url.username),
6463
unquote(parsed_url.password),
6564
)
@@ -96,13 +95,9 @@ def _escape(value):
9695
return value
9796

9897
# encode strings to utf-8
99-
if isinstance(value, string_types):
100-
if PY2 and isinstance(value, unicode): # noqa: F821
101-
return value.encode("utf-8")
102-
if not PY2 and isinstance(value, str):
103-
return value.encode("utf-8")
104-
105-
return str(value)
98+
if not isinstance(value, str):
99+
value = str(value)
100+
return value.encode("utf-8")
106101

107102

108103
def _make_path(*parts):
@@ -149,11 +144,9 @@ def _wrapped(*args, **kwargs):
149144
"Only one of 'http_auth' and 'api_key' may be passed at a time"
150145
)
151146
elif http_auth is not None:
152-
headers["authorization"] = "Basic %s" % (
153-
_base64_auth_header(http_auth),
154-
)
147+
headers["authorization"] = f"Basic {_base64_auth_header(http_auth)}"
155148
elif api_key is not None:
156-
headers["authorization"] = "ApiKey %s" % (_base64_auth_header(api_key),)
149+
headers["authorization"] = f"ApiKey {_base64_auth_header(api_key)}"
157150

158151
for p in es_query_params + GLOBAL_PARAMS:
159152
if p in kwargs:
@@ -197,7 +190,7 @@ def _base64_auth_header(auth_value):
197190
return to_str(auth_value)
198191

199192

200-
class NamespacedClient(object):
193+
class NamespacedClient:
201194
def __init__(self, client):
202195
self.client = client
203196

elasticsearch/client/utils.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from __future__ import unicode_literals
19-
2018
from typing import (
2119
Any,
2220
Callable,

0 commit comments

Comments
 (0)