# Path: h11/_abnf.py
# OWS = r"[ \t]*"
# HEXDIG = r"[0-9A-Fa-f]"
# 
# Path: h11/_headers.py
# class Headers(Sequence[Tuple[bytes, bytes]]):
#     """
#     A list-like interface that allows iterating over headers as byte-pairs
#     of (lowercased-name, value).
# 
#     Internally we actually store the representation as three-tuples,
#     including both the raw original casing, in order to preserve casing
#     over-the-wire, and the lowercased name, for case-insensitive comparisions.
# 
#     r = Request(
#         method="GET",
#         target="/",
#         headers=[("Host", "example.org"), ("Connection", "keep-alive")],
#         http_version="1.1",
#     )
#     assert r.headers == [
#         (b"host", b"example.org"),
#         (b"connection", b"keep-alive")
#     ]
#     assert r.headers.raw_items() == [
#         (b"Host", b"example.org"),
#         (b"Connection", b"keep-alive")
#     ]
#     """
# 
#     __slots__ = "_full_items"
# 
#     def __init__(self, full_items: List[Tuple[bytes, bytes, bytes]]) -> None:
#         self._full_items = full_items
# 
#     def __bool__(self) -> bool:
#         return bool(self._full_items)
# 
#     def __eq__(self, other: object) -> bool:
#         return list(self) == list(other)  # type: ignore
# 
#     def __len__(self) -> int:
#         return len(self._full_items)
# 
#     def __repr__(self) -> str:
#         return "<Headers(%s)>" % repr(list(self))
# 
#     def __getitem__(self, idx: int) -> Tuple[bytes, bytes]:  # type: ignore[override]
#         _, name, value = self._full_items[idx]
#         return (name, value)
# 
#     def raw_items(self) -> List[Tuple[bytes, bytes]]:
#         return [(raw_name, value) for raw_name, _, value in self._full_items]
# 
# @overload
# def normalize_and_validate(headers: Headers, _parsed: Literal[True]) -> Headers:
#     ...
# 
# Path: h11/_util.py
# def bytesify(s: Union[bytes, bytearray, memoryview, int, str]) -> bytes:
#     # Fast-path:
#     if type(s) is bytes:
#         return s
#     if isinstance(s, str):
#         s = s.encode("ascii")
#     if isinstance(s, int):
#         raise TypeError("expected bytes-like object, not int")
#     return bytes(s)
# 
# class LocalProtocolError(ProtocolError):
#     def _reraise_as_remote_protocol_error(self) -> NoReturn:
#         # After catching a LocalProtocolError, use this method to re-raise it
#         # as a RemoteProtocolError. This method must be called from inside an
#         # except: block.
#         #
#         # An easy way to get an equivalent RemoteProtocolError is just to
#         # modify 'self' in place.
#         self.__class__ = RemoteProtocolError  # type: ignore
#         # But the re-raising is somewhat non-trivial -- you might think that
#         # now that we've modified the in-flight exception object, that just
#         # doing 'raise' to re-raise it would be enough. But it turns out that
#         # this doesn't work, because Python tracks the exception type
#         # (exc_info[0]) separately from the exception object (exc_info[1]),
#         # and we only modified the latter. So we really do need to re-raise
#         # the new type explicitly.
#         # On py3, the traceback is part of the exception object, so our
#         # in-place modification preserved it and we can just re-raise:
#         raise self
# 
# def validate(
#     regex: Pattern[bytes], data: bytes, msg: str = "malformed data", *format_args: Any
# ) -> Dict[str, bytes]:
#     match = regex.fullmatch(data)
#     if not match:
#         if format_args:
#             msg = msg.format(*format_args)
#         raise LocalProtocolError(msg)
#     return match.groupdict()


