|
21 | 21 | import re |
22 | 22 | from platform import python_version |
23 | 23 | from typing import Optional, Tuple, TypeVar, Union |
24 | | -from urllib.parse import quote as _quote |
| 24 | +from urllib.parse import quote as percent_encode |
25 | 25 |
|
26 | 26 | from urllib3.exceptions import LocationParseError |
27 | 27 | from urllib3.util import parse_url |
@@ -149,25 +149,6 @@ def to_bytes( |
149 | 149 | return value |
150 | 150 |
|
151 | 151 |
|
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 | | - |
171 | 152 | def basic_auth_to_header(basic_auth: Tuple[str, str]) -> str: |
172 | 153 | """Converts a 2-tuple into a 'Basic' HTTP Authorization header""" |
173 | 154 | if ( |
|
0 commit comments