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

�hxX�@sDddlmZddlZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
mZddlmZddlmZmZddlmZmZmZdd	lmZdd
lmZddlmZmZmZddl m!Z!m"Z"dd
l#m$Z$m%Z%ddl&m'Z'ddl	m(Z(m)Z)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddl3m4Z4gd�Z5Gdd�de2�Z6dddddddde!dddddddddddd�dedDdE�Z7		dfdgdGdH�Z8z%ddIl9m:Z:ddJl;m,Z<e:j=e:j=e:j>e:j>dK�Z?ddLddLdK�Z@dhdSdT�ZAWneBy�dhdUdT�ZAYnw	didjdWdX�ZCdkdZd[�ZDdddd\�dld]d^�ZEe
d_�ZFe
d`edaeFfdb�ZGGdcdd�dd�ZHdS)m�)�annotationsN)�Sequence)�Any�Callable�Literal�TypeVar�cast�)�ClientProtocol)�Headers�HeadersLike)�InvalidProxyMessage�InvalidProxyStatus�
ProxyError)�ClientExtensionFactory)� enable_client_permessage_deflate)�build_authorization_basic�
build_host�validate_subprotocols)�
USER_AGENT�Response)�
CONNECTING�Event)�StreamReader)�
LoggerLike�Origin�Subprotocol)�Proxy�WebSocketURI�	get_proxy�parse_proxy�	parse_uri�)�
Connection)�Deadline)�connect�unix_connect�ClientConnectioncs\eZdZdZddddd�d"�fdd�Zdedfd#dd�Zd$�fdd�Zd%�fd d!�Z�Z	S)&r'a1
    :mod:`threading` implementation of a WebSocket client connection.

    :class:`ClientConnection` provides :meth:`recv` and :meth:`send` methods for
    receiving and sending messages.

    It supports iteration to receive messages::

        for message in websocket:
            process(message)

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

    The ``ping_interval``, ``ping_timeout``, ``close_timeout``, and
    ``max_queue`` arguments have the same meaning as in :func:`connect`.

    Args:
        socket: Socket connected to a WebSocket server.
        protocol: Sans-I/O connection.

    ��
���
ping_interval�ping_timeout�
close_timeout�	max_queue�socket�
socket.socket�protocolr
r,�float | Noner-r.r/�*int | None | tuple[int | None, int | None]�return�Nonecs*|t��|_t�j||||||d�dS)Nr+)�	threadingr�
response_rcvd�super�__init__)�selfr0r2r,r-r.r/��	__class__��I/usr/local/CyberCP/lib/python3.10/site-packages/websockets/sync/client.pyr:6s


�zClientConnection.__init__N�additional_headers�HeadersLike | None�user_agent_header�
str | None�timeoutcCs�|jtd��,|j��|_|dur|jj�|�|dur$|jj�d|�|j�|j�Wd�n1s5wY|j	�
|�sDtd��|jjdurN|jj�dS)z1
        Perform the opening handshake.

        )�expected_stateN�
User-Agentz.timed out while waiting for handshake response)
�send_contextrr2r%�request�headers�update�
setdefault�send_requestr8�wait�TimeoutError�
handshake_exc)r;r@rBrDr>r>r?�	handshakeKs
��zClientConnection.handshake�eventrcs<|jdurt|t�sJ�||_|j��dSt��|�dS)z.
        Process one incoming event.

        N)�response�
isinstancerr8�setr9�
process_event)r;rQr<r>r?rUgs

zClientConnection.process_eventcs(z
t���W|j��dS|j��w)zI
        Read incoming data from the socket and process events.

        N)r9�recv_eventsr8rT)r;r<r>r?rVuszClientConnection.recv_events)r0r1r2r
r,r3r-r3r.r3r/r4r5r6)r@rArBrCrDr3r5r6)rQrr5r6)r5r6)
�__name__�
__module__�__qualname__�__doc__r:rrPrUrV�
__classcell__r>r>r<r?r's��r'�deflateTr)r(ir*)�sock�ssl�server_hostname�origin�
extensions�subprotocols�compressionr@rB�proxy�	proxy_ssl�proxy_server_hostname�open_timeoutr,r-r.�max_sizer/�logger�create_connection�uri�strr]�socket.socket | Noner^�ssl_module.SSLContext | Noner_rCr`�
Origin | Nonera�'Sequence[ClientExtensionFactory] | Nonerb�Sequence[Subprotocol] | Nonercr@rArBrd�str | Literal[True] | Nonererfrgr3r,r-r.rh�
int | Noner/r4ri�LoggerLike | Nonerj�type[ClientConnection] | None�kwargsrr5cKs.|durd|vr|�d�}t�dt�t|�}|js"|dur"td��|�dd�}|�dd�}|rH|dur<|dur<td��|durH|durHtd	��|durPt|�|d
krYt|�}n|durdtd|����|rhd}
|durnd}
|
durvt	|�}
t
|
�}|dur�t}z�|du�r|r�t�tj
tj�}|�|���|dus�J�|�|�n\|
dur�t|
�}|jdd
�dkr�t||||�dd�d�}n>|jdd�dkr�|jdkr�|dur�td��t|||f|	||d�|��}ntd��|�d|���tj|j|jffi|��}|�d�|�s|�tjtjd�|j�rK|du�rt��}|du�r%|j}|�|���|du�r9|j ||d�}n
t!|||d�}t"tj|�}|�d�t#||||||d�}|||||||d�}Wnt$�yr|du�rq|�%��wz|�&||	|���Wnt$�y�|�'�|j(�)��w|�*�|S)a�
    Connect to the WebSocket server at ``uri``.

    This function returns a :class:`ClientConnection` instance, which you can
    use to send and receive messages.

    :func:`connect` may be used as a context manager::

        from websockets.sync.client import connect

        with connect(...) as websocket:
            ...

    The connection is closed automatically when exiting the context.

    Args:
        uri: URI of the WebSocket server.
        sock: Preexisting TCP socket. ``sock`` overrides the host and port
            from ``uri``. You may call :func:`socket.create_connection` to
            create a suitable TCP socket.
        ssl: Configuration for enabling TLS on the connection.
        server_hostname: Host name for the TLS handshake. ``server_hostname``
            overrides the host name from ``uri``.
        origin: Value of the ``Origin`` header, for servers that require it.
        extensions: List of supported extensions, in order in which they
            should be negotiated and run.
        subprotocols: List of supported subprotocols, in order of decreasing
            preference.
        compression: The "permessage-deflate" extension is enabled by default.
            Set ``compression`` to :obj:`None` to disable it. See the
            :doc:`compression guide <../../topics/compression>` for details.
        additional_headers (HeadersLike | None): Arbitrary HTTP headers to add
            to the handshake request.
        user_agent_header: Value of  the ``User-Agent`` request header.
            It defaults to ``"Python/x.y.z websockets/X.Y"``.
            Setting it to :obj:`None` removes the header.
        proxy: If a proxy is configured, it is used by default. Set ``proxy``
            to :obj:`None` to disable the proxy or to the address of a proxy
            to override the system configuration. See the :doc:`proxy docs
            <../../topics/proxies>` for details.
        proxy_ssl: Configuration for enabling TLS on the proxy connection.
        proxy_server_hostname: Host name for the TLS handshake with the proxy.
            ``proxy_server_hostname`` overrides the host name from ``proxy``.
        open_timeout: Timeout for opening the connection in seconds.
            :obj:`None` disables the timeout.
        ping_interval: Interval between keepalive pings in seconds.
            :obj:`None` disables keepalive.
        ping_timeout: Timeout for keepalive pings in seconds.
            :obj:`None` disables timeouts.
        close_timeout: Timeout for closing the connection in seconds.
            :obj:`None` disables the timeout.
        max_size: Maximum size of incoming messages in bytes.
            :obj:`None` disables the limit.
        max_queue: High-water mark of the buffer where frames are received.
            It defaults to 16 frames. The low-water mark defaults to ``max_queue
            // 4``. You may pass a ``(high, low)`` tuple to set the high-water
            and low-water marks. If you want to disable flow control entirely,
            you may set it to ``None``, although that's a bad idea.
        logger: Logger for this client.
            It defaults to ``logging.getLogger("websockets.client")``.
            See the :doc:`logging guide <../../topics/logging>` for details.
        create_connection: Factory for the :class:`ClientConnection` managing
            the connection. Set it to a wrapper or a subclass to customize
            connection handling.

    Any other keyword arguments are passed to :func:`~socket.create_connection`.

    Raises:
        InvalidURI: If ``uri`` isn't a valid WebSocket URI.
        OSError: If the TCP connection fails.
        InvalidHandshake: If the opening handshake fails.
        TimeoutError: If the opening handshake times out.

    N�ssl_contextzssl_context was renamed to sslz-ssl argument is incompatible with a ws:// URI�unixF�pathzmissing path argumentz(path and sock arguments are incompatibler\zunsupported compression: T��socks�source_address)�
