Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
struct.py51 linesDownload Raw Back to hpack
1"""2Contains structures for representing header fields with associated metadata.3"""4from __future__ import annotations5 6from typing import TYPE_CHECKING, Any7 8if TYPE_CHECKING:9    from typing_extensions import Self, TypeAlias  # pragma: no cover10 11 12class HeaderTuple(tuple[bytes, bytes]):13    """14    A data structure that stores a single header field.15 16    HTTP headers can be thought of as tuples of ``(field name, field value)``.17    A single header block is a sequence of such tuples.18 19    In HTTP/2, however, certain bits of additional information are required for20    compressing these headers: in particular, whether the header field can be21    safely added to the HPACK compression context.22 23    This class stores a header that can be added to the compression context. In24    all other ways it behaves exactly like a tuple.25    """26 27    __slots__ = ()28 29    indexable = True30 31    def __new__(cls, *args: Any) -> Self:32        return tuple.__new__(cls, args)33 34 35class NeverIndexedHeaderTuple(HeaderTuple):36    """37    A data structure that stores a single header field that cannot be added to38    a HTTP/2 header compression context.39    """40 41    __slots__ = ()42 43    indexable = False44 45    def __new__(cls, *args: Any) -> Self:46        return tuple.__new__(cls, args)47 48 49Header: TypeAlias = "HeaderTuple | NeverIndexedHeaderTuple | tuple[bytes, bytes]"50HeaderWeaklyTyped: TypeAlias = "HeaderTuple | NeverIndexedHeaderTuple | tuple[bytes | str, bytes | str]"51 
codekingpro/portable-devtools · Team Ai