403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/websockets/legacy/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/websockets/legacy/__pycache__/server.cpython-311.pyc
�

�=Xc���"�ddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZmZmZmZmZmZmZmZmZmZmZmZddlmZddlmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(dd	l)m*Z*m+Z+dd
l,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2ddlm3Z3dd
l
m4Z4m5Z5m6Z6m7Z7ddl8m9Z9ddl:m;Z;m<Z<ddlm=Z=ddl>m?Z?gd�Z@eeeeAegeffZBeejCeeDfZEGd�de?��ZFGd�d��ZGGd�d��ZHeHZI	d$d%d!�ZJd&d#�ZKdS)'�)�annotationsN)�
TracebackType)
�Any�	Awaitable�Callable�	Generator�Iterable�List�Optional�Sequence�Set�Tuple�Type�Union�cast�)�State)�Headers�HeadersLike�MultipleValuesError)�AbortHandshake�InvalidHandshake�
InvalidHeader�InvalidMessage�
InvalidOrigin�InvalidUpgrade�NegotiationError)�	Extension�ServerExtensionFactory)� enable_server_permessage_deflate)�build_extension�parse_extension�parse_subprotocol�validate_subprotocols)�
USER_AGENT)�ExtensionHeader�
LoggerLike�Origin�Subprotocol�)�loop_if_py_lt_38)�build_response�
check_request)�read_request)�WebSocketCommonProtocol)�serve�
unix_serve�WebSocketServerProtocol�WebSocketServerc	����eZdZdZdZdZdddddeddd�d>�fd�Zd?�fd!�Zd@d"�Z	dAd$�Z
	dBdCd+�ZdDd0�Ze
	dBdEd2���Ze
dFd5���ZdGd8�ZdHd<�Z				dIdJd=�Z�xZS)Kr2az
    WebSocket server connection.

    :class:`WebSocketServerProtocol` provides :meth:`recv` and :meth:`send`
    coroutines for receiving and sending messages.

    It supports asynchronous iteration to receive messages::

        async for message in websocket:
            await process(message)

    The iterator exits normally when the connection is closed with close code
    1000 (OK) or 1001 (going away). It raises
    a :exc:`~websockets.exceptions.ConnectionClosedError` when the connection
    is closed with any other code.

    You may customize the opening handshake in a subclass by
    overriding :meth:`process_request` or :meth:`select_subprotocol`.

    Args:
        ws_server: WebSocket server that created this connection.

    See :func:`serve` for the documentation of ``ws_handler``, ``logger``, ``origins``,
    ``extensions``, ``subprotocols``, ``extra_headers``, and ``server_header``.

    See :class:`~websockets.legacy.protocol.WebSocketCommonProtocol` for the
    documentation of ``ping_interval``, ``ping_timeout``, ``close_timeout``,
    ``max_size``, ``max_queue``, ``read_limit``, and ``write_limit``.

    F�serverN)�logger�origins�
extensions�subprotocols�
extra_headers�
server_header�process_request�select_subprotocol�
ws_handler�tUnion[Callable[[WebSocketServerProtocol], Awaitable[Any]], Callable[[WebSocketServerProtocol, str], Awaitable[Any]]]�	ws_serverr3r6�Optional[LoggerLike]r7�$Optional[Sequence[Optional[Origin]]]r8�*Optional[Sequence[ServerExtensionFactory]]r9�Optional[Sequence[Subprotocol]]r:�Optional[HeadersLikeOrCallable]r;�
Optional[str]r<�EOptional[Callable[[str, Headers], Awaitable[Optional[HTTPResponse]]]]r=�OOptional[Callable[[Sequence[Subprotocol], Sequence[Subprotocol]], Subprotocol]]�kwargsr�return�Nonec�Z��|�tjd��}t��jdd|i|��|�*d|vr&t	jdt��d�|D��}t|��|_||_	||_
||_||_||_
||_|	|_|
|_dS)N�websockets.serverr6�z!use None instead of '' in originsc�"�g|]}|dkrdn|��
S)rNN�)�.0�origins  �:/usr/lib/python3/dist-packages/websockets/legacy/server.py�
<listcomp>z4WebSocketServerProtocol.__init__.<locals>.<listcomp>~s$��N�N�N�F�v��|�|�t�t��N�N�N�rP)�logging�	getLogger�super�__init__�warnings�warn�DeprecationWarning�remove_path_argumentr>r@r7�available_extensions�available_subprotocolsr:r;�_process_request�_select_subprotocol)
�selfr>r@r6r7r8r9r:r;r<r=rI�	__class__s
            �rSrYz WebSocketServerProtocol.__init__bs����,�>��&�':�;�;�F������1�1��1�&�1�1�1���2��=�=��M�=�?Q�R�R�R�N�N�g�N�N�N�G�/�z�:�:���"������$.��!�&2��#�*���*��� /���#5�� � � rU�	transport�asyncio.BaseTransportc����t���|��|j�|��|j�|�����|_dS)zJ
        Register connection and initialize a task to handle it.

        N)rX�connection_mader@�register�loop�create_task�handler�handler_task)rbrdrcs  �rSrgz'WebSocketServerProtocol.connection_made�s[���
	�����	�*�*�*�
	
