Ë
    Õ±1h“  ã                  óÞ   — 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
 d dlmZ d dlmZmZ ddlmZmZ dd	lmZmZmZ g d
¢Z G d„ d«      Zddddœ	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	 d	 	 	 	 	 	 	 dd„Zy)é    )ÚannotationsN)ÚAnyÚCallableÚLiteral)ÚNotFound)ÚMapÚRequestRedirecté   )ÚRequestÚResponseé   )ÚServerÚServerConnectionÚserve)ÚrouteÚ
unix_routeÚRouterc                  ó`   — 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)Úurl_mapÚserver_nameÚ
url_schemeÚ
iter_rulesÚ	websocket)Úselfr   r   r   Úrules        úT/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/websockets/sync/router.pyÚ__init__zRouter.__init__   s=   € ð ˆŒØ&ˆÔØ$ˆŒØ—L‘L×+Ñ+Ó-ò 	"ˆDØ!ˆD�Nñ	"ó    c                óP   — | j                   €|j                  d   S | j                   S )NÚHost)r   Úheaders)r   Ú
connectionÚrequests      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ÚFOUNDr"   )r   r#   ÚurlÚresponses       r   ÚredirectzRouter.redirect'   s:   € Ø×%Ñ%¤d§o¡o×&;Ñ&;¸yÈÈÐ=NÓOˆØ'*ˆ×Ñ˜Ñ$Øˆr   c                óV   — |j                  t        j                  j                  d«      S )Nz	Not Found)r(   r)   r*   Ú	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   Úbindr%   r   ÚurllibÚparseÚurlparseÚpathÚmatchÚqueryr	   r.   Únew_urlr   r2   ÚhandlerÚhandler_kwargs)r   r#   r$   Úurl_map_adapterÚparsedr>   Úkwargsr.   s           r   Úroute_requestz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                ó<   —  |j                   |fi |j                  ¤ŽS )zHandle a connection.)r>   r?   r1   s     r   r>   zRouter.handlerD   s    € à!ˆz×!Ñ! *ÑJ°
×0IÑ0IÑJÐJr   )NÚws)r   r   r   ú
str | Noner   ÚstrÚreturnÚNone)r#   r   r$   r   rH   rG   )r#   r   r,   rG   rH   r   )r#   r   rH   r   ©r#   r   r$   r   rH   zResponse | None)r#   r   rH   rI   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   r.   r2   rC   r>   © r   r   r   r      sk   „ Ù4ð
 #'Øð	
"àð
"ð  ð
"ð ð	
"ð
 
ó
"ó$óó
JðØ*ðØ5<ðà	óô*Kr   r   )r   Ú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.sync.router import route
        from werkzeug.routing import Map, Rule

        def channel_handler(websocket, channel_id):
            ...

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

        with route(url_map, ...) as server:
            server.serve_forever()

    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 actually 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.

    NrE   ÚwssTrP   Úprocess_requestc                óB   •—  ‰| |«      }|�|S ‰j                  | |«      S ©N)rC   )r#   r$   r-   Ú_process_requestÚrouters      €€r   rT   zroute.<locals>.process_request¥   s/   ø€ ñ (¨
°GÓ<ˆHØÐ#Ø�Ø×'Ñ'¨
°GÓ<Ð<r   rJ   )r   ÚpoprC   r   r>   )
r   r   rP   rQ   ÚargsrB   r   rT   rW   rX   s
           @@r   r   r   I   s©   ù€ ðJ ˜‘¨%€JØ
�$�˜3˜?Øˆˆu‰àÐÜˆá˜7 K°Ó<€Fð 	�
‰
Ð$ dÓ+ð ð Ðð × Ñ ñ 	ð	=Ø(ð	=Ø3:ð	=àö	=ô �—‘ÐR $ÒR¸ÐRÈ6ÑRÐRr   c                ó    — t        | fd|dœ|¤ŽS )aK  
    Create a WebSocket Unix server dispatching connections to different handlers.

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

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

    T)Úunixr:   )r   )r   r:   rB   s      r   r   r   °   s   € ô  �Ð9˜t¨$Ñ9°&Ñ9Ð9r   )r   r   rZ   r   r   rF   rP   z,ssl_module.SSLContext | Literal[True] | NonerQ   ztype[Router] | NonerB   r   rH   r   rV   )r   r   r:   rF   rB   r   rH   r   )Ú
__future__r   r)   rP   Ú
ssl_moduleÚurllib.parser7   Útypingr   r   r   Úwerkzeug.exceptionsr   Úwerkzeug.routingr   r	   Úhttp11r   r   Úserverr   r   r   Ú__all__r   r   r   rO   r   r   ú<module>rf      sË   ðÝ "ã Û Û ß )Ñ )å (ß 1ç &ß 3Ñ 3ò ,€÷4Kñ 4Kðt #Ø8<Ø)-ñdSØðdSàðdSð ðdSð 
6ð	dSð
 'ðdSð ðdSð ódSðR ð:Øð:à
ð:ð ð:ð ô	:r   