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/__pycache__/client.cpython-310.pyc
o

�h�4�@s�ddlmZddlZddlZddlZddlmZmZddlm	Z	ddl
mZmZddl
mZmZmZmZmZmZmZddlmZmZdd	lmZmZmZmZmZmZmZm Z dd
l!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(m)Z)m*Z*m+Z+dd
lm,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3ddl4m5Z5m6Z6dgZ7Gdd�de*�Z8Gdd�de8�Z9e:ej;�<dd��Z=e:ej;�<dd��Z>e:ej;�<dd��Z?e:ej;�<dd��Z@e=e>e?e@fd(d#d$�ZAe%eB�d%d%d%d&�d'�dS))�)�annotationsN)�	Generator�Sequence)�Any�)�Headers�MultipleValuesError)�InvalidHandshake�
InvalidHeader�InvalidHeaderValue�InvalidMessage�
InvalidStatus�InvalidUpgrade�NegotiationError)�ClientExtensionFactory�	Extension)�build_authorization_basic�build_extension�
build_host�build_subprotocol�parse_connection�parse_extension�parse_subprotocol�
parse_upgrade)�Request�Response)�lazy_import)�CLIENT�
CONNECTING�OPEN�Protocol�State)�ConnectionOption�ExtensionHeader�
LoggerLike�Origin�Subprotocol�UpgradeProtocol)�WebSocketURI)�
accept_key�generate_key�ClientProtocolcsreZdZdZdddeddd�d,�fdd�Zd-dd�Zd.dd�Zd/d!d"�Zd0d$d%�Z	d1d'd(�Z
d2�fd*d+�Z�ZS)3r+a�
    Sans-I/O implementation of a WebSocket client connection.

    Args:
        uri: URI of the WebSocket server, parsed
            with :func:`~websockets.uri.parse_uri`.
        origin: Value of the ``Origin`` header. This is useful when connecting
            to a server that validates the ``Origin`` header to defend 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.
        state: Initial state of the WebSocket connection.
        max_size: Maximum size of incoming messages in bytes;
            :obj:`None` disables the limit.
        logger: Logger for this connection;
            defaults to ``logging.getLogger("websockets.client")``;
            see the :doc:`logging guide <../../topics/logging>` for details.

    Ni)�origin�
extensions�subprotocols�state�max_size�logger�urir(r,�
Origin | Noner-�'Sequence[ClientExtensionFactory] | Noner.�Sequence[Subprotocol] | Noner/r!r0�
int | Noner1�LoggerLike | None�return�Nonecs8t�jt|||d�||_||_||_||_t�|_dS)N)�sider/r0r1)	�super�__init__rr2r,�available_extensions�available_subprotocolsr*�key)�selfr2r,r-r.r/r0r1��	__class__��D/usr/local/CyberCP/lib/python3.10/site-packages/websockets/client.pyr<Gs�zClientProtocol.__init__rcCs�t�}t|jj|jj|jj�|d<|jjrt|jj�|d<|jdur'|j|d<d|d<d|d<|j	|d<d	|d
<|j
durItdd�|j
D��|d
<|jdurUt
|j�|d<t|jj|�S)a1
        Create a handshake request to open a connection.

        You must send the handshake request with :meth:`send_request`.

        You can modify it before sending it, for example to add HTTP headers.

        Returns:
            WebSocket handshake request event to send to the server.

        �Host�
AuthorizationNr%�	websocket�Upgrade�
ConnectionzSec-WebSocket-Key�13zSec-WebSocket-VersioncSsg|]	}|j|��f�qSrC)�name�get_request_params)�.0�extension_factoryrCrCrD�
<listcomp>vs��z*ClientProtocol.connect.<locals>.<listcomp>�Sec-WebSocket-Extensions�Sec-WebSocket-Protocol)rrr2�host�port�secure�	user_inforr,r?r=rr>rr�
resource_name)r@�headersrCrCrD�connect^s*



��
�zClientProtocol.connect�responsercCs |jdkr	t|��|j}tdd�|�d�D�g�}tdd�|D��s/td|r,d�|���d��td	d�|�d
�D�g�}t|�dkrJ|d�	�d
ksWtd
|rTd�|���d��z|d}Wnt
yitd�d�tyutdd�d�w|t
|j�kr�td|��|�|�|_|�|�|_dS)z�
        Check a handshake response.

        Args:
            request: WebSocket handshake response received from the server.

        Raises:
            InvalidHandshake: If the handshake response is invalid.

        �ecS�g|]}t|��qSrC)r�rM�valuerCrCrDrO��z3ClientProtocol.process_response.<locals>.<listcomp>rIcss�|]	}|��dkVqdS)�upgradeN)�lowerr\rCrCrD�	<genexpr>�s�z2ClientProtocol.process_response.<locals>.<genexpr>�, NcSr[rC)rr\rCrCrDrO�r^rHrrrGzSec-WebSocket-Acceptzmultiple values)�status_coder
