| 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 : |
�
�=Xcvg � � � d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl m
Z
d dlmZm
Z
mZmZmZmZmZmZmZmZ ddlmZmZ ddlmZmZmZmZmZmZm Z ddl!m"Z"m#Z# dd l$m%Z% dd
l&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ ddlm0Z0m1Z1m2Z2m3Z3 dd
l4m5Z5m6Z6 ddl7m8Z8m9Z9 ddl.m:Z: ddl;m<Z< g d�Z= G d� de<� � Z> G d� d� � Z?e?Z@ d d!d�ZAdS )"� )�annotationsN)�
TracebackType)
�Any�
AsyncIterator�Callable� Generator�List�Optional�Sequence�Tuple�Type�cast� )�Headers�HeadersLike)�InvalidHandshake�
InvalidHeader�InvalidMessage�InvalidStatusCode�NegotiationError�RedirectHandshake�
SecurityError)�ClientExtensionFactory� Extension)� enable_client_permessage_deflate)�build_authorization_basic�build_extension�
build_host�build_subprotocol�parse_extension�parse_subprotocol�validate_subprotocols)�
USER_AGENT)�ExtensionHeader�
LoggerLike�Origin�Subprotocol)�WebSocketURI� parse_uri� )�
build_request�check_response)�
read_response)�WebSocketCommonProtocol)�connect�unix_connect�WebSocketClientProtocolc � � � e Zd ZdZdZdZddddded�d'� fd�Zd(d�Zd)d�Z e
d*d �� � Ze
d+d#�� � Z d,d-d&�Z
� xZS ).r1 a�
WebSocket client connection.
:class:`WebSocketClientProtocol` provides :meth:`recv` and :meth:`send`
coroutines for receiving and sending messages.
It supports asynchronous iteration to receive incoming 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.
See :func:`connect` for the documentation of ``logger``, ``origin``,
``extensions``, ``subprotocols``, ``extra_headers``, and
``user_agent_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``.
T�clientN)�logger�origin�
extensions�subprotocols�
extra_headers�user_agent_headerr4 �Optional[LoggerLike]r5 �Optional[Origin]r6 �*Optional[Sequence[ClientExtensionFactory]]r7 �Optional[Sequence[Subprotocol]]r8 �Optional[HeadersLike]r9 �
Optional[str]�kwargsr �return�Nonec � �� |�t j d� � } t � � j dd|i|�� || _ || _ || _ || _ || _ d S )N�websockets.clientr4 � ) �logging� getLogger�super�__init__r5 �available_extensions�available_subprotocolsr8 r9 ) �selfr4 r5 r6 r7 r8 r9 r@ � __class__s ��:/usr/lib/python3/dist-packages/websockets/legacy/client.pyrI z WebSocketClientProtocol.__init__U sj �� � �>��&�':�;�;�F������1�1��1�&�1�1�1����$.��!�&2��#�*���!2����� �path�str�headersr c �Z � || _ || _ | j rQ| j � d|� � |� � � D ]!\ }}| j � d||� � �"d|� d�}|t |� � z
}| j � |� � � � � dS )zF
Write request line and headers to the HTTP request.
z> GET %s HTTP/1.1z> %s: %szGET z HTTP/1.1
N) rP �request_headers�debugr4 � raw_itemsrQ � transport�write�encode)rL rP rR �key�value�requests rN �write_http_requestz*WebSocketClientProtocol.write_http_requesti s� � �
�� �&����:� :��K���1�4�8�8�8�%�/�/�1�1�
:�
:�
��U���!�!�*�c�5�9�9�9�9� -��,�,�,���3�w�<�<�������W�^�^�-�-�.�.�.�.�.rO �Tuple[int, Headers]c � �z K � t | j � � � d{V ��\ }}}n1# t j $ r � t $ r}t d� � |�d}~ww xY w| j rR| j � d||� � |� � � D ]!\ }}| j � d||� � �"|| _ || j fS )a<
Read status line and headers from the HTTP response.
If the response 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 response.
Nz%did not receive a valid HTTP responsez< HTTP/1.1 %d %sz< %s: %s)
r- �reader�asyncio�CancelledError� Exceptionr rU r4 rV �response_headers)rL �status_code�reasonrR �excrZ r[ s rN �read_http_responsez*WebSocketClientProtocol.read_http_response} s� � � � � S�1>�t�{�1K�1K�+K�+K�+K�+K�+K�+K�(�K����� �%� � � ��� S� S� S� �!H�I�I�s�R����� S���� �:� :��K���0�+�v�F�F�F�%�/�/�1�1�
:�
:�
��U���!�!�*�c�5�9�9�9�9� '����D�1�1�1s �# �A�A�ArJ �List[Extension]c �f � g }| � d� � }|r�|�t d� � �t d� |D � � g � � }|D ]i\ }}|D ]L}|j |k r� |� ||� � }n# t
$ r Y �2w xY w|� |� � nt d|� d|� �� � ��j|S )a/
Handle the Sec-WebSocket-Extensions HTTP response header.
Check that each extension is supported, as well as its parameters.
Return the list of accepted extensions.
Raise :exc:`~websockets.exceptions.InvalidHandshake` to abort the
connection.
: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.
�Sec-WebSocket-ExtensionsNzno extensions supportedc �, � g | ]}t |� � ��S rE )r ��.0�header_values rN �
<listcomp>z>WebSocketClientProtocol.process_extensions.<locals>.<listcomp>� s � �Q�Q�Q�<���.�.�Q�Q�QrO zUnsupported extension: name = z, params = )�get_allr �sum�name�process_response_paramsr �append) rR rJ �accepted_extensions�
header_values�parsed_header_valuesrs �response_params�extension_factory� extensions rN �process_extensionsz*WebSocketClientProtocol.process_extensions� s< � �>