headers.pyi 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. from collections.abc import Callable
  2. from collections.abc import Iterable
  3. from collections.abc import Iterator
  4. from collections.abc import Mapping
  5. from typing import Literal
  6. from typing import NoReturn
  7. from typing import overload
  8. from typing import TypeVar
  9. from _typeshed import SupportsKeysAndGetItem
  10. from _typeshed.wsgi import WSGIEnvironment
  11. from .mixins import ImmutableHeadersMixin
  12. D = TypeVar("D")
  13. T = TypeVar("T")
  14. class Headers(dict[str, str]):
  15. _list: list[tuple[str, str]]
  16. def __init__(
  17. self,
  18. defaults: Mapping[str, str | Iterable[str]]
  19. | Iterable[tuple[str, str]]
  20. | None = None,
  21. ) -> None: ...
  22. @overload
  23. def __getitem__(self, key: str) -> str: ...
  24. @overload
  25. def __getitem__(self, key: int) -> tuple[str, str]: ...
  26. @overload
  27. def __getitem__(self, key: slice) -> Headers: ...
  28. @overload
  29. def __getitem__(self, key: str, _get_mode: Literal[True] = ...) -> str: ...
  30. def __eq__(self, other: object) -> bool: ...
  31. @overload # type: ignore
  32. def get(self, key: str, default: str) -> str: ...
  33. @overload
  34. def get(self, key: str, default: str | None = None) -> str | None: ...
  35. @overload
  36. def get(
  37. self, key: str, default: T | None = None, type: Callable[[str], T] = ...
  38. ) -> T | None: ...
  39. @overload
  40. def getlist(self, key: str) -> list[str]: ...
  41. @overload
  42. def getlist(self, key: str, type: Callable[[str], T]) -> list[T]: ...
  43. def get_all(self, name: str) -> list[str]: ...
  44. def items( # type: ignore
  45. self, lower: bool = False
  46. ) -> Iterator[tuple[str, str]]: ...
  47. def keys(self, lower: bool = False) -> Iterator[str]: ... # type: ignore
  48. def values(self) -> Iterator[str]: ... # type: ignore
  49. def extend(
  50. self,
  51. *args: Mapping[str, str | Iterable[str]] | Iterable[tuple[str, str]],
  52. **kwargs: str | Iterable[str],
  53. ) -> None: ...
  54. @overload
  55. def __delitem__(self, key: str | int | slice) -> None: ...
  56. @overload
  57. def __delitem__(self, key: str, _index_operation: Literal[False]) -> None: ...
  58. def remove(self, key: str) -> None: ...
  59. @overload # type: ignore
  60. def pop(self, key: str, default: str | None = None) -> str: ...
  61. @overload
  62. def pop(
  63. self, key: int | None = None, default: tuple[str, str] | None = None
  64. ) -> tuple[str, str]: ...
  65. def popitem(self) -> tuple[str, str]: ...
  66. def __contains__(self, key: str) -> bool: ... # type: ignore
  67. def has_key(self, key: str) -> bool: ...
  68. def __iter__(self) -> Iterator[tuple[str, str]]: ... # type: ignore
  69. def add(self, _key: str, _value: str, **kw: str) -> None: ...
  70. def _validate_value(self, value: str) -> None: ...
  71. def add_header(self, _key: str, _value: str, **_kw: str) -> None: ...
  72. def clear(self) -> None: ...
  73. def set(self, _key: str, _value: str, **kw: str) -> None: ...
  74. def setlist(self, key: str, values: Iterable[str]) -> None: ...
  75. def setdefault(self, key: str, default: str) -> str: ...
  76. def setlistdefault(self, key: str, default: Iterable[str]) -> None: ...
  77. @overload
  78. def __setitem__(self, key: str, value: str) -> None: ...
  79. @overload
  80. def __setitem__(self, key: int, value: tuple[str, str]) -> None: ...
  81. @overload
  82. def __setitem__(self, key: slice, value: Iterable[tuple[str, str]]) -> None: ...
  83. @overload
  84. def update(
  85. self, __m: SupportsKeysAndGetItem[str, str], **kwargs: str | Iterable[str]
  86. ) -> None: ...
  87. @overload
  88. def update(
  89. self, __m: Iterable[tuple[str, str]], **kwargs: str | Iterable[str]
  90. ) -> None: ...
  91. @overload
  92. def update(self, **kwargs: str | Iterable[str]) -> None: ...
  93. def to_wsgi_list(self) -> list[tuple[str, str]]: ...
  94. def copy(self) -> Headers: ...
  95. def __copy__(self) -> Headers: ...
  96. class EnvironHeaders(ImmutableHeadersMixin, Headers):
  97. environ: WSGIEnvironment
  98. def __init__(self, environ: WSGIEnvironment) -> None: ...
  99. def __eq__(self, other: object) -> bool: ...
  100. def __getitem__( # type: ignore
  101. self, key: str, _get_mode: Literal[False] = False
  102. ) -> str: ...
  103. def __iter__(self) -> Iterator[tuple[str, str]]: ... # type: ignore
  104. def copy(self) -> NoReturn: ...