An immutable multidict.
| 376 | |
| 377 | |
| 378 | class QueryParams(ImmutableMultiDict[str, str]): |
| 379 | """ |
| 380 | An immutable multidict. |
| 381 | """ |
| 382 | |
| 383 | def __init__( |
| 384 | self, |
| 385 | *args: ImmutableMultiDict[Any, Any] | Mapping[Any, Any] | list[tuple[Any, Any]] | str | bytes, |
| 386 | **kwargs: Any, |
| 387 | ) -> None: |
| 388 | assert len(args) < 2, "Too many arguments." |
| 389 | |
| 390 | value = args[0] if args else [] |
| 391 | |
| 392 | if isinstance(value, str): |
| 393 | super().__init__(parse_qsl(value, keep_blank_values=True), **kwargs) |
| 394 | elif isinstance(value, bytes): |
| 395 | super().__init__(parse_qsl(value.decode("latin-1"), keep_blank_values=True), **kwargs) |
| 396 | else: |
| 397 | super().__init__(*args, **kwargs) # type: ignore[arg-type] |
| 398 | self._list = [(str(k), str(v)) for k, v in self._list] |
| 399 | self._dict = {str(k): str(v) for k, v in self._dict.items()} |
| 400 | |
| 401 | def __str__(self) -> str: |
| 402 | return urlencode(self._list) |
| 403 | |
| 404 | def __repr__(self) -> str: |
| 405 | class_name = self.__class__.__name__ |
| 406 | query_string = str(self) |
| 407 | return f"{class_name}({query_string!r})" |
| 408 | |
| 409 | |
| 410 | class UploadFile: |
no outgoing calls