local_addr��http�httpsz8proxy_ssl argument is incompatible with an http:// proxy�rBr^r_zunsupported proxyrD�r_)r`rarbrhrir+)+�pop�warnings�warn�DeprecationWarningr!�secure�
ValueErrorrrrr$r'r0�AF_UNIX�SOCK_STREAM�
settimeoutrDr%r �scheme�connect_socks_proxy�connect_http_proxy�AssertionErrorrKrj�host�port�
setsockopt�IPPROTO_TCP�TCP_NODELAY�
ssl_module�create_default_context�wrap_socket�SSLSSLSocketrr
�	Exception�closerP�close_socket�recv_events_thread�join�start_keepalive)rkr]r^r_r`rarbrcr@rBrdrerfrgr,r-r.rhr/rirjrv�ws_urirxry�deadline�proxy_parsed�sock_2r2�
connectionr>r>r?r%�s�n
�


�����

��




�
�
��
�r%rycKsD|dur|�d�dur|�d�durd}nd}td|d|d�|��S)	a�
    Connect to a WebSocket server listening on a Unix socket.

    This function accepts the same keyword arguments as :func:`connect`.

    It's only available on Unix.

    It's mainly useful for debugging servers listening on Unix sockets.

    Args:
        path: File system path to the Unix socket.
        uri: URI of the WebSocket server. ``uri`` defaults to
            ``ws://localhost/`` or, when a ``ssl`` is provided, to
            ``wss://localhost/``.

    Nr^rwzws://localhost/zwss://localhost/T)rkrxryr>)�getr%)ryrkrvr>r>r?r&�s
r&)�	ProxyType)r)�socks5h�socks5�socks4a�socks4Frr�rr�r$r1c
Ks�tt|j|j|j|j|jt|j�}|�d|�	��z
|j
|j|jfi|��WSttt
j	fy4�tyD}ztd�|�d}~ww)z0Connect via a SOCKS proxy and return the socket.rDz failed to connect to SOCKS proxyN)�
SocksProxy�SOCKS_PROXY_TYPESr�r�r��username�password�SOCKS_PROXY_RDNSrKrDr%�OSErrorrNr0r�r)rdr�r�rv�socks_proxy�excr>r>r?r��s"�
��r�cKstd��)Nz-python-socks is required to use a SOCKS proxy)�ImportError)rdr�r�rvr>r>r?r��s�bytescCs�t|j|j|jdd�}t�}t|j|j|j�|d<|dur!||d<|jdur6|jdus-J�t|j|j�|d<d|�d���|�	�S)NT)�always_include_port�HostrFzProxy-AuthorizationzCONNECT z HTTP/1.1
)
rr�r�r�rr�r�r�encode�	serialize)rdr�rBr�rIr>r>r?�prepare_connect_request�s
�r�rc
Cst�}tj|j|j|jdd�}zsz	|�|���|�d�}|r&|�	|�n|�
�t|�qtyg}z-t
|jt�s>J�|j}d|jkrLdkr_nt|��|WYd}~W|�d�St|��d}~wtjyrtd��ty�}ztd�|�d}~ww|�d�w)	NF)�include_bodyTi��i,z(timed out while connecting to HTTP proxyz0did not receive a valid HTTP response from proxy)rr�parse�	read_line�
read_exact�read_to_eofr�rD�recv�	feed_data�feed_eof�next�
StopIterationrS�value�status_coderr0rNr�r
)r]r��reader�parser�datar�rRr>r>r?�read_connect_response�sH�
��
������r�r�cKs�|�d|���tj|j|jffi|��}|jdkr<|dur"t��}|dur)|j}|�	|���|j
||d�}|�	d�|�t|||��zt
||�W|StyY|���w)NrDr�r�)rKrDr0rjr�r�r�r�r�r�r��sendallr�r�r�r�)rdr�r�rBr^r_rvr]r>r>r?r�s$

��r��T�F.)�boundc@sTeZdZdZdZ	d#d$dd
�Zd%dd�Zd&dd�Zd'dd�Zd(dd�Z	d)d!d"�Z
dS)*r�zr
    Socket-like object providing TLS-in-TLS.

    Only methods that are used by websockets are implemented.

    iNr]r1rw�ssl_module.SSLContextr_rCr5r6cCsBt��|_t��|_||_|j|j|j|d�|_|�|jj�dS)Nr�)	r��	MemoryBIO�incoming�outgoing�
ssl_socket�wrap_bio�
ssl_object�run_io�do_handshake)r;r]rwr_r>r>r?r:Es

�zSSLSSLSocket.__init__�func�Callable[..., T]�argsrr�cGs�	d}d}z||�}Wntjyd}Yntjy"d}Ynw|j��}|r0|j�|�|rH|j�|j�}|rB|j	�
|�n|j	��q|rKq|S)NTF)r��SSLWantReadError�SSLWantWriteErrorr��readr�r�r��recv_bufsizer��write�	write_eof)r;r�r��	want_read�
want_write�resultr�r>r>r?r�Us,�

zSSLSSLSocket.run_io�buflen�intr�cCs*z	|�|jj|�WStjyYdSw)N�)r�r�r�r��SSLEOFError)r;r�r>r>r?r�ss
�zSSLSSLSocket.recvr�cCs|�|jj|�S�N)r�r�r�)r;r�r>r>r?�sendyszSSLSSLSocket.sendc	Cs�d}t|��=}|�d��}t|�}||kr$||�||d��7}||ksWd�n1s.wYWd�dSWd�dS1sFwYdS)Nr�B)�
memoryviewr�lenr�)r;r��count�view�	byte_view�amountr>r>r?r�|s��P�zSSLSSLSocket.sendall�namerlcCst|j|�Sr�)�getattrr�)r;r�r>r>r?�__getattr__�szSSLSSLSocket.__getattr__r�)r]r1rwr�r_rCr5r6)r�r�r�rr5r�)r�r�r5r�)r�r�r5r�)r�r�r5r6)r�rlr5r)rWrXrYrZr�r:r�r�r�r�r�r>r>r>r?r�;s�



r�).rkrlr]rmr^rnr_rCr`rorarprbrqrcrCr@rArBrCrdrrrernrfrCrgr3r,r3r-r3r.r3rhrsr/r4rirtrjrurvrr5r')NN)ryrCrkrCrvrr5r')
rdrr�rr�r$rvrr5r1r�)rdrr�rrBrCr5r�)r]r1r�r$r5r)rdrr�rr�r$rBrCr^rnr_rCrvrr5r1)I�
__future__rr0r^r�r7r��collections.abcr�typingrrrrr�clientr
�datastructuresrr�
exceptionsr
rr�extensions.baser�extensions.permessage_deflaterrIrrr�http11rrr2rr�streamsrrrrrkrrrr r!r�r#�utilsr$�__all__r'r%r&�python_socksr��python_socks.syncr��SOCKS5�SOCKS4r�r�r�r�r�r�r�r�r�r�r>r>r>r?�<module>s�i�
�����
'�&