# Path: starlette/requests.py
# class HTTPConnection(Mapping):
#     """
#     A base class for incoming HTTP connections, that is used to provide
#     any functionality that is common to both `Request` and `WebSocket`.
#     """
# 
#     def __init__(self, scope: Scope, receive: Receive = None) -> None:
#         assert scope["type"] in ("http", "websocket")
#         self.scope = scope
# 
#     def __getitem__(self, key: str) -> typing.Any:
#         return self.scope[key]
# 
#     def __iter__(self) -> typing.Iterator[str]:
#         return iter(self.scope)
# 
#     def __len__(self) -> int:
#         return len(self.scope)
# 
#     # Don't use the `abc.Mapping.__eq__` implementation.
#     # Connection instances should never be considered equal
#     # unless `self is other`.
#     __eq__ = object.__eq__
#     __hash__ = object.__hash__
# 
#     @property
#     def app(self) -> typing.Any:
#         return self.scope["app"]
# 
#     @property
#     def url(self) -> URL:
#         if not hasattr(self, "_url"):
#             self._url = URL(scope=self.scope)
#         return self._url
# 
#     @property
#     def base_url(self) -> URL:
#         if not hasattr(self, "_base_url"):
#             base_url_scope = dict(self.scope)
#             base_url_scope["path"] = "/"
#             base_url_scope["query_string"] = b""
#             base_url_scope["root_path"] = base_url_scope.get(
#                 "app_root_path", base_url_scope.get("root_path", "")
#             )
#             self._base_url = URL(scope=base_url_scope)
#         return self._base_url
# 
#     @property
#     def headers(self) -> Headers:
#         if not hasattr(self, "_headers"):
#             self._headers = Headers(scope=self.scope)
#         return self._headers
# 
#     @property
#     def query_params(self) -> QueryParams:
#         if not hasattr(self, "_query_params"):
#             self._query_params = QueryParams(self.scope["query_string"])
#         return self._query_params
# 
#     @property
#     def path_params(self) -> typing.Dict[str, typing.Any]:
#         return self.scope.get("path_params", {})
# 
#     @property
#     def cookies(self) -> typing.Dict[str, str]:
#         if not hasattr(self, "_cookies"):
#             cookies: typing.Dict[str, str] = {}
#             cookie_header = self.headers.get("cookie")
# 
#             if cookie_header:
#                 cookies = cookie_parser(cookie_header)
#             self._cookies = cookies
#         return self._cookies
# 
#     @property
#     def client(self) -> typing.Optional[Address]:
#         # client is a 2 item tuple of (host, port), None or missing
#         host_port = self.scope.get("client")
#         if host_port is not None:
#             return Address(*host_port)
#         return None
# 
#     @property
#     def session(self) -> dict:
#         assert (
#             "session" in self.scope
#         ), "SessionMiddleware must be installed to access request.session"
#         return self.scope["session"]
# 
#     @property
#     def auth(self) -> typing.Any:
#         assert (
#             "auth" in self.scope
#         ), "AuthenticationMiddleware must be installed to access request.auth"
#         return self.scope["auth"]
# 
#     @property
#     def user(self) -> typing.Any:
#         assert (
#             "user" in self.scope
#         ), "AuthenticationMiddleware must be installed to access request.user"
#         return self.scope["user"]
# 
#     @property
#     def state(self) -> State:
#         if not hasattr(self, "_state"):
#             # Ensure 'state' has an empty dict if it's not already populated.
#             self.scope.setdefault("state", {})
#             # Create a state instance with a reference to the dict in which it should
#             # store info
#             self._state = State(self.scope["state"])
#         return self._state
# 
#     def url_for(self, name: str, **path_params: typing.Any) -> str:
#         router: Router = self.scope["router"]
#         url_path = router.url_path_for(name, **path_params)
#         return url_path.make_absolute_url(base_url=self.base_url)
# 
# Path: starlette/types.py



import enum
import json
import typing
from starlette.requests import HTTPConnection
from starlette.types import Message, Receive, Scope, Send



class WebSocketState(enum.Enum):
    CONNECTING = 0
    CONNECTED = 1
    DISCONNECTED = 2


class WebSocketDisconnect(Exception):
    def __init__(self, code: int = 1000, reason: str = None) -> None:
        self.code = code
        self.reason = reason or ""


class WebSocket(HTTPConnection):
    def __init__(self, scope: Scope, receive: Receive, send: Send) -> None:
        super().__init__(scope)
        assert scope["type"] == "websocket"
        self._receive = receive
        self._send = send
        self.client_state = WebSocketState.CONNECTING
        self.application_state = WebSocketState.CONNECTING


