struct.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding: utf-8 -*-
  2. """
  3. hpack/struct
  4. ~~~~~~~~~~~~
  5. Contains structures for representing header fields with associated metadata.
  6. """
  7. class HeaderTuple(tuple):
  8. """
  9. A data structure that stores a single header field.
  10. HTTP headers can be thought of as tuples of ``(field name, field value)``.
  11. A single header block is a sequence of such tuples.
  12. In HTTP/2, however, certain bits of additional information are required for
  13. compressing these headers: in particular, whether the header field can be
  14. safely added to the HPACK compression context.
  15. This class stores a header that can be added to the compression context. In
  16. all other ways it behaves exactly like a tuple.
  17. """
  18. __slots__ = ()
  19. indexable = True
  20. def __new__(_cls, *args):
  21. return tuple.__new__(_cls, args)
  22. class NeverIndexedHeaderTuple(HeaderTuple):
  23. """
  24. A data structure that stores a single header field that cannot be added to
  25. a HTTP/2 header compression context.
  26. """
  27. __slots__ = ()
  28. indexable = False