§
    xÅjë  ã                  ó  — d dl mZ d dlZd dlZd dlZd dlmZm	Z	m
Z
mZ d dlZddlmZmZ ddlmZmZmZ dd	gZ	 d d
lmZ d dlmZmZ dddej        dœdd„Zn# e$ r dddej        dœdd„ZY nw xY w G d„ d	¦  «        ZdS ) é    )ÚannotationsN)ÚAnyÚ	AwaitableÚCallableÚLiteralé   )ÚRequestÚResponseé   )ÚServerÚServerConnectionÚserveÚrouteÚRouter)ÚNotFound)ÚMapÚRequestRedirect)Úserver_nameÚsslÚcreate_routerÚtask_statusÚurl_mapr   Úargsr   r   ú
str | Noner   ú,ssl_module.SSLContext | Literal[True] | Noner   útype[Router] | Noner   útrio.TaskStatus[Server]ÚkwargsÚreturnÚNonec             �  óâ   ‡	‡
K  — |€dnd}|dur|�||d<   |€t           } || ||¦  «        Š
|                     dd¦  «        Š	‰	€‰
j        }ndˆ	ˆ
fd„}t          ‰
j        g|¢R ||dœ|¤Žƒ d{V —†S )aƒ
  
        Create a WebSocket server dispatching connections to different handlers.

        This feature requires the third-party library `werkzeug`_:

        .. code-block:: console

            $ pip install werkzeug

        .. _werkzeug: https://werkzeug.palletsprojects.com/

        :func:`route` accepts the same arguments as
        :func:`~websockets.trio.server.serve`, except as described below.

        The first argument is a :class:`werkzeug.routing.Map` that maps URL patterns
        to connection handlers. In addition to the connection, handlers receive
        parameters captured in the URL as keyword arguments.

        Here's an example::

            from websockets.trio.router import route
            from werkzeug.routing import Map, Rule

            async def channel_handler(websocket, channel_id):
                ...

            url_map = Map([
                Rule("/channel/<uuid:channel_id>", endpoint=channel_handler),
                ...
            ])

            # set this event to exit the server
            stop = trio.Event()

            with trio.open_nursery() as nursery:
                server = await nursery.start(route, url_map, ...)
                async with server:
                    await stop.wait()

        Refer to the documentation of :mod:`werkzeug.routing` for details.

        If you define redirects with ``Rule(..., redirect_to=...)`` in the URL map,
        when the server runs behind a reverse proxy that modifies the ``Host``
        header or terminates TLS, you need additional configuration:

        * Set ``server_name`` to the name of the server as seen by clients. When
          not provided, websockets uses the value of the ``Host`` header.

        * Set ``ssl=True`` to generate ``wss://`` URIs without enabling TLS.
          Under the hood, this bind the URL map with a ``url_scheme`` of
          ``wss://`` instead of ``ws://``.

        There is no need to specify ``websocket=True`` in each rule. It is added
        automatically.

        Args:
            url_map: Mapping of URL patterns to connection handlers.
            server_name: Name of the server as seen by clients. If :obj:`None`,
                websockets uses the value of the ``Host`` header.
            ssl: Configuration for enabling TLS on the connection. Set it to
                :obj:`True` if a reverse proxy terminates TLS connections.
            create_router: Factory for the :class:`Router` dispatching requests to
                handlers. Set it to a wrapper or a subclass to customize routing.
            task_status: For compatibility with :meth:`nursery.start
                <trio.Nursery.start>`.

        NÚwsÚwssTr   Úprocess_requestÚ
connectionr   Úrequestr	   r   úResponse | Nonec              “  óŽ   •K  —  ‰| |¦  «        }t          |t          ¦  «        r|ƒ d {V —†}|�|S ‰                     | |¦  «        S )N)Ú
isinstancer   Úroute_request)r%   r&   ÚresponseÚ_process_requestÚrouters      €€úGC:\Projects\Historical\venv\Lib\site-packages\websockets/trio/router.pyr$   zroute.<locals>.process_request‡   s_   øè è € ð ,Ð+¨J¸Ñ@Ô@�Ý˜h­	Ñ2Ô2ð .Ø%-˜~˜~˜~˜~˜~˜~�HØÐ'Ø#�OØ×+Ò+¨J¸Ñ@Ô@Ð@ó    )r$   r   ©r%   r   r&   r	   r   r'   )r   Úpopr*   r   Úhandler)r   r   r   r   r   r   r   Ú
url_schemer$   r,   r-   s            @@r.   r   r   $   s  øøè è € ðX !˜[�T�T¨eˆ
Ø�dˆ?ˆ?˜s˜ØˆF�5‰MàÐ Ý"ˆMà�˜w¨°ZÑ@Ô@ˆð �JŠJÐ(¨$Ñ/Ô/ð 	ð Ð#ð Ô$ð ˆOð	Að 	Að 	Að 	Að 	Að 	Að 	Aõ ØŒNð
àð
ð 
ð ,Ø#ð	
ð 
ð
 ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r/   c             �  ó$   K  — t          d¦  «        ‚)Nzroute() requires werkzeug)ÚImportError)r   r   r   r   r   r   r   s          r.   r   r      s   è è € õ Ð5Ñ6Ô6Ð6r/   c                  óH   — e Zd ZdZ	 	 ddd„Zdd„Zdd„Zdd„Zdd„Zdd„Z	dS ) r   z*WebSocket router supporting :func:`route`.Nr"   r   r   r   r   r3   Ústrr   r    c                óv   — || _         || _        || _        | j                              ¦   «         D ]	}d|_        Œ
