
    ,h                        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 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	Awaitable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        [/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/websockets/asyncio/router.py__init__zRouter.__init__   s=     &$LL++- 	"D!DN	"    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:    %%doo&;&;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   r3   handlerhandler_kwargs)r   r$   r%   url_map_adapterparsedr?   kwargsr/   s           r   route_requestzRouter.route_request/   s     ,,++,,ZA , 
		.\\**7<<8F-33 ++!<< 4 OGV 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?   r@   r2   s     r   r?   zRouter.handlerD   s*     'Z''
Pj6O6OPPPPs   !*(*)Nws)r   r	   r   
str | Noner   strreturnNone)r$   r   r%   r   rI   rH   )r$   r   r-   rH   rI   r   )r$   r   rI   r   r$   r   r%   r   rI   zResponse | None)r$   r   rI   rJ   )
__name__
__module____qualname____doc__r   r&   r/   r3   rD   r?    r    r   r   r      sk    4
 #'	
"
"  
" 	
"
 

"$
J*5<	*Q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.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 future to exit the server
        stop = asyncio.get_running_loop().create_future()

        async with route(url_map, ...) as server:
            await stop


    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.

    NrF   wssTrQ   process_requestc                   K    | |      }t        |t              r
| d {   }||S j                  | |      S 7 wN)
isinstancer   rD   )r$   r%   r.   _process_requestrouters      r   rU   zroute.<locals>.process_request   sI      (
G<H(I.!)>#''
G<< *s   ?=?rK   )r   poprD   r   r?   )
r   r   rQ   rR   argsrC   r   rU   rY   rZ   s
           @@r   r   r   I   s    R %J
$3?u7K<F 	

$d+      		=(	=3:	=	= R$RR6RRr    c                     t        | fd|d|S )aN  
    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)unixr;   )r   )r   r;   rC   s      r   r   r      s      9t$9&99r    )r   r	   r\   r   r   rG   rQ   z,ssl_module.SSLContext | Literal[True] | NonerR   ztype[Router] | NonerC   r   rI   Awaitable[Server]rW   )r   r	   r;   rG   rC   r   rI   r_   )
__future__r   r*   rQ   
ssl_moduleurllib.parser8   typingr   r   r   r   werkzeug.exceptionsr   werkzeug.routingr	   r
   http11r   r   serverr   r   r   __all__r   r   r   rP   r    r   <module>ri      s    "    4 4 ( 1 & 3 3 ,4Q 4Qt #8<)-jSjSjS jS 
6	jS
 'jS jS jS^ ::
: : 	:r    