Ë
    ·�©jg  ã                  óL  — 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 G d„ d«      Zy# e$ r& ddddœ	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	 d	 	 	 	 	 	 	 dd„ZY Œ5w xY w)é    )ÚannotationsN)ÚAnyÚ	AwaitableÚCallableÚLiteralé   )ÚRequestÚResponse)ÚPathLikeé   )ÚServerÚServerConnectionÚserve)ÚrouteÚ
unix_routeÚRouter)ÚNotFound)ÚMapÚRequestRedirect)Úserver_nameÚsslÚcreate_routerc               óÞ   ‡‡	— |€dnd}|dur|�||d<   |€t         } || ||«      Š	|j                  dd«      Š‰€‰	j                  }n	 	 	 	 	 	 dˆˆ	fd„}t        ‰	j                  g|¢­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_requestc              “  ó‚   •K  —  ‰| |«      }t        |t        «      r
|ƒ d {  –—† }|�|S ‰j                  | |«      S 7 Œ­w©N)Ú
isinstancer   Úroute_request)Ú
connectionÚrequestÚresponseÚ_process_requestÚrouters      €€ú`/var/www/html/streamforge-license/venv/lib/python3.12/site-packages/websockets/asyncio/router.pyr   zroute.<locals>.process_request‹   sI   øè ø€ ñ ,¨J¸Ó@�Ü˜h¬	Ô2Ø%-Ÿ~�HØÐ'Ø#�OØ×+Ñ+¨J¸Ó@Ð@ð  .ús   ƒ?¢=£?©r!   r   r"   r	   ÚreturnzResponse | None)r   Úpopr    r   Úhandler)
Úurl_mapr   r   r   ÚargsÚkwargsÚ
url_schemer   r$   r%   s
           @@r&   r   r   )   sÁ   ù€ ðV !˜[‘T¨eˆ
Ø�d‰?˜s˜ØˆF�5‰MàÐ Ü"ˆMá˜w¨°ZÓ@ˆð �J‰JÐ(¨$Ó/ð 	ð Ð#ð ×$Ñ$ñ ð	AØ,ð	Aà ð	Að !ö	Aô Ø�N‰Nð
àò
ð ,ð
ð ñ	
ð 	
ó    c                ó    — 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)ÚunixÚpath)r   ©r+   r2   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Ð6r/   c                ó   — t        d«      ‚)Nzunix_route() requires werkzeugr5   r3   s      r&   r   r       s   € ô
 Ð:Ó;Ð;r/   c                  ó`   — 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	y)r   z*WebSocket router supporting :func:`route`.Nc                óz   — || _         || _        || _        | j                   j                  «       D ]	  }d|_        Œ y )NT)r+   r   r.   Ú
iter_rulesÚ	websocket)Úselfr+   r   r.   Úrules        r&   Ú__init__zRouter.__init__³   s=   € ð ˆŒØ&ˆÔØ$ˆŒØ—L‘L×+Ñ+Ó-ò 	"ˆDØ!ˆD�Nñ	"r/   c                óP   — | 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/   c                ó~   — |j                  t        j                  j                  d|› �«      }||j                  d<   |S )Nz	Found at ÚLocation)ÚrespondÚhttpÚ
HTTPStatusÚFOUNDrA   )r<   r!   Úurlr#   s       r&   ÚredirectzRouter.redirectÅ   s:   € Ø×%Ñ%¤d§o¡o×&;Ñ&;¸yÈÈÐ=NÓOˆØ'*ˆ×Ñ˜Ñ$Øˆr/   c                óV   — |j                  t        j                  j                  d«      S )Nz	Not Found)rE   rF   rG   Ú	NOT_FOUND©r<   r!   s     r&   Ú	not_foundzRouter.not_foundÊ   s   € Ø×!Ñ!¤$§/¡/×";Ñ";¸[ÓIÐIr/   c                óÒ  — | j                   j                  | j                  ||«      | j                  ¬«      }	 t        j
                  j                  |j                  «      }|j                  |j                  |j                  ¬«      \  }}||c|_        |_        y# t        $ r&}| j                  ||j                  «      cY d}~S d}~wt        $ r | j                  |«      cY S w xY w)zRoute incoming request.)r   r.   )Ú	path_infoÚ
query_argsN)r+   ÚbindrB   r.   ÚurllibÚparseÚurlparser2   ÚmatchÚqueryr   rJ   Únew_urlr   rN   r*   Úhandler_kwargs)r<   r!   r"   Úurl_map_adapterÚparsedr*   r-   rJ   s           r&   r    zRouter.route_requestÍ   sÐ   € ð Ÿ,™,×+Ñ+Ø×,Ñ,¨Z¸ÓAØ—‘ð ,ó 
ˆð		.Ü—\‘\×*Ñ*¨7¯<©<Ó8ˆFØ-×3Ñ3Ø Ÿ+™+Ø!Ÿ<™<ð 4ó ‰OˆG�Vð 9@ÀÐ5ˆ
Ô˜JÔ5Øøô ò 	?Ø—=‘= ¨X×-=Ñ-=Ó>Õ>ûÜò 	.Ø—>‘> *Ó-Ò-ð	.ús$   ¹AB Â	C&Â%CÃ C&ÃC&Ã%C&c              ƒ  óX   K  —  |j                   |fi |j                  ¤Žƒ d{  –—† S 7 Œ­w)zHandle a connection.N)r*   rY   rM   s     r&   r*   zRouter.handlerâ   s*   è ø€ à'�Z×'Ñ'¨
ÑP°j×6OÑ6OÑP×PÐPÐPús   ‚!*£(¤*)Nr   )r+   r   r   ú
str | Noner.   Ústrr(   ÚNone)r!   r   r"   r	   r(   r^   )r!   r   rI   r^   r(   r
   )r!   r   r(   r
   r'   )r!   r   r(   r_   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r>   rB   rJ   rN   r    r*   © r/   r&   r   r   °   sk   „ Ù4ð
 #'Øð	
"àð
"ð  ð
"ð ð	
"ð
 
ó
"ó$óó
JðØ*ðØ5<ðà	óô*Qr/   r   )r+   r   r,   r   r   r]   r   z,ssl_module.SSLContext | Literal[True] | Noner   ztype[Router] | Noner-   r   r(   r   r   )r+   r   r2   zPathLike | Noner-   r   r(   r   )Ú
__future__r   rF   r   Ú
ssl_moduleÚurllib.parserS   Útypingr   r   r   r   Úhttp11r	   r
   r   Úserverr   r   r   Ú__all__Úwerkzeug.exceptionsr   Úwerkzeug.routingr   r   r   r   r6   r   rd   r/   r&   ú<module>rn      s]  ðÝ "ã Û Û ß 4Ó 4ç &Ý ß 3Ñ 3ò ,€ð]>Ý,ß5ð4 #'Ø<@Ø-1ñr
Øðr
àðr
ð  ðr
ð :ð	r
ð
 +ðr
ð ðr
ð 
ór
ðl !%ð>Øð>àð>ð ð>ð 
ó	>÷&4Qò 4Qøðy ò <ð
 #'Ø<@Ø-1ñ7Øð7àð7ð  ð7ð :ð	7ð
 +ð7ð ð7ð 
ó7ð !%ð<Øð<àð<ð ð<ð 
õ	<ð<ús   ¼A8 Á8(B#Â"B#