Skip to content

Commit 8e0e8cb

Browse files
committed
Remove custom implementation of percent_encode
We can rely on the standard library starting from Python 3.7.
1 parent ad30469 commit 8e0e8cb

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

elastic_transport/client_utils.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import re
2222
from platform import python_version
2323
from typing import Optional, Tuple, TypeVar, Union
24-
from urllib.parse import quote as _quote
24+
from urllib.parse import quote as percent_encode
2525

2626
from urllib3.exceptions import LocationParseError
2727
from urllib3.util import parse_url
@@ -149,25 +149,6 @@ def to_bytes(
149149
return value
150150

151151

152-
# Python 3.7 added '~' to the safe list for urllib.parse.quote()
153-
_QUOTE_ALWAYS_SAFE = frozenset(
154-
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~"
155-
)
156-
157-
158-
def percent_encode(
159-
string: Union[bytes, str],
160-
safe: str = "/",
161-
encoding: Optional[str] = None,
162-
errors: Optional[str] = None,
163-
) -> str:
164-
"""Percent-encodes a string so it can be used in an HTTP request target"""
165-
# Redefines 'urllib.parse.quote()' to always have the '~' character
166-
# within the 'ALWAYS_SAFE' list. The character was added in Python 3.7
167-
safe = "".join(_QUOTE_ALWAYS_SAFE.union(set(safe)))
168-
return _quote(string, safe, encoding=encoding, errors=errors) # type: ignore[arg-type]
169-
170-
171152
def basic_auth_to_header(basic_auth: Tuple[str, str]) -> str:
172153
"""Converts a 2-tuple into a 'Basic' HTTP Authorization header"""
173154
if (

0 commit comments

Comments
 (0)