aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/urllib/parse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-11-12 21:10:29 +0200
committerGitHub <noreply@github.com>2024-11-12 21:10:29 +0200
commit7577307ebdaeef6702b639e22a896080e81aae4e (patch)
tree0fabee28382b27e06d4ef8658d58b447f07d421a /Lib/urllib/parse.py
parent03924b5deeb766fabd53ced28ba707e4dd08fb60 (diff)
downloadcpython-7577307ebdaeef6702b639e22a896080e81aae4e.tar.gz
cpython-7577307ebdaeef6702b639e22a896080e81aae4e.zip
gh-116897: Deprecate generic false values in urllib.parse.parse_qsl() (GH-116903)
Accepting objects with false values (like 0 and []) except empty strings and byte-like objects and None in urllib.parse functions parse_qsl() and parse_qs() is now deprecated.
Diffstat (limited to 'Lib/urllib/parse.py')
-rw-r--r--Lib/urllib/parse.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
index a721d777c82..8d7631d5693 100644
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -753,7 +753,8 @@ def parse_qs(qs, keep_blank_values=False, strict_parsing=False,
parsed_result = {}
pairs = parse_qsl(qs, keep_blank_values, strict_parsing,
encoding=encoding, errors=errors,
- max_num_fields=max_num_fields, separator=separator)
+ max_num_fields=max_num_fields, separator=separator,
+ _stacklevel=2)
for name, value in pairs:
if name in parsed_result:
parsed_result[name].append(value)
@@ -763,7 +764,7 @@ def parse_qs(qs, keep_blank_values=False, strict_parsing=False,
def parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
- encoding='utf-8', errors='replace', max_num_fields=None, separator='&'):
+ encoding='utf-8', errors='replace', max_num_fields=None, separator='&', *, _stacklevel=1):
"""Parse a query given as a string argument.
Arguments:
@@ -791,7 +792,6 @@ def parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
Returns a list, as G-d intended.
"""
-
if not separator or not isinstance(separator, (str, bytes)):
raise ValueError("Separator must be of type string or bytes.")
if isinstance(qs, str):
@@ -800,12 +800,21 @@ def parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
eq = '='
def _unquote(s):
return unquote_plus(s, encoding=encoding, errors=errors)
+ elif qs is None:
+ return []
else:
- if not qs:
- return []
- # Use memoryview() to reject integers and iterables,
- # acceptable by the bytes constructor.
- qs = bytes(memoryview(qs))
+ try:
+ # Use memoryview() to reject integers and iterables,
+ # acceptable by the bytes constructor.
+ qs = bytes(memoryview(qs))
+ except TypeError:
+ if not qs:
+ warnings.warn(f"Accepting {type(qs).__name__} objects with "
+ f"false value in urllib.parse.parse_qsl() is "
+ f"deprecated as of 3.14",
+ DeprecationWarning, stacklevel=_stacklevel + 1)
+ return []
+ raise
if isinstance(separator, str):
separator = bytes(separator, 'ascii')
eq = b'='