�����%�%�%� �I�1�1�$�,�,�.�.�A�A����rUc	��	K�		|�|j|j|j|j����d{V���n+#t
j$r�t$r�t$�r}t|t��r|j|j|j
}}}�n�t|t��r\|jr|j�dd���t"jjt)��d|�d����}}}�nt|t,��r]|jr|j�dd���t"jjt)d	g��d|�d
����}}}n�t|t0��r[|jr|j�dd���t"jjt)��d|�d����}}}n=|j�dd���t"jjt)��d
}}}|�dt:j�d�����|j �|�d|j ��|�dtCtE|������|�dd��|�dd��|�#|||��|j�$d|j%|j&��|�'���d{V��Yd}~|j(�)|��|j�$d��dSd}~wwxYw	|�*|���d{V��nG#t$r:|j�dd���|j+s|�,d���wxYw	|�-���d{V��n5#t$r�t$r|j�dd����wxYwn;#t$r.	|j.�-��n#t$rYnwxYwYnwxYw|j(�)|��|j�$d��dS#|j(�)|��|j�$d��wxYw)a
        Handle the lifecycle of a WebSocket connection.

        Since this method doesn't have a caller able to handle exceptions, it
        attempts to log relevant ones and guarantees that the TCP connection is
        closed before exiting.

        )r7r^r_r:Nz! invalid originT)�exc_infoz'Failed to open a WebSocket connection: z.
z! invalid upgrade)�Upgrade�	websocketz^.

You cannot access a WebSocket server directly with a browser. You need a WebSocket client.
z! invalid handshakezopening handshake failedsLFailed to open a WebSocket connection.
See server log for more information.
�Date��usegmt�ServerzContent-LengthzContent-Typez
text/plain�
Connection�closezconnection failed (%d %s)zconnection closedzconnection handler failedi�zclosing handshake failed)/�	handshaker7r^r_r:�asyncio�CancelledError�ConnectionError�	Exception�
isinstancer�status�headers�bodyr�debugr6�http�
HTTPStatus�	FORBIDDENr�encoder�UPGRADE_REQUIREDr�BAD_REQUEST�error�INTERNAL_SERVER_ERROR�
setdefault�email�utils�
formatdater;�str�len�write_http_response�info�value�phrase�close_transportr@�
unregisterr>�closed�fail_connectionrvrd)rb�excr}r~rs     rSrkzWebSocketServerProtocol.handler�s|����f	2�E
��n�n� �L�)-�)B�+/�+F�"&�"4�	%�������������)�
�
�
��"�
�
�
���8
�8
�8
��c�>�2�2�(�,/�J���S�X�T�G�F�F���]�3�3�&��z�M���)�)�*<�t�)�L�L�L���1��	�	�J�#�J�J�J�Q�Q�S�S�&*�G�F�F�
 ��^�4�4���z�N���)�)�*=��)�M�M�M���8��!9� :�;�;�N�c�N�N�N�!�&�(�(�&*�G�F�F� ��%5�6�6���z�P���)�)�*?�$�)�O�O�O���3��	�	�J�#�J�J�J�Q�Q�S�S�&*�G�F�F��K�%�%�&@�4�%�P�P�P���=��	�	�F�	&*�G�F��"�"�6�5�;�+A�+A��+A�+N�+N�O�O�O��%�1��&�&�x��1C�D�D�D��"�"�#3�S��T���^�^�D�D�D��"�"�>�<�@�@�@��"�"�<��9�9�9��(�(���$�?�?�?��� � �/���v�}�����*�*�,�,�,�,�,�,�,�,�,�����<
�N�%�%�d�+�+�+��K���0�1�1�1�1�1�����o8
����t
��o�o�d�+�+�+�+�+�+�+�+�+�+���
�
�
���!�!�"=��!�M�M�M��{�/��(�(��.�.�.��	
����
��j�j�l�l�"�"�"�"�"�"�"�"��"�
�
�
���
�
�
���!�!�"<�t�!�L�L�L��
����#���	�	�	�
���$�$�&�&�&�&���
�
�
���
������		����
�N�%�%�d�+�+�+��K���0�1�1�1�1�1��
�N�%�%�d�+�+�+��K���0�1�1�1�1���s��3:�P�$M"�KM�#P�M"�"P�&N�P�AO�P�
O%�$P�%2P�P�R�
Q�&Q�?Q�
Q
�
Q�Q
�
Q�R�Q�R�6S�Tuple[str, Headers]c��zK�	t|j���d{V��\}}n1#tj$r�t$r}td��|�d}~wwxYw|jrQ|j�d|��|���D]!\}}|j�d||���"||_	||_
||fS)a:
        Read request line and headers from the HTTP request.

        If the request contains a body, it may be read from ``self.reader``
        after this coroutine returns.

        Raises:
            InvalidMessage: if the HTTP message is malformed or isn't an
                HTTP/1.1 GET request.

        Nz$did not receive a valid HTTP requestz< GET %s HTTP/1.1z< %s: %s)r.�readerrxryr{rr�r6�	raw_items�path�request_headers)rbr�r~r��keyr�s      rS�read_http_requestz)WebSocketServerProtocol.read_http_request