# Path: starlette/requests.py
# class HTTPConnection(Mapping):
#     """
#     A base class for incoming HTTP connections, that is used to provide
#     any functionality that is common to both `Request` and `WebSocket`.
#     """
# 
#     def __init__(self, scope: Scope, receive: Receive = None) -> None:
#         assert scope["type"] in ("http", "websocket")
#         self.scope = scope
# 
#     def __getitem__(self, key: str) -> typing.Any:
#         return self.scope[key]
# 
#     def __iter__(self) -> typing.Iterator[str]:
#         return iter(self.scope)
# 
#     def __len__(self) -> int:
#         return len(self.scope)
# 
#     # Don't use the `abc.Mapping.__eq__` implementation.
#     # Connection instances should never be considered equal
#     # unless `self is other`.
#     __eq__ = object.__eq__
#     __hash__ = object.__hash__
# 
#     @property
#     def app(self) -> typing.Any:
#         return self.scope["app"]
# 
#     @property
#     def url(self) -> URL:
#         if not hasattr(self, "_url"):
#             self._url = URL(scope=self.scope)
#         return self._url
# 
#     @property
#     def base_url(self) -> URL:
#         if not hasattr(self, "_base_url"):
#             base_url_scope = dict(self.scope)
#             base_url_scope["path"] = "/"
#             base_url_scope["query_string"] = b""
#             base_url_scope["root_path"] = base_url_scope.get(
#                 "app_root_path", base_url_scope.get("root_path", "")
#             )
#             self._base_url = URL(scope=base_url_scope)
#         return self._base_url
# 
#     @property
#     def headers(self) -> Headers:
#         if not hasattr(self, "_headers"):
#             self._headers = Headers(scope=self.scope)
#         return self._headers
# 
#     @property
#     def query_params(self) -> QueryParams:
#         if not hasattr(self, "_query_params"):
#             self._query_params = QueryParams(self.scope["query_string"])
#         return self._query_params
# 
#     @property
#     def path_params(self) -> typing.Dict[str, typing.Any]:
#         return self.scope.get("path_params", {})
# 
#     @property
#     def cookies(self) -> typing.Dict[str, str]:
#         if not hasattr(self, "_cookies"):
#             cookies: typing.Dict[str, str] = {}
#             cookie_header = self.headers.get("cookie")
# 
#             if cookie_header:
#                 cookies = cookie_parser(cookie_header)
#             self._cookies = cookies
#         return self._cookies
# 
#     @property
#     def client(self) -> typing.Optional[Address]:
#         # client is a 2 item tuple of (host, port), None or missing
#         host_port = self.scope.get("client")
#         if host_port is not None:
#             return Address(*host_port)
#         return None
# 
#     @property
#     def session(self) -> dict:
#         assert (
#             "session" in self.scope
#         ), "SessionMiddleware must be installed to access request.session"
#         return self.scope["session"]
# 
#     @property
#     def auth(self) -> typing.Any:
#         assert (
#             "auth" in self.scope
#         ), "AuthenticationMiddleware must be installed to access request.auth"
#         return self.scope["auth"]
# 
#     @property
#     def user(self) -> typing.Any:
#         assert (
#             "user" in self.scope
#         ), "AuthenticationMiddleware must be installed to access request.user"
#         return self.scope["user"]
# 
#     @property
#     def state(self) -> State:
#         if not hasattr(self, "_state"):
#             # Ensure 'state' has an empty dict if it's not already populated.
#             self.scope.setdefault("state", {})
#             # Create a state instance with a reference to the dict in which it should
#             # store info
#             self._state = State(self.scope["state"])
#         return self._state
# 
#     def url_for(self, name: str, **path_params: typing.Any) -> str:
#         router: Router = self.scope["router"]
#         url_path = router.url_path_for(name, **path_params)
#         return url_path.make_absolute_url(base_url=self.base_url)
# 
# Path: starlette/types.py



# Path: starlette/websockets.py
import enum
import json
import typing
from starlette.requests import HTTPConnection
from starlette.types import Message, Receive, Scope, Send




class WebSocketState(enum.Enum):
    CONNECTING = 0
    CONNECTED = 1
    DISCONNECTED = 2


class WebSocketDisconnect(Exception):
    def __init__(self, code: int = 1000, reason: str = None) -> None:
        self.code = code
        self.reason = reason or ""


class WebSocket(HTTPConnection):
    def __init__(self, scope: Scope, receive: Receive, send: Send) -> None:
        super().__init__(scope)
        assert scope["type"] == "websocket"
        self._receive = receive
        self._send = send
        self.client_state = WebSocketState.CONNECTING
        self.application_state = WebSocketState.CONNECTING


    async def receive(self) -> Message: