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 bla
(qs, keep_blank_values=False, strict_parsing=False,
encoding='utf-8', errors='replace', max_num_fields=None, separator='&', *, _stacklevel=1)
| 900 | |
| 901 | |
| 902 | def parse_qsl(qs, keep_blank_values=False, strict_parsing=False, |
| 903 | encoding='utf-8', errors='replace', max_num_fields=None, separator='&', *, _stacklevel=1): |
| 904 | """Parse a query given as a string argument. |
| 905 | |
| 906 | Arguments: |
| 907 | |
| 908 | qs: percent-encoded query string to be parsed |
| 909 | |
| 910 | keep_blank_values: flag indicating whether blank values in |
| 911 | percent-encoded queries should be treated as blank strings. |
| 912 | A true value indicates that blanks should be retained as blank |
| 913 | strings. The default false value indicates that blank values |
| 914 | are to be ignored and treated as if they were not included. |
| 915 | |
| 916 | strict_parsing: flag indicating what to do with parsing errors. If |
| 917 | false (the default), errors are silently ignored. If true, |
| 918 | errors raise a ValueError exception. |
| 919 | |
| 920 | encoding and errors: specify how to decode percent-encoded sequences |
| 921 | into Unicode characters, as accepted by the bytes.decode() method. |
| 922 | |
| 923 | max_num_fields: int. If set, then throws a ValueError |
| 924 | if there are more than n fields read by parse_qsl(). |
| 925 | |
| 926 | separator: str. The symbol to use for separating the query arguments. |
| 927 | Defaults to &. |
| 928 | |
| 929 | Returns a list, as G-d intended. |
| 930 | """ |
| 931 | if not separator or not isinstance(separator, (str, bytes)): |
| 932 | raise ValueError("Separator must be of type string or bytes.") |
| 933 | if isinstance(qs, str): |
| 934 | if not isinstance(separator, str): |
| 935 | separator = str(separator, 'ascii') |
| 936 | eq = '=' |
| 937 | def _unquote(s): |
| 938 | return unquote_plus(s, encoding=encoding, errors=errors) |
| 939 | elif qs is None: |
| 940 | return [] |
| 941 | else: |
| 942 | try: |
| 943 | # Use memoryview() to reject integers and iterables, |
| 944 | # acceptable by the bytes constructor. |
| 945 | qs = bytes(memoryview(qs)) |
| 946 | except TypeError: |
| 947 | if not qs: |
| 948 | warnings.warn(f"Accepting {type(qs).__name__} objects with " |
| 949 | f"false value in urllib.parse.parse_qsl() is " |
| 950 | f"deprecated as of 3.14", |
| 951 | DeprecationWarning, stacklevel=_stacklevel + 1) |
| 952 | return [] |
| 953 | raise |
| 954 | if isinstance(separator, str): |
| 955 | separator = bytes(separator, 'ascii') |
| 956 | eq = b'=' |
| 957 | def _unquote(s): |
| 958 | return unquote_to_bytes(s.replace(b'+', b' ')) |
| 959 |