rW�sum�get_all�anyr�join�lenr`�KeyErrorr
rr)r?r�process_extensionsr-�process_subprotocol�subprotocol)r@rYrW�
connectionr_�
s_w_acceptrCrCrD�process_response�s8
����
�
zClientProtocol.process_responserWr�list[Extension]c	
Cs�g}|�d�}|rQ|jdurtd��tdd�|D�g�}|D]2\}}|jD] }|j|kr-q%z|�||�}Wn	ty>Yq%w|�|�n
td|�d|����q|S)aj
        Handle the Sec-WebSocket-Extensions HTTP response header.

        Check that each extension is supported, as well as its parameters.

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

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

        If several variants of the same extension are accepted by the server,
        it may be configured 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.

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

        Args:
            headers: WebSocket handshake response headers.

        Returns:
            List of accepted extensions.

        Raises:
            InvalidHandshake: To abort the handshake.

        rPNzno extensions supportedcSr[rC)r�rM�header_valuerCrCrDrO�r^z5ClientProtocol.process_extensions.<locals>.<listcomp>zUnsupported extension: name = z, params = )rer=rrdrK�process_response_params�append)	r@rW�accepted_extensionsr-�parsed_extensionsrK�response_paramsrN�	extensionrCrCrDrj�s<

�

��
����
z!ClientProtocol.process_extensions�Subprotocol | NonecCs~d}|�d�}|r=|jdurtd��tdd�|D�g�}t|�dkr-tddd�|�����|d	}||jvr=td
|����|S)a#
        Handle the Sec-WebSocket-Protocol HTTP response header.

        If provided, check that it contains exactly one supported subprotocol.

        Args:
            headers: WebSocket handshake response headers.

        Returns:
           Subprotocol, if one was selected.

        NrQzno subprotocols supportedcSr[rC)rrqrCrCrDrO
r^z6ClientProtocol.process_subprotocol.<locals>.<listcomp>rzmultiple values: rbrzunsupported subprotocol: )rer>rrdrhr
rg)r@rWrlr.�parsed_subprotocolsrCrCrDrk�s"

��
z"ClientProtocol.process_subprotocol�requestcCsN|jr|j�d|j�|j��D]\}}|j�d||�q|j�|���dS)z�
        Send a handshake request to the server.

        Args:
            request: WebSocket handshake request event.

        z> GET %s HTTP/1.1z> %s: %sN)�debugr1�pathrW�	raw_items�writesrt�	serialize)r@r{r?r]rCrCrD�send_requests
zClientProtocol.send_request�Generator[None]c
#s��|jtur�zt�|jj|jj|jj�EdH}Wn,tyD}z t	d�|_
||j
_|��|�
�|_t|j�dVWYd}~nd}~ww|jrv|j|j}}|j�d||�|j��D]\}}|j�d||�q\|jrv|j�dt|j��z|�|�Wn/ty�}z#||_|j�|�||_
|��|�
�|_t|j�dVWYd}~nd}~ww|jtus�J�t|_|j�|�t���EdHdS)Nz%did not receive a valid HTTP responsez< HTTP/1.1 %d %sz< %s: %sz< [body] (%d bytes))r/rr�parse�reader�	read_line�
read_exact�read_to_eof�	Exceptionr�
handshake_exc�	__cause__�send_eof�discard�parser�nextr|rc�
reason_phraser1rWr~�bodyrhror	�
_exception�eventsrtrr;)r@rY�exc�code�phraser?r]rArCrDr�*sT�
��

��


��	zClientProtocol.parse)r2r(r,r3r-r4r.r5r/r!r0r6r1r7r8r9)r8r)rYrr8r9)rWrr8rp)rWrr8ry)r{rr8r9)r8r�)
�__name__�
__module__�__qualname__�__doc__rr<rXrorjrkr�r��
__classcell__rCrCrArDr+0s�

#
-
I
$cseZdZd�fdd�Z�ZS)	�ClientConnection�argsr�kwargsr8r9cs"t�dt�t�j|i|��dS)Nz.ClientConnection was renamed to ClientProtocol)�warnings�warn�DeprecationWarningr;r<)r@r�r�rArCrDr<Ws
�zClientConnection.__init__)r�rr�rr8r9)r�r�r�r<r�rCrCrArDr�Vsr�� WEBSOCKETS_BACKOFF_INITIAL_DELAY�5�WEBSOCKETS_BACKOFF_MIN_DELAYz3.1�WEBSOCKETS_BACKOFF_MAX_DELAYz90.0�WEBSOCKETS_BACKOFF_FACTORz1.618�
initial_delay�float�	min_delay�	max_delay�factorr8�Generator[float]ccs<�t��|V|}||kr|V||9}||ks	|Vq)z�
    Generate a series of backoff delays between reconnection attempts.

    Yields:
        How many seconds to wait before retrying to connect.

    )�random)r�r�r�r��delayrCrCrD�backoffes���r�z.legacy.client)�WebSocketClientProtocolrX�unix_connect)�deprecated_aliases)
r�r�r�r�r�r�r�r�r8r�)C�
__future__r�osr�r��collections.abcrr�typingr�datastructuresrr�
exceptionsr	r
rrr
rrr-rrrWrrrrrrrr�http11rr�importsr�protocolrrrr r!r"r#r$r%r&r'r2r(�utilsr)r*�__all__r+r�r��environ�get�BACKOFF_INITIAL_DELAY�BACKOFF_MIN_DELAY�BACKOFF_MAX_DELAY�BACKOFF_FACTORr��globalsrCrCrCrD�<module>sJ$	(
 (	��
