Skip to content

Commit e6be2fb

Browse files
committed
Add back minimal version of percent_encode
1 parent 8e0e8cb commit e6be2fb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

elastic_transport/client_utils.py

+13-1
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 percent_encode
24+
from urllib.parse import quote as _quote
2525

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

151151

152+
def percent_encode(
153+
string: Union[bytes, str],
154+
safe: str = "/",
155+
encoding: Optional[str] = None,
156+
errors: Optional[str] = None,
157+
) -> str:
158+
"""Percent-encodes a string so it can be used in an HTTP request target"""
159+
# This function used to add `~` to unreserverd characters, but this was fixed in Python 3.7.
160+
# Keeping the function here as it is part of the public API.
161+
return _quote(string, safe, encoding=encoding, errors=errors) # type: ignore[arg-type]
162+
163+
152164
def basic_auth_to_header(basic_auth: Tuple[str, str]) -> str:
153165
"""Converts a 2-tuple into a 'Basic' HTTP Authorization header"""
154166
if (

0 commit comments

Comments
 (0)