import re
from abc import ABC
from dataclasses import dataclass, field
from typing import Any, cast, Dict, List, Tuple, Union
from ._abnf import method, request_target
from ._headers import Headers, normalize_and_validate
from ._util import bytesify, LocalProtocolError, validate
    Fields:

    .. attribute:: headers

       Default value: ``[]``

       Any trailing headers attached to this message, represented as a list of
       (name, value) pairs. See :ref:`the header normalization rules
       <headers-format>` for details.

       Must be empty unless ``Transfer-Encoding: chunked`` is in use.

    """

    __slots__ = ("headers",)

    headers: Headers

    def __init__(
        self,
        *,
        headers: Union[
            Headers, List[Tuple[bytes, bytes]], List[Tuple[str, str]], None
        ] = None,
        _parsed: bool = False,
    ) -> None:
        super().__init__()
        if headers is None:
            headers = Headers([])
        elif not isinstance(headers, Headers):

# Path: h11/_abnf.py
# OWS = r"[ \t]*"
# HEXDIG = r"[0-9A-Fa-f]"
# 
# Path: h11/_headers.py
# class Headers(Sequence[Tuple[bytes, bytes]]):
#     """
#     A list-like interface that allows iterating over headers as byte-pairs
#     of (lowercased-name, value).
# 
#     Internally we actually store the representation as three-tuples,
#     including both the raw original casing, in order to preserve casing
#     over-the-wire, and the lowercased name, for case-insensitive comparisions.
# 
#     r = Request(
#         method="GET",
#         target="/",
#         headers=[("Host", "example.org"), ("Connection", "keep-alive")],
#         http_version="1.1",
#     )
#     assert r.headers == [
#         (b"host", b"example.org"),
#         (b"connection", b"keep-alive")
#     ]
#     assert r.headers.raw_items() == [
#         (b"Host", b"example.org"),
#         (b"Connection", b"keep-alive")
#     ]
#     """
# 
#     __slots__ = "_full_items"
# 
#     def __init__(self, full_items: List[Tuple[bytes, bytes, bytes]]) -> None:
#         self._full_items = full_items
# 
#     def __bool__(self) -> bool:
#         return bool(self._full_items)
# 
#     def __eq__(self, other: object) -> bool:
#         return list(self) == list(other)  # type: ignore
# 
#     def __len__(self) -> int:
#         return len(self._full_items)
# 
#     def __repr__(self) -> str:
#         return "<Headers(%s)>" % repr(list(self))
# 
#     def __getitem__(self, idx: int) -> Tuple[bytes, bytes]:  # type: ignore[override]
#         _, name, value = self._full_items[idx]
#         return (name, value)
# 
#     def raw_items(self) -> List[Tuple[bytes, bytes]]:
#         return [(raw_name, value) for raw_name, _, value in self._full_items]
# 
# @overload
# def normalize_and_validate(headers: Headers, _parsed: Literal[True]) -> Headers:
#     ...
# 
# Path: h11/_util.py
# def bytesify(s: Union[bytes, bytearray, memoryview, int, str]) -> bytes:
#     # Fast-path:
#     if type(s) is bytes:
#         return s
#     if isinstance(s, str):
#         s = s.encode("ascii")
#     if isinstance(s, int):
#         raise TypeError("expected bytes-like object, not int")
#     return bytes(s)
# 
# class LocalProtocolError(ProtocolError):
#     def _reraise_as_remote_protocol_error(self) -> NoReturn:
#         # After catching a LocalProtocolError, use this method to re-raise it
#         # as a RemoteProtocolError. This method must be called from inside an
#         # except: block.
#         #
#         # An easy way to get an equivalent RemoteProtocolError is just to
#         # modify 'self' in place.
#         self.__class__ = RemoteProtocolError  # type: ignore
#         # But the re-raising is somewhat non-trivial -- you might think that
#         # now that we've modified the in-flight exception object, that just
#         # doing 'raise' to re-raise it would be enough. But it turns out that
#         # this doesn't work, because Python tracks the exception type
#         # (exc_info[0]) separately from the exception object (exc_info[1]),
#         # and we only modified the latter. So we really do need to re-raise
#         # the new type explicitly.
#         # On py3, the traceback is part of the exception object, so our
#         # in-place modification preserved it and we can just re-raise:
#         raise self
# 
# def validate(
#     regex: Pattern[bytes], data: bytes, msg: str = "malformed data", *format_args: Any
# ) -> Dict[str, bytes]:
#     match = regex.fullmatch(data)
#     if not match:
#         if format_args:
#             msg = msg.format(*format_args)
#         raise LocalProtocolError(msg)
#     return match.groupdict()


# Path: h11/_events.py
import re
from abc import ABC
from dataclasses import dataclass, field
from typing import Any, cast, Dict, List, Tuple, Union
from ._abnf import method, request_target
from ._headers import Headers, normalize_and_validate
from ._util import bytesify, LocalProtocolError, validate

    Fields:

    .. attribute:: headers

       Default value: ``[]``

       Any trailing headers attached to this message, represented as a list of
       (name, value) pairs. See :ref:`the header normalization rules
       <headers-format>` for details.

       Must be empty unless ``Transfer-Encoding: chunked`` is in use.

    """

    __slots__ = ("headers",)

    headers: Headers

    def __init__(
        self,
        *,
        headers: Union[
            Headers, List[Tuple[bytes, bytes]], List[Tuple[str, str]], None
        ] = None,
        _parsed: bool = False,
    ) -> None:
        super().__init__()
        if headers is None:
            headers = Headers([])
        elif not isinstance(headers, Headers):

            headers = normalize_and_validate(headers, _parsed=_parsed)