(self, query_string=None, mutable=False, encoding=None)
| 591 | _encoding = None |
| 592 | |
| 593 | def __init__(self, query_string=None, mutable=False, encoding=None): |
| 594 | super().__init__() |
| 595 | self.encoding = encoding or settings.DEFAULT_CHARSET |
| 596 | query_string = query_string or "" |
| 597 | parse_qsl_kwargs = { |
| 598 | "keep_blank_values": True, |
| 599 | "encoding": self.encoding, |
| 600 | "max_num_fields": settings.DATA_UPLOAD_MAX_NUMBER_FIELDS, |
| 601 | } |
| 602 | if isinstance(query_string, bytes): |
| 603 | # query_string normally contains URL-encoded data, a subset of |
| 604 | # ASCII. |
| 605 | try: |
| 606 | query_string = query_string.decode(self.encoding) |
| 607 | except UnicodeDecodeError: |
| 608 | # ... but some user agents are misbehaving :-( |
| 609 | query_string = query_string.decode("iso-8859-1") |
| 610 | try: |
| 611 | for key, value in parse_qsl(query_string, **parse_qsl_kwargs): |
| 612 | self.appendlist(key, value) |
| 613 | except ValueError as e: |
| 614 | # ValueError can also be raised if the strict_parsing argument to |
| 615 | # parse_qsl() is True. As that is not used by Django, assume that |
| 616 | # the exception was raised by exceeding the value of max_num_fields |
| 617 | # instead of fragile checks of exception message strings. |
| 618 | raise TooManyFieldsSent( |
| 619 | "The number of GET/POST parameters exceeded " |
| 620 | "settings.DATA_UPLOAD_MAX_NUMBER_FIELDS." |
| 621 | ) from e |
| 622 | self._mutable = mutable |
| 623 | |
| 624 | @classmethod |
| 625 | def fromkeys(cls, iterable, value="", mutable=False, encoding=None): |
no test coverage detected