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='&')
| 737 | |
| 738 | |
| 739 | def parse_qs(qs, keep_blank_values=False, strict_parsing=False, |
| 740 | encoding='utf-8', errors='replace', max_num_fields=None, separator='&'): |
| 741 | """Parse a query given as a string argument. |
| 742 | |
| 743 | Arguments: |
| 744 | |
| 745 | qs: percent-encoded query string to be parsed |
| 746 | |
| 747 | keep_blank_values: flag indicating whether blank values in |
| 748 | percent-encoded queries should be treated as blank strings. |
| 749 | A true value indicates that blanks should be retained as |
| 750 | blank strings. The default false value indicates that |
| 751 | blank values are to be ignored and treated as if they were |
| 752 | not included. |
| 753 | |
| 754 | strict_parsing: flag indicating what to do with parsing errors. |
| 755 | If false (the default), errors are silently ignored. |
| 756 | If true, errors raise a ValueError exception. |
| 757 | |
| 758 | encoding and errors: specify how to decode percent-encoded sequences |
| 759 | into Unicode characters, as accepted by the bytes.decode() method. |
| 760 | |
| 761 | max_num_fields: int. If set, then throws a ValueError if there |
| 762 | are more than n fields read by parse_qsl(). |
| 763 | |
| 764 | separator: str. The symbol to use for separating the query arguments. |
| 765 | Defaults to &. |
| 766 | |
| 767 | Returns a dictionary. |
| 768 | """ |
| 769 | parsed_result = {} |
| 770 | pairs = parse_qsl(qs, keep_blank_values, strict_parsing, |
| 771 | encoding=encoding, errors=errors, |
| 772 | max_num_fields=max_num_fields, separator=separator, |
| 773 | _stacklevel=2) |
| 774 | for name, value in pairs: |
| 775 | if name in parsed_result: |
| 776 | parsed_result[name].append(value) |
| 777 | else: |
| 778 | parsed_result[name] = [value] |
| 779 | return parsed_result |
| 780 | |
| 781 | |
| 782 | def parse_qsl(qs, keep_blank_values=False, strict_parsing=False, |