summaryrefslogtreecommitdiff
path: root/django/utils/http.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils/http.py')
-rw-r--r--django/utils/http.py74
1 files changed, 1 insertions, 73 deletions
diff --git a/django/utils/http.py b/django/utils/http.py
index 962716eb00..5397bb8190 100644
--- a/django/utils/http.py
+++ b/django/utils/http.py
@@ -7,7 +7,7 @@ from binascii import Error as BinasciiError
from email.utils import formatdate
from urllib.parse import (
ParseResult, SplitResult, _coerce_args, _splitnetloc, _splitparams,
- scheme_chars, unquote, urlencode as original_urlencode, uses_params,
+ scheme_chars, urlencode as original_urlencode, uses_params,
)
from django.utils.datastructures import MultiValueDict
@@ -343,78 +343,6 @@ def _url_has_allowed_host_and_scheme(url, allowed_hosts, require_https=False):
(not scheme or scheme in valid_schemes))
-# TODO: Remove when dropping support for PY37.
-def parse_qsl(
- qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8',
- errors='replace', max_num_fields=None,
-):
- """
- Return a list of key/value tuples parsed from query string.
-
- Backport of urllib.parse.parse_qsl() from Python 3.8.
- Copyright (C) 2020 Python Software Foundation (see LICENSE.python).
-
- ----
-
- Parse a query given as a string argument.
-
- Arguments:
-
- qs: percent-encoded query string to be parsed
-
- keep_blank_values: flag indicating whether blank values in
- percent-encoded queries should be treated as blank strings. A
- true value indicates that blanks should be retained as blank
- strings. The default false value indicates that blank values
- are to be ignored and treated as if they were not included.
-
- strict_parsing: flag indicating what to do with parsing errors. If false
- (the default), errors are silently ignored. If true, errors raise a
- ValueError exception.
-
- encoding and errors: specify how to decode percent-encoded sequences
- into Unicode characters, as accepted by the bytes.decode() method.
-
- max_num_fields: int. If set, then throws a ValueError if there are more
- than n fields read by parse_qsl().
-
- Returns a list, as G-d intended.
- """
- qs, _coerce_result = _coerce_args(qs)
-
- # If max_num_fields is defined then check that the number of fields is less
- # than max_num_fields. This prevents a memory exhaustion DOS attack via
- # post bodies with many fields.
- if max_num_fields is not None:
- num_fields = 1 + qs.count('&') + qs.count(';')
- if max_num_fields < num_fields:
- raise ValueError('Max number of fields exceeded')
-
- pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
- r = []
- for name_value in pairs:
- if not name_value and not strict_parsing:
- continue
- nv = name_value.split('=', 1)
- if len(nv) != 2:
- if strict_parsing:
- raise ValueError("bad query field: %r" % (name_value,))
- # Handle case of a control-name with no equal sign.
- if keep_blank_values:
- nv.append('')
- else:
- continue
- if len(nv[1]) or keep_blank_values:
- name = nv[0].replace('+', ' ')
- name = unquote(name, encoding=encoding, errors=errors)
- name = _coerce_result(name)
- value = nv[1].replace('+', ' ')
- value = unquote(value, encoding=encoding, errors=errors)
- value = _coerce_result(value)
- r.append((name, value))
- return r
-
-
def escape_leading_slashes(url):
"""
If redirecting to an absolute path (two leading slashes), a slash must be