
    g                        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dS )!    )annotationsN)AnyCallableLiteral)NotFound)MapRequestRedirect   )RequestResponse   )ServerServerConnectionserve)route
unix_routeRouterc                  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`.Nwsurl_mapr   server_name
str | None
url_schemestrreturnNonec                v    || _         || _        || _        | j                                         D ]	}d|_        
d S )NT)r   r   r   
iter_rules	websocket)selfr   r   r   rules        b/var/www/html/nodeJS/PythonScripts/venv3.11/lib/python3.11/site-packages/websockets/sync/router.py__init__zRouter.__init__   sJ     &$L++-- 	" 	"D!DNN	" 	"    
connectionr   requestr   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%   r+   responses       r"   redirectzRouter.redirect'   s7    %%do&;=N=N=NOO'*$r$   c                L    |                     t          j        j        d          S )Nz	Not Found)r.   r/   r0   	NOT_FOUNDr    r%   s     r"   	not_foundzRouter.not_found,   s    !!$/";[IIIr$   Response | Nonec                   | 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   r   )	path_info
query_argsN)r   bindr*   r   urllibparseurlparsepathmatchqueryr	   r3   new_urlr   r7   handlerhandler_kwargs)r    r%   r&   url_map_adapterparsedrD   kwargsr3   s           r"   route_requestzRouter.route_request/   s    ,++,,ZAA , 
 
		.\**7<88F-33 +!< 4  OGVV  	? 	? 	?==X-=>>>>>>>> 	. 	. 	.>>*-----	.8?5
J5ts$   AB   
C
B*$C*"CCc                (     |j         |fi |j        S )zHandle a connection.)rD   rE   r6   s     r"   rD   zRouter.handlerD   s     !z!*JJ
0IJJJr$   )Nr   )r   r   r   r   r   r   r   r   )r%   r   r&   r   r   r   )r%   r   r+   r   r   r   )r%   r   r   r   r%   r   r&   r   r   r8   )r%   r   r   r   )
__name__
__module____qualname____doc__r#   r*   r3   r7   rI   rD    r$   r"   r   r      s        44
 #'	
" 
" 
" 
" 
"$ $ $ $   
J J J J   *K K K K K Kr$   r   )r   sslcreate_routerr   r   argsr   r   r   rQ   ,ssl_module.SSLContext | Literal[True] | NonerR   type[Router] | NonerH   r   r   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.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   wssTrQ   process_requestr%   r   r&   r   r   r8   c                P     | |          }||S                      | |          S N)rI   )r%   r&   r2   _process_requestrouters      r"   rX   zroute.<locals>.process_request   s8     ('
G<<H#''
G<<<r$   rK   )r   poprI   r   rD   )
r   r   rQ   rR   rS   rH   r   rX   r[   r\   s
           @@r"   r   r   I   s    J %J
$3?u]7K<<F 	

$d++     		= 	= 	= 	= 	= 	= 	= R$RRRR6RRRr$   r@   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@   rH   s      r"   r   r      s!      9t$99&999r$   )r   r   rS   r   r   r   rQ   rT   rR   rU   rH   r   r   r   rZ   )r   r   r@   r   rH   r   r   r   )
__future__r   r/   rQ   
ssl_moduleurllib.parser=   typingr   r   r   werkzeug.exceptionsr   werkzeug.routingr   r	   http11r   r   serverr   r   r   __all__r   r   r   rP   r$   r"   <module>ri      sR   " " " " " "          ) ) ) ) ) ) ) ) ) ) ( ( ( ( ( ( 1 1 1 1 1 1 1 1 & & & & & & & & 3 3 3 3 3 3 3 3 3 3 ,
+
+4K 4K 4K 4K 4K 4K 4K 4Kt #8<)-dS dS dS dS dS dSR : : : : : : :r$   