d S )NT)r   r   r3   Ú
iter_rulesÚ	websocket)Úselfr   r   r3   Úrules        r.   Ú__init__zRouter.__init__ž   sJ   € ð ˆŒØ&ˆÔØ$ˆŒØ”L×+Ò+Ñ-Ô-ð 	"ð 	"ˆDØ!ˆDŒNˆNð	"ð 	"r/   r%   r   r&   r	   c                ó8   — | j         €|j        d         S | j         S )NÚHost)r   Úheaders)r;   r%   r&   s      r.   Úget_server_namezRouter.get_server_nameª   s!   € ØÔÐ#Ø”? 6Ô*Ð*àÔ#Ð#r/   Úurlr
   c                ój   — |                      t          j        j        d|› �¦  «        }||j        d<   |S )Nz	Found at ÚLocation)ÚrespondÚhttpÚ
HTTPStatusÚFOUNDr@   )r;   r%   rB   r+   s       r.   ÚredirectzRouter.redirect°   s7   € Ø×%Ò%¥d¤oÔ&;Ð=NÈÐ=NÐ=NÑOÔOˆØ'*ˆÔ˜Ñ$Øˆr/   c                óL   — |                      t          j        j        d¦  «        S )Nz	Not Found)rE   rF   rG   Ú	NOT_FOUND©r;   r%   s     r.   Ú	not_foundzRouter.not_foundµ   s   € Ø×!Ò!¥$¤/Ô";¸[ÑIÔIÐIr/   r'   c                óÆ  — | j                              |                      ||¦  «        | j        ¬¦  «        }	 t          j                             |j        ¦  «        }|                     |j        |j	        ¬¦  «        \  }}nR# t          $ r%}|                      ||j        ¦  «        cY d}~S d}~wt          $ r |                      |¦  «        cY S w xY w||c|_        |_        dS )zRoute incoming request.)r   r3   )Ú	path_infoÚ
query_argsN)r   ÚbindrA   r3   ÚurllibÚparseÚurlparseÚpathÚmatchÚqueryr   rI   Únew_urlr   rM   r2   Úhandler_kwargs)r;   r%   r&   Úurl_map_adapterÚparsedr2   r   rI   s           r.   r*   zRouter.route_request¸   s  € ð œ,×+Ò+Ø×,Ò,¨Z¸ÑAÔAØ”ð ,ñ 
ô 
ˆð		.Ý”\×*Ò*¨7¬<Ñ8Ô8ˆFØ-×3Ò3Ø œ+Ø!œ<ð 4ñ ô ‰OˆG�V�Vøõ ð 	?ð 	?ð 	?Ø—=’= ¨XÔ-=Ñ>Ô>Ð>Ð>Ð>Ð>Ð>Ð>øøøøÝð 	.ð 	.ð 	.Ø—>’> *Ñ-Ô-Ð-Ð-Ð-ð	.øøøà8?ÀÐ5ˆ
Ô˜JÔ5Øˆts$   ·AB  Â 
CÂ
B*Â$CÂ*"CÃCc              ƒ  ó8   K  —  |j         |fi |j        ¤Žƒ d{V —†S )zHandle a connection.N)r2   rY   rL   s     r.   r2   zRouter.handlerÍ   s6   è è € à'�ZÔ'¨
ÐPÐP°jÔ6OÐPÐPÐPÐPÐPÐPÐPÐPÐPr/   )Nr"   )r   r   r   r   r3   r7   r   r    )r%   r   r&   r	   r   r7   )r%   r   rB   r7   r   r
   )r%   r   r   r
   r0   )r%   r   r   r    )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r=   rA   rI   rM   r*   r2   © r/   r.   r   r   ›   s©   € € € € € Ø4Ð4ð
 #'Øð	
"ð 
"ð 
"ð 
"ð 
"ð$ð $ð $ð $ðð ð ð ð
Jð Jð Jð Jðð ð ð ð*Qð Qð Qð Qð Qð Qr/   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    )Ú
__future__r   rF   r   Ú
ssl_moduleÚurllib.parserR   Útypingr   r   r   r   ÚtrioÚhttp11r	   r
   Úserverr   r   r   Ú__all__Úwerkzeug.exceptionsr   Úwerkzeug.routingr   r   ÚTASK_STATUS_IGNOREDr   r5   r   ra   r/   r.   ú<module>rm      s¥  ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ø Ð Ð Ð Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4à €€€à &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3ð �HÐ
€ðG
Ø,Ð,Ð,Ð,Ð,Ð,Ø5Ð5Ð5Ð5Ð5Ð5Ð5Ð5ð( #'Ø<@Ø-1Ø/3Ô/Gðt
ð t
ð t
ð t
ð t
ð t
ð t
øð ð 7ð 7ð 7ð
 #'Ø<@Ø-1Ø/3Ô/Gð	7ð 	7ð 	7ð 	7ð 	7ð 	7ð 	7ð 	7ð7øøøðL4Qð 4Qð 4Qð 4Qð 4Qñ 4Qô 4Qð 4Qð 4Qð 4Qs   ºA ÁA/Á.A/