s�����	R�".�t�{�";�";�;�;�;�;�;�;�M�D�'�'���%�	�	�	���	R�	R�	R� �!G�H�H�c�Q�����	R�����:�	:��K���1�4�8�8�8�%�/�/�1�1�
:�
:�
��U���!�!�*�c�5�9�9�9�9���	�&����W�}�s�"�A�A�Ar}�http.HTTPStatusr~rr�Optional[bytes]c��||_|jr�|j�d|j|j��|���D]!\}}|j�d||���"|�(|j�dt
|����d|j�d|j�d�}|t|��z
}|j�	|�
����|�|j�	|��dSdS)z�
        Write status line and headers to the HTTP response.

        This coroutine is also able to write a response body.

        z> HTTP/1.1 %d %sz> %s: %sNz> [body] (%d bytes)z	HTTP/1.1 � z
)�response_headersr�r6r�r�r�r�r�rd�writer�)rbr}r~rr�r��responses       rSr�z+WebSocketServerProtocol.write_http_response's��!(����:�	D��K���0�&�,��
�N�N�N�%�/�/�1�1�
:�
:�
��U���!�!�*�c�5�9�9�9�9�����!�!�"7��T���C�C�C�B�v�|�A�A�f�m�A�A�A���C��L�L� ������X�_�_�.�.�/�/�/����N� � ��&�&�&�&�&��rUr�r�r��Optional[HTTPResponse]c��K�|j�O|�||��}t|t��r|�d{V��Stjdt
��|SdS)a�
        Intercept the HTTP request and return an HTTP response if appropriate.

        You may override this method in a :class:`WebSocketServerProtocol`
        subclass, for example:

        * to return a HTTP 200 OK response on a given path; then a load
          balancer can use this path for a health check;
        * to authenticate the request and return a HTTP 401 Unauthorized or a
          HTTP 403 Forbidden when authentication fails.

        You may also override this method with the ``process_request``
        argument of :func:`serve` and :class:`WebSocketServerProtocol`. This
        is equivalent, except ``process_request`` won't have access to the
        protocol instance, so it can't store information for later use.

        :meth:`process_request` is expected to complete quickly. If it may run
        for a long time, then it should await :meth:`wait_closed` and exit if
        :meth:`wait_closed` completes, or else it could prevent the server
        from shutting down.

        Args:
            path: request path, including optional query string.
            request_headers: request headers.

        Returns:
            Optional[Tuple[http.HTTPStatus, HeadersLike, bytes]]: :obj:`None`
            to continue the WebSocket handshake normally.

            An HTTP response, represented by a 3-uple of the response status,
            headers, and body, to abort the WebSocket handshake and return
            that HTTP response instead.

        N�&declare process_request as a coroutine)r`r|rrZr[r\)rbr�r�r�s    rSr<z'WebSocketServerProtocol.process_requestCss����J� �,��,�,�T�?�C�C�H��(�I�.�.�
 �%�~�~�~�~�~�~�%��
�<�>P���� ���trU�Optional[Origin]c���	ttt|�d����}n##t$r}tdd��|�d}~wwxYw|�||vrt
|���|S)z�
        Handle the Origin HTTP request header.

        Args:
            headers: request headers.
            origins: optional list of acceptable origins.

        Raises:
            InvalidOrigin: if the origin isn't acceptable.

        r(z!more than one Origin header foundN)rrr(�getrrr)r~r7rRr�s    rS�process_originz&WebSocketServerProtocol.process_origints���"	X��(�6�*�G�K�K��,A�,A�B�B�F�F��"�	X�	X�	X���*M�N�N�TW�W�����	X�������W�$�$�#�F�+�+�+��
s�36�
A�A�Ar^�%Tuple[Optional[str], List[Extension]]c�~�d}g}g}|�d��}|r�|r�td�|D��g��}|D]m\}}|D]e}	|	j|kr�	|	�||��\}
}n#t$rY�5wxYw|�||
f��|�|���n|rt
|��}||fS)a�
        Handle the Sec-WebSocket-Extensions HTTP request header.

        Accept or reject each extension proposed in the client request.
        Negotiate parameters for accepted extensions.

        Return the Sec-WebSocket-Extensions HTTP response header and the list
        of accepted extensions.

        :rfc:`6455` leaves the rules up to the specification of each
        :extension.

        To provide this level of flexibility, for each extension proposed by
        the client, we check for a match with each extension available in the
        server configuration. If no match is found, the extension is ignored.

        If several variants of the same extension are proposed by the client,
        it may be accepted several times, which won't make sense in general.
        Extensions must implement their own requirements. For this purpose,
        the list of previously accepted extensions is provided.

        This process doesn't allow the server to reorder extensions. It can
        only select a subset of the extensions proposed by the client.

        Other requirements, for example related to mandatory extensions or the
        order of extensions, may be implemented by overriding this method.

        Args:
            headers: request headers.
            extensions: optional list of supported extensions.

        Raises:
            InvalidHandshake: to abort the handshake with an HTTP 400 error.

        N�Sec-WebSocket-Extensionsc�,�g|]}t|����SrP)r"�rQ�header_values  rSrTz>WebSocketServerProtocol.process_extensions.<locals>.<listcomp>�s ��Q�Q�Q�<���.�.�Q�Q�QrU)�get_all�sum�name�process_request_paramsr�appendr!)r~r^�response_header_value�extension_headers�accepted_extensions�
header_values�parsed_header_valuesr��request_params�ext_factory�response_params�	extensions            rS�process_extensionsz*WebSocketServerProtocol.process_extensions�s9��P04��35��/1�����(B�C�C�
��	�1�	�:=�Q�Q�=�Q�Q�Q�SU�;�;� �)=�
�
�$��n�#7���K�#�'�4�/�/� �!�5@�5W�5W�*�,?�6�6�2�����,�!�!�!� ��!����&�,�,�d�O�-D�E�E�E�'�.�.�y�9�9�9����	G�$3�4E�$F�$F�!�$�&9�9�9s�A,�,
A9�8A9r_�Optional[Subprotocol]c��d}|�d��}|r2|r0td�|D��g��}|�||��}|S)a�
        Handle the Sec-WebSocket-Protocol HTTP request header.

        Return Sec-WebSocket-Protocol HTTP response header, which is the same
        as the selected subprotocol.

        Args:
            headers: request headers.
            available_subprotocols: optional list of supported subprotocols.

        Raises:
            InvalidHandshake: to abort the handshake with an HTTP 400 error.

        N�Sec-WebSocket-Protocolc�,�g|]}t|����SrP)r#r�s  rSrTz?WebSocketServerProtocol.process_subprotocol.<locals>.<listcomp>�s!��S�S�S�\�"�<�0�0�S�S�SrU)r�r�r=)rbr~r_�subprotocolr�r�s      rS�process_subprotocolz+WebSocketServerProtocol.process_subprotocol�st��".2�����(@�A�A�
��	�3�	�69�S�S�]�S�S�S�UW�7�7� ��1�1�$�&<���K��rU�client_subprotocols�Sequence[Subprotocol]�server_subprotocolsc����|j�|�����St���t���z}|sdS��fd�}t||���dS)a@
        Pick a subprotocol among those offered by the client.

        If several subprotocols are supported by the client and the server,
        the default implementation selects the preferred subprotocol by
        giving equal value to the priorities of the client and the server.
        If no subprotocol is supported by the client and the server, it
        proceeds without a subprotocol.

        This is unlikely to be the most useful implementation in practice.
        Many servers providing a subprotocol will require that the client
        uses that subprotocol. Such rules can be implemented in a subclass.

        You may also override this method with the ``select_subprotocol``
        argument of :func:`serve` and :class:`WebSocketServerProtocol`.

        Args:
            client_subprotocols: list of subprotocols offered by the client.
            server_subprotocols: list of subprotocols available on the server.

        Returns:
            Optional[Subprotocol]: Selected subprotocol.

            :obj:`None` to continue without a subprotocol.


        Nc�Z����|����|��zS�N)�index)�pr�r�s ��rS�<lambda>z<WebSocketServerProtocol.select_subprotocol.<locals>.<lambda>+s-����%�%�a�(�(�+>�+D�+D�Q�+G�+G�G�rU)r�r)ra�set�sorted)rbr�r�r9�prioritys ``  rSr=z*WebSocketServerProtocol.select_subprotocols�����@�#�/��+�+�,?�AT�U�U�U��.�/�/�#�6I�2J�2J�J���	��4�
�
�
�
�
���l��1�1�1�!�4�4rUc��zK�|����d{V��\}}|�||��}t|t��r	|�d{V��}nt	jdt��|}|jtj	urtd���|j���stjjgdf}|�	t!|��t#|��}	|�||��|_|�||��\}
|_|�||��x}|_t1��}t3||	��|
�|
|d<|�||d<t5|��r|||j��}|�|�|��|�dt<j� d�	����|j!�|�d
|j!��|�"tjj#|��|j$�%d��|�&��|S)a�
        Perform the server side of the opening handshake.

        Args:
            origins: list of acceptable values of the Origin HTTP header;
                include :obj:`None` if the lack of an origin is acceptable.
            extensions: list of supported extensions, in order in which they
                should be tried.
            subprotocols: list of supported subprotocols, in order of
                decreasing preference.
            extra_headers: arbitrary HTTP headers to add to the response when
                the handshake succeeds.

        Returns:
            str: path of the URI of the request.

        Raises:
            InvalidHandshake: if the handshake fails.

        Nr�z*connection closed during opening handshakesServer is shutting down.
r�r�rqTrrrtzconnection open)'r�r<r|rrZr[r\�stater�CLOSED�BrokenPipeErrorr@�
is_servingr�r��SERVICE_UNAVAILABLErr-r�rRr�r8r�r�rr,�callabler��updater�r�r�r�r;r��SWITCHING_PROTOCOLSr6r��connection_open)
rbr7r^r_r:r�r��early_response_awaitable�early_responser��extensions_header�protocol_headerr�s
             rSrwz!WebSocketServerProtocol.handshake0sr����6'+�&<�&<�&>�&>� >� >� >� >� >� >���o�$(�#7�#7��o�#N�#N� ��.�	�:�:�	6�#;�;�;�;�;�;�;�N�N�
�M�B�DV�W�W�W�5�N��:���%�%�!�"N�O�O�O��~�(�(�*�*�	���3��-��N��%� �.�1�1��O�,�,���)�)�/�7�C�C���-1�-D�-D��1�.
�.
�*��4�?�.2�-E�-E��3�.
�.
�	
��$�*�#�9�9���'��-�-�-��(�;L��7�8��&�9H��5�6��M�"�"�	F�)�M�$��0D�E�E�M��$��#�#�M�2�2�2��#�#�F�E�K�,B�,B�$�,B�,O�,O�P�P�P���)��'�'��$�2D�E�E�E�� � ���!D�FV�W�W�W�����*�+�+�+��������rU)r>r?r@r3r6rAr7rBr8rCr9rDr:rEr;rFr<rGr=rHrIrrJrK)rdrerJrK�rJrK)rJr�r�)r}r�r~rrr�rJrK)r�r�r�rrJr�)r~rr7rBrJr�)r~rr^rCrJr�)r~rr_rDrJr�)r�r�r�r�rJr�)NNNN)
r7rBr^rCr_rDr:rErJr�)�__name__�
__module__�__qualname__�__doc__�	is_client�sider%rYrgrkr�r�r<�staticmethodr�r�r�r=rw�
__classcell__)rcs@rSr2r2?s����������>�I��D�(,�8<�AE�8<�9=�'1�
�
�'(6�(6�(6�(6�(6�(6�(6�(6�TB�B�B�B�B�B�o2�o2�o2�o2�b����<RV�'�'�'�'�'�8/�/�/�/�b�JN������\��2�R:�R:�R:��\�R:�j����B)5�)5�)5�)5�Z9=�KO�BF�9=�\�\�\�\�\�\�\�\�\rUr2c��eZdZdZd"d#d�Zd$d
�Zd%d
�Zd%d�Zd&d�Zd&d�Z	d&d�Z
d'd�Zd(d�Zd&d�Z
d&d�Zed)d���Zd*d�Zd+d!�ZdS),r3a
    WebSocket server returned by :func:`serve`.

    This class provides the same interface as :class:`~asyncio.Server`,
    notably the :meth:`~asyncio.Server.close`
    and :meth:`~asyncio.Server.wait_closed` methods.

    It keeps track of WebSocket connections in order to close them properly
    when shutting down.

    Args:
        logger: logger for this server;
            defaults to ``logging.getLogger("websockets.server")``;
            see the :doc:`logging guide <../topics/logging>` for details.

    Nr6rAc�x�|�tjd��}||_t��|_d|_|dS)NrM)rVrWr6r��
websockets�
close_task)rbr6s  rSrYzWebSocketServer.__init__�sC���>��&�':�;�;�F����9<�����9=���	
�0�0�0rUr5�asyncio.base_events.ServerrJrKc��||_|jD]�}|jtjkrd|���z}n�|jtjkr d|���dd�z}nK|jtjkr|���}n!t|�����}|j	�
d|����|������|_
dS)a
        Attach to a given :class:`~asyncio.Server`.

        Since :meth:`~asyncio.loop.create_server` doesn't support injecting a
        custom ``Server`` class, the easiest solution that doesn't rely on
        private :mod:`asyncio` APIs is to:

        - instantiate a :class:`WebSocketServer`
        - give the protocol factory a reference to that instance
        - call :meth:`~asyncio.loop.create_server` with the factory
        - attach the resulting :class:`~asyncio.Server` with this method

        z%s:%dz[%s]:%dNrzserver listening on %s)r5�sockets�family�socket�AF_INET�getsockname�AF_INET6�AF_UNIXr�r6r��get_loop�
create_future�
closed_waiter)rbr5�sockr�s    rS�wrapzWebSocketServer.wrap�s�������N�	=�	=�D��{�f�n�,�,���!1�!1�!3�!3�3�������/�/� �4�#3�#3�#5�#5�b�q�b�#9�9�������.�.��'�'�)�)����4�+�+�-�-�.�.���K���5�t�<�<�<�<�$�_�_�.�.�<�<�>�>����rU�protocolr2c�:�|j�|��dS)z:
        Register a connection with this server.

        N)r��add�rbr�s  rSrhzWebSocketServer.register�s ��
	
����H�%�%�%�%�%rUc�:�|j�|��dS)z<
        Unregister a connection with this server.

        N)r��removers  rSr�zWebSocketServer.unregister�s ��
	
����x�(�(�(�(�(rUc��|j�@|����|�����|_dSdS)a�
        Close the server.

        This method:

        * closes the underlying :class:`~asyncio.Server`;
        * rejects new WebSocket connections with an HTTP 503 (service
          unavailable) error; this happens when the server accepted the TCP
          connection but didn't complete the WebSocket opening handshake prior
          to closing;
        * closes open WebSocket connections with close code 1001 (going away).

        :meth:`close` is idempotent.

        N)r�r�rj�_close�rbs rSrvzWebSocketServer.close�s=�� �?�"�"�m�m�o�o�9�9�$�+�+�-�-�H�H�D�O�O�O�#�"rUc��K�|j�d��|j���|j����d{V��tjdit|��������d{V��d�|j	D��}|r7tj
|fit|��������d{V��|j	rFtj
d�|j	D��fit|��������d{V��|j�d��|j�d��dS)a
        Implementation of :meth:`close`.

        This calls :meth:`~asyncio.Server.close` on the underlying
        :class:`~asyncio.Server` object to stop accepting new connections and
        then closes open connections with close code 1001.

        zserver closingNrc��g|]<}|jtju�tj|�d������=S)i�)r�r�
CONNECTINGrxrjrv�rQrps  rSrTz*WebSocketServer._close.<locals>.<listcomp>	sI��
�
�
����e�&6�6�6�
��	���� 5� 5�6�6�6�6�6rUc��g|]	}|j��
SrP)rlr
s  rSrTz*WebSocketServer._close.<locals>.<listcomp>s��I�I�I�I��'�I�I�IrUz
server closed)r)
r6r�r5rv�wait_closedrx�sleepr+r�r��waitr��
set_result)rb�close_taskss  rSrzWebSocketServer._close�s�����	
����)�*�*�*�	
��������k�%�%�'�'�'�'�'�'�'�'�'��m�C�C�!1�$�-�-�/�/�!B�!B�C�C�C�C�C�C�C�C�C�
�
�!�_�
�
�
���	��,����"�4�=�=�?�?�3�3���
�
�
�
�
�
�
��?�	��,�I�I���I�I�I���"�4�=�=�?�?�3�3���
�
�
�
�
�
�
�	
��%�%�d�+�+�+������)�)�)�)�)rUc��HK�tj|j���d{V��dS)a�
        Wait until the server is closed.

        When :meth:`wait_closed` returns, all TCP connections are closed and
        all connection handlers have returned.

        To ensure a fast shutdown, a connection handler should always be
        awaiting at least one of:

        * :meth:`~WebSocketServerProtocol.recv`: when the connection is closed,
          it raises :exc:`~websockets.exceptions.ConnectionClosedOK`;
        * :meth:`~WebSocketServerProtocol.wait_closed`: when the connection is
          closed, it returns.

        Then the connection handler is immediately notified of the shutdown;
        it can clean up and exit.

        N)rx�shieldr�rs rSrzWebSocketServer.wait_closed#s3����&�n�T�/�0�0�0�0�0�0�0�0�0�0�0rU�asyncio.AbstractEventLoopc�4�|j���S)z7
        See :meth:`asyncio.Server.get_loop`.

        )r5r�rs rSr�zWebSocketServer.get_loop8s��
�{�#�#�%�%�%rU�boolc�4�|j���S)z9
        See :meth:`asyncio.Server.is_serving`.

        )r5r�rs rSr�zWebSocketServer.is_serving?s��
�{�%�%�'�'�'rUc��HK�|j����d{V��dS)a
        See :meth:`asyncio.Server.start_serving`.

        Typical use::

            server = await serve(..., start_serving=False)
            # perform additional setup here...
            # ... then start the server
            await server.start_serving()

        N)r5�
start_servingrs rSrzWebSocketServer.start_servingFs4�����k�'�'�)�)�)�)�)�)�)�)�)�)�)rUc��HK�|j����d{V��dS)a�
        See :meth:`asyncio.Server.serve_forever`.

        Typical use::

            server = await serve(...)
            # this coroutine doesn't return
            # canceling it stops the server
            await server.serve_forever()

        This is an alternative to using :func:`serve` as an asynchronous context
        manager. Shutdown is triggered by canceling :meth:`serve_forever`
        instead of exiting a :func:`serve` context.

        N)r5�
serve_foreverrs rSrzWebSocketServer.serve_foreverTs4���� �k�'�'�)�)�)�)�)�)�)�)�)�)�)rU�Iterable[socket.socket]c��|jjS)z6
        See :attr:`asyncio.Server.sockets`.

        )r5r�rs rSr�zWebSocketServer.socketsfs���{�"�"rUc��
K�|Sr�rPrs rS�
__aenter__zWebSocketServer.__aenter__ns�����rU�exc_type�Optional[Type[BaseException]]�	exc_value�Optional[BaseException]�	traceback�Optional[TracebackType]c��fK�|���|����d{V��dSr�)rvr�rbrr!r#s    rS�	__aexit__zWebSocketServer.__aexit__qs?����	
�
�
������� � � � � � � � � � � rUr�)r6rA)r5r�rJrK)r�r2rJrKr�)rJr)rJr)rJr�rJr3�rr r!r"r#r$rJrK)r�r�r�r�rYr�rhr�rvrrr�r�rr�propertyr�rr'rPrUrSr3r3�sM��������"1�1�1�1�1�?�?�?�?�@&�&�&�&�)�)�)�)�I�I�I�I�&1*�1*�1*�1*�f1�1�1�1�*&�&�&�&�(�(�(�(�*�*�*�*�*�*�*�*�$�#�#�#��X�#�����!�!�!�!�!�!rUr3c�j�eZdZdZ		d<dddddddedddddddddd�d=d/�Zd>d1�Zd?d8�Zd@d:�Zd>d;�Z	eZ
dS)A�Servea�
    Start a WebSocket server listening on ``host`` and ``port``.

    Whenever a client connects, the server creates a
    :class:`WebSocketServerProtocol`, performs the opening handshake, and
    delegates to the connection handler, ``ws_handler``.

    The handler receives the :class:`WebSocketServerProtocol` and uses it to
    send and receive messages.

    Once the handler completes, either normally or with an exception, the
    server performs the closing handshake and closes the connection.

    Awaiting :func:`serve` yields a :class:`WebSocketServer`. This object
    provides :meth:`~WebSocketServer.close` and
    :meth:`~WebSocketServer.wait_closed` methods for shutting down the server.

    :func:`serve` can be used as an asynchronous context manager::

        stop = asyncio.Future()  # set this future to exit the server

        async with serve(...):
            await stop

    The server is shut down automatically when exiting the context.

    Args:
        ws_handler: connection handler. It receives the WebSocket connection,
            which is a :class:`WebSocketServerProtocol`, in argument.
        host: network interfaces the server is bound to;
            see :meth:`~asyncio.loop.create_server` for details.
        port: TCP port the server listens on;
            see :meth:`~asyncio.loop.create_server` for details.
        create_protocol: factory for the :class:`asyncio.Protocol` managing
            the connection; defaults to :class:`WebSocketServerProtocol`; may
            be set to a wrapper or a subclass to customize connection handling.
        logger: logger for this server;
            defaults to ``logging.getLogger("websockets.server")``;
            see the :doc:`logging guide <../topics/logging>` for details.
        compression: shortcut that enables the "permessage-deflate" extension
            by default; may be set to :obj:`None` to disable compression;
            see the :doc:`compression guide <../topics/compression>` for details.
        origins: acceptable values of the ``Origin`` header; include
            :obj:`None` in the list if the lack of an origin is acceptable.
            This is useful for defending against Cross-Site WebSocket
            Hijacking attacks.
        extensions: list of supported extensions, in order in which they
            should be tried.
        subprotocols: list of supported subprotocols, in order of decreasing
            preference.
        extra_headers (Union[HeadersLike, Callable[[str, Headers], HeadersLike]]):
            arbitrary HTTP headers to add to the request; this can be
            a :data:`~websockets.datastructures.HeadersLike` or a callable
            taking the request path and headers in arguments and returning
            a :data:`~websockets.datastructures.HeadersLike`.
        server_header: value of  the ``Server`` response header;
            defaults to ``"Python/x.y.z websockets/X.Y"``;
            :obj:`None` removes the header.
        process_request (Optional[Callable[[str, Headers],             Awaitable[Optional[Tuple[http.HTTPStatus, HeadersLike, bytes]]]]]):
            intercept HTTP request before the opening handshake;
            see :meth:`~WebSocketServerProtocol.process_request` for details.
        select_subprotocol: select a subprotocol supported by the client;
            see :meth:`~WebSocketServerProtocol.select_subprotocol` for details.

    See :class:`~websockets.legacy.protocol.WebSocketCommonProtocol` for the
    documentation of ``ping_interval``, ``ping_timeout``, ``close_timeout``,
    ``max_size``, ``max_queue``, ``read_limit``, and ``write_limit``.

    Any other keyword arguments are passed the event loop's
    :meth:`~asyncio.loop.create_server` method.

    For example:

    * You can set ``ssl`` to a :class:`~ssl.SSLContext` to enable TLS.

    * You can set ``sock`` to a :obj:`~socket.socket` that you created
      outside of websockets.

    Returns:
        WebSocketServer: WebSocket server.

    N�deflate�i� i)�create_protocolr6�compressionr7r8r9r:r;r<r=�
ping_interval�ping_timeout�
close_timeout�max_size�	max_queue�
read_limit�write_limitr>r?�host�#Optional[Union[str, Sequence[str]]]�port�
Optional[int]r0�2Optional[Callable[[Any], WebSocketServerProtocol]]r6rAr1rFr7rBr8rCr9rDr:rEr;r<rGr=rHr2�Optional[float]r3r4r5r6r7�intr8rIrrJrKc��|�dd��}|�d}ntjdt��|�|}|�dd��}|�t}ntjdt��|�|}|�dd��}|�dd��}|�tj��}n|}tjd	t��t|�
��}|�d��du}|dkrt|��}n|�td
|�����|	�t|	��tj
|t|��|fid|�d|�d|�d|�d|�d|�d|�d|�d|�d|�d|�d|�d|�d|�d|	�d|
�d|�d|�d|
�d|��}|�d d��r6|�d!d��}|�|�J�tj
|j||fi|��}ntj
|j|||fi|��}||_||_dS)"N�timeout�
zrename timeout to close_timeout�klasszrename klass to create_protocol�legacy_recvFrizremove loop argument)r6�sslr-zunsupported compression: r9r;�securer2r3r4r5r6r7r8r7r8r9r:r;r<r=r6�unixr�)�poprZr[r\r2rx�get_event_loopr3r�r �
ValueErrorr$�	functools�partialr]�create_unix_server�
create_server�_create_serverr@) rbr>r9r;r0r6r1r7r8r9r:r;r<r=r2r3r4r5r6r7r8rIrArCrD�_looprir@rF�factoryr�rNs                                 rSrYzServe.__init__�s
��B$*�:�:�i��#>�#>���?��G�G��M�;�=O�P�P�P�� �#�M�:@���G�T�9R�9R���=�+�E�E��M�;�=O�P�P�P��"�#�O�#�J�J�}�e�<�<��6<�Z�Z���5M�5M���=��)�+�+�D�D��D��M�0�2D�E�E�E�#�6�2�2�2�	����E�"�"�$�.���)�#�#�9�*�E�E�J�J�
�
$��F��F�F�G�G�G��#�!�,�/�/�/��#��
!��,�,��

�
�
���
���
��6�
�(�-�
�&��
�(�-�
��X�
� �i�
�"�z�
� $��!
�"��#
�$$��%
�&�G�'
�("�z�)
�*&��+
�,(�-�-
�.(�-�/
�0,�O�1
�2 2�1�3
�4�6�5
��:�:�:�f�e�$�$�
	�"(�*�*�V�T�":�":�D��<�D�L�L�L�%�-��'��$���:@���M�M�&�-��"�G�T�4���;A���M�
,���"����rUr3c��K�|�d{V��Sr�rPrs rSrzServe.__aenter__Js�����z�z�z�z�z�z�rUrr r!r"r#r$c��zK�|j���|j����d{V��dSr�)r@rvrr&s    rSr'zServe.__aexit__MsH����	
��������n�(�(�*�*�*�*�*�*�*�*�*�*�*rU�%Generator[Any, None, WebSocketServer]c�N�|������Sr�)�__await_impl__�	__await__rs rSrWzServe.__await__Xs ���"�"�$�$�.�.�0�0�0rUc��|K�|����d{V��}|j�|��|jSr�)rOr@r�)rbr5s  rSrVzServe.__await_impl__\sG�����*�*�,�,�,�,�,�,�,�,������F�#�#�#��~�rU)NN),r>r?r9r:r;r<r0r=r6rAr1rFr7rBr8rCr9rDr:rEr;rFr<rGr=rHr2r>r3r>r4r>r5r<r6r<r7r?r8r?rIrrJrKr(r))rJrT)r�r�r�r�r%rYrr'rWrV�__iter__rPrUrSr,r,{s�������R�R�t59�"�v#�OS�'+�%.�8<�AE�8<�9=�'1�
�
�)+�(*�)-�"'�#'�� �;v#�v#�v#�v#�v#�v#�t����+�+�+�+�1�1�1�1������H�H�HrUr,r>r?r�rFrIrrJc�"�t|f|dd�|��S)a[
    Similar to :func:`serve`, but for listening on Unix sockets.

    This function builds upon the event
    loop's :meth:`~asyncio.loop.create_unix_server` method.

    It is only available on Unix.

    It's useful for deploying a server behind a reverse proxy such as nginx.

    Args:
        path: file system path to the Unix socket.

    T)r�rG)r0)r>r�rIs   rSr1r1is!��,��<�$�T�<�<�V�<�<�<rU�3Callable[[WebSocketServerProtocol], Awaitable[Any]]c�b��	tj����d��nS#t$rF	tj����dd��d�fd�}|cYS#t$rYnwxYwYnwxYwt	t
tgttf���S)NrNrpr2rJrc���K�ttttgtt
f���||j���d{V��Sr�)rrr2r�rrr�)rpr>s �rS�_ws_handlerz)remove_path_argument.<locals>._ws_handler�sh������T��5�s�;�Y�s�^�K�L�����Y�^�-�-�-�-�-�-�-�-�-rU)rpr2rJr)	�inspect�	signature�bind�	TypeErrorrrr2rr)r>r^s` rSr]r]�s�������*�%�%�*�*�4�0�0�0�0������	���j�)�)�.�.�t�R�8�8�8�
-�
-�
-�
-�
-�
-�������	�	�	��D�	�����D�����(��)�*�I�c�N�:�;����s2�'+�
A;�(A(�A;�(
A5�2A;�4A5�5A;�:A;r�)r>r?r�rFrIrrJr,)r>r?rJr[)L�
__future__rrx�email.utilsr�rKr�r_rVr�rZ�typesr�typingrrrrr	r
rrr
rrrr�
connectionr�datastructuresrrr�
exceptionsrrrrrrrr8rr�extensions.permessage_deflater r~r!r"r#r$r%r&r'r(r)�
compatibilityr+rwr,r-r.r�r/�__all__r��HeadersLikeOrCallabler��bytes�HTTPResponser2r3r,r0r1r]rPrUrS�<module>rps���"�"�"�"�"�"�������������������������
�
�
�
����������������������������������������� ������F�F�F�F�F�F�F�F�F�F�������������������;�:�:�:�:�:�:�:�L�L�L�L�L�L�������������������E�E�E�E�E�E�E�E�E�E�E�E�+�+�+�+�+�+�4�4�4�4�4�4�4�4�������-�-�-�-�-�-�P�
O�
O���k�8�S�'�N�K�4O�+P�P�Q���T�_�k�5�8�9��M	�M	�M	�M	�M	�5�M	�M	�M	�`i!�i!�i!�i!�i!�i!�i!�i!�Xh�h�h�h�h�h�h�h�V	���=�=�=�=�=�2�����rU

Youez - 2016 - github.com/yon3zu
LinuXploit