HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/websockets/sync/__pycache__/router.cpython-310.pyc
o

�h��@s�ddlmZddlZddlZddlZddlmZm	Z	m
Z
ddlmZddl
mZmZddlmZmZdd	lmZmZmZgd
�ZGdd�d�Zdddd
�d dd�Z	d!d"dd�ZdS)#�)�annotationsN)�Any�Callable�Literal)�NotFound)�Map�RequestRedirect�)�Request�Response�)�Server�ServerConnection�serve)�route�
unix_route�Routerc@sReZdZdZ		dd dd
�Zd!dd�Zd"dd�Zd#dd�Zd$dd�Zd%dd�Z	dS)&rz*WebSocket router supporting :func:`route`.N�ws�url_mapr�server_name�
str | None�
url_scheme�str�return�NonecCs,||_||_||_|j��D]}d|_qdS)NT)rrr�
iter_rules�	websocket)�selfrrr�rule�r�I/usr/local/CyberCP/lib/python3.10/site-packages/websockets/sync/router.py�__init__s�zRouter.__init__�
connectionr�requestr
cCs|jdur
|jdS|jS)N�Host)r�headers)rr"r#rrr �get_server_name!s

zRouter.get_server_name�urlrcCs$|�tjjd|���}||jd<|S)Nz	Found at �Location)�respond�http�
HTTPStatus�FOUNDr%)rr"r'�responserrr �redirect's
zRouter.redirectcCs|�tjjd�S)Nz	Not Found)r)r*r+�	NOT_FOUND�rr"rrr �	not_found,szRouter.not_found�Response | Nonec
Cs�|jj|�||�|jd�}ztj�|j�}|j|j|j	d�\}}Wn&t
y:}z
|�||j�WYd}~Sd}~wt
yG|�|�YSw|||_|_dS)zRoute incoming request.)rr)�	path_info�
query_argsN)r�bindr&r�urllib�parse�urlparse�path�match�queryrr.�new_urlrr1�handler�handler_kwargs)rr"r#�url_map_adapter�parsedr=�kwargsr.rrr �
route_request/s$
����zRouter.route_requestcCs|j|fi|j��S)zHandle a connection.)r=r>r0rrr r=DszRouter.handler)Nr)rrrrrrrr)r"rr#r
rr)r"rr'rrr)r"rrr�r"rr#r
rr2)r"rrr)
�__name__�
__module__�__qualname__�__doc__r!r&r.r1rBr=rrrr rs�



r)r�ssl�
create_routerrr�argsrrrrH�,ssl_module.SSLContext | Literal[True] | NonerI�type[Router] | NonerArr
cs�|durdnd}|dur|dur||d<|durt}||||��|�dd���dur.�j}nd��fd
d�}t�jg|�Rd|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.

    Nr�wssTrH�process_requestr"rr#r
rr2cs"�||�}|dur|S��||�S�N)rB)r"r#r-��_process_request�routerrr rN�s
zroute.<locals>.process_requestrC)r�poprBrr=)rrrHrIrJrArrNrrPr rIsE
��rr9cKst|fd|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)�unixr9)r)rr9rArrr r�sr)rrrJrrrrHrKrIrLrArrr
rO)rrr9rrArrr
)�
__future__rr*rH�
ssl_module�urllib.parser6�typingrrr�werkzeug.exceptionsr�werkzeug.routingrr�http11r
r�serverr
rr�__all__rrrrrrr �<module>s":�i