# Path: starlette/types.py

# 
# Path: starlette/websockets.py
# class WebSocketDisconnect(Exception):
#     def __init__(self, code: int = 1000, reason: str = None) -> None:
#         self.code = code
#         self.reason = reason or ""


import asyncio
import contextlib
import http
import inspect
import io
import json
import math
import queue
import sys
import types
import typing
import anyio.abc
import requests
from concurrent.futures import Future
from urllib.parse import unquote, urljoin, urlsplit
from anyio.streams.stapled import StapledObjectStream
from starlette.types import Message, Receive, Scope, Send
from starlette.websockets import WebSocketDisconnect
    from typing import TypedDict
    from typing_extensions import TypedDict
        finally:
            self.exit_stack.close()
        while not self._send_queue.empty():
            message = self._send_queue.get()
            if isinstance(message, BaseException):
                raise message

    async def _run(self) -> None:
        """
        The sub-thread in which the websocket session runs.
        """
        scope = self.scope
        receive = self._asgi_receive
        send = self._asgi_send
        try:
            await self.app(scope, receive, send)
        except BaseException as exc:
            self._send_queue.put(exc)
            raise

    async def _asgi_receive(self) -> Message:
        while self._receive_queue.empty():
            await anyio.sleep(0)
        return self._receive_queue.get()

    async def _asgi_send(self, message: Message) -> None:
        self._send_queue.put(message)

    def _raise_on_close(self, message: Message) -> None:
        if message["type"] == "websocket.close":

# Path: starlette/types.py

# 
# Path: starlette/websockets.py
# class WebSocketDisconnect(Exception):
#     def __init__(self, code: int = 1000, reason: str = None) -> None:
#         self.code = code
#         self.reason = reason or ""


# Path: starlette/testclient.py
import asyncio
import contextlib
import http
import inspect
import io
import json
import math
import queue
import sys
import types
import typing
import anyio.abc
import requests
from concurrent.futures import Future
from urllib.parse import unquote, urljoin, urlsplit
from anyio.streams.stapled import StapledObjectStream
from starlette.types import Message, Receive, Scope, Send
from starlette.websockets import WebSocketDisconnect
    from typing import TypedDict
    from typing_extensions import TypedDict

        finally:
            self.exit_stack.close()
        while not self._send_queue.empty():
            message = self._send_queue.get()
            if isinstance(message, BaseException):
                raise message

    async def _run(self) -> None:
        """
        The sub-thread in which the websocket session runs.
        """
        scope = self.scope
        receive = self._asgi_receive
        send = self._asgi_send
        try:
            await self.app(scope, receive, send)
        except BaseException as exc:
            self._send_queue.put(exc)
            raise

    async def _asgi_receive(self) -> Message:
        while self._receive_queue.empty():
            await anyio.sleep(0)
        return self._receive_queue.get()

    async def _asgi_send(self, message: Message) -> None:
        self._send_queue.put(message)

    def _raise_on_close(self, message: Message) -> None:
        if message["type"] == "websocket.close":

            raise WebSocketDisconnect(