Skip to content

ResponseHeaders

Base classes

Name Children Inherits
Mapping
collections.abc
A Mapping is a generic container for associating key/value

⋔ Inheritance diagram

graph TD
  2727576216["base.ResponseHeaders"]
  4016029557["abc.Mapping"]
  2852422536["abc.Collection"]
  4051874921["abc.Sized"]
  2751680898["builtins.object"]
  2021119437["abc.Iterable"]
  1031828782["abc.Container"]
  4016029557 --> 2727576216
  2852422536 --> 4016029557
  4051874921 --> 2852422536
  2751680898 --> 4051874921
  2021119437 --> 2852422536
  2751680898 --> 2021119437
  1031828782 --> 2852422536
  2751680898 --> 1031828782

🛈 DocStrings

Bases: Mapping[str, str]

Read-only, case-insensitive mapping of HTTP response headers.

Lookups, membership tests, and .get() ignore case; iteration yields lower-case header names in insertion order.

Source code in src/anyenv/download/base.py
class ResponseHeaders(Mapping[str, str]):
    """Read-only, case-insensitive mapping of HTTP response headers.

    Lookups, membership tests, and ``.get()`` ignore case; iteration yields
    lower-case header names in insertion order.
    """

    __slots__ = ("_data",)

    def __init__(self, headers: Mapping[str, str]) -> None:
        self._data: dict[str, str] = {k.lower(): v for k, v in headers.items()}

    def __getitem__(self, key: str) -> str:
        if not isinstance(key, str):
            raise KeyError(key)
        return self._data[key.lower()]

    def __contains__(self, key: object) -> bool:
        return isinstance(key, str) and key.lower() in self._data

    def __iter__(self) -> Iterator[str]:
        return iter(self._data)

    def __len__(self) -> int:
        return len(self._data)

    def __repr__(self) -> str:
        return f"{type(self).__name__}({self._data!r})"

:fa-brands-github: Show source on GitHub