§
     	ÊjK  ã                  ó  — 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mZmZ ddlmZ ddlmZmZmZ g d	¢Z	 d d
lmZ d dlmZmZ ddddœd"d„Z	 d#d$d„Zn# e$ r ddddœd"d„Z	 d#d$d„ZY nw xY w G d „ d!¦  «        ZdS )%é    )ÚannotationsN)ÚAnyÚ	AwaitableÚCallableÚLiteralé   )ÚRequestÚResponse)ÚPathLikeé   )ÚServerÚServerConnectionÚserve)ÚrouteÚ
unix_routeÚRouter)ÚNotFound)ÚMapÚRequestRedirect)Úserver_nameÚsslÚcreate_routerÚurl_mapr   Úargsr   r   ú
str | Noner   ú,ssl_module.SSLContext | Literal[True] | Noner   útype[Router] | NoneÚkwargsÚreturnr   c               óÐ   ‡‡	— |€dnd}|dur|�||d<   |€t           } || ||¦  «        Š	|                     dd¦  «        Š‰€‰	j        }ndˆˆ	fd„}t          ‰	j        g|¢R d|i|¤Ž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.sync.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.asyncio.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 = asyncio.Event()

            async with route(url_map, ...) as 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.

        Like :func:`~websockets.sync.server.serve`, :func:`route` returns a
        :class:`~websockets.sync.server.Server` that you can also run with
        :meth:`~websockets.sync.server.Server.serve_forever`.

        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.

        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      €€úIC:\Projects\Muse2API\.venv\Lib\site-packages\websockets/asyncio/router.pyr#   zroute.<locals>.process_request‹   s_   øè è € ð ,Ð+¨J¸Ñ@Ô@�Ý˜h­	Ñ2Ô2ð .Ø%-˜~˜~˜~˜~˜~˜~�HØÐ'Ø#�OØ×+Ò+¨J¸Ñ@Ô@Ð@ó    ©r$   r   r%   r	   r   r&   )r   Úpopr*   r   Úhandler)
r   r   r   r   r   r   Ú
url_schemer#   r,   r-   s
           @@r.   r   r   )   sá   øø€ ðV !˜[�T�T¨eˆ
Ø�dˆ?ˆ?˜s˜ØˆF�5‰MàÐ Ý"ˆMà�˜w¨°ZÑ@Ô@ˆð �JŠJÐ(¨$Ñ/Ô/ð 	ð Ð#ð Ô$ð ˆOð	Að 	Að 	Að 	Að 	Að 	Að 	Aõ ØŒNð
àð
ð 
ð 
ð ,ð
ð ð	
ð 
ð 	
r/   ÚpathúPathLike | Nonec                ó"   — t          | fd|dœ|¤ŽS )aj  
        Create a WebSocket Unix server dispatching connections to different handlers.

        :func:`unix_route` combines the behaviors of :func:`route` and
        :func:`~websockets.asyncio.server.unix_serve`.

        Args:
            url_map: Mapping of URL patterns to connection handlers.
            path: File system path to the Unix socket.

        T)Úunixr4   )r   ©r   r4   r   s      r.   r   r   �   s!   € õ  �WÐ= 4¨dÐ=Ð=°fÐ=Ð=Ð=r/   c               ó    — t          d¦  «        ‚)Nzroute() requires werkzeug©ÚImportError)r   r   r   r   r   r   s         r.   r   r      s   € õ Ð5Ñ6Ô6Ð6r/   c                ó    — t          d¦  «        ‚)Nzunix_route() requires werkzeugr:   r8   s      r.   r   r       s   € õ
 Ð:Ñ;Ô;Ð;r/   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   ÚNonec                ó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)rC   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ÚFOUNDrH   )rC   r$   rJ   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)rM   rN   rO   Ú	NOT_FOUND©rC   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   ÚbindrI   r3   ÚurllibÚparseÚurlparser4   ÚmatchÚqueryr   rQ   Únew_urlr   rU   r2   Úhandler_kwargs)rC   r$   r%   Úurl_map_adapterÚparsedr2   r   rQ   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   r`   rT   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   r>   r   r?   )r$   r   r%   r	   r   r>   )r$   r   rJ   r>   r   r
   )r$   r   r   r
   r0   )r$   r   r   r?   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__rE   rI   rQ   rU   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(   )r   r   r4   r5   r   r   r   r   )Ú
__future__r   rN   r   Ú
ssl_moduleÚurllib.parserZ   Útypingr   r   r   r   Úhttp11r	   r
   r   Úserverr   r   r   Ú__all__Úwerkzeug.exceptionsr   Úwerkzeug.routingr   r   r   r   r;   r   rh   r/   r.   ú<module>rr      sà  ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ø Ð Ð Ð Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4à &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ø Ð Ð Ð Ð Ð Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3ð ,Ð
+Ð
+€ð]>Ø,Ð,Ð,Ð,Ð,Ð,Ø5Ð5Ð5Ð5Ð5Ð5Ð5Ð5ð4 #'Ø<@Ø-1ðr
ð r
ð r
ð r
ð r
ð r
ðl !%ð>ð >ð >ð >ð >ð >øðS ð <ð <ð <ð
 #'Ø<@Ø-1ð7ð 7ð 7ð 7ð 7ð 7ð !%ð<ð <ð <ð <ð <ð <ð <ð<øøøðx4Qð 4Qð 4Qð 4Qð 4Qñ 4Qô 4Qð 4Qð 4Qð 4Qs   ¼A ÁA1Á0A1