Ë
    ãU.jF0  ã                  ó†  — d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 ddlmZ ddlmZ ddlmZ dd	l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 ddlmZ ddl m!Z! ddl"m#Z# g d¢Z$ G d„ de!«      Z%dddddddeddddddddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z&	 	 d	 	 	 	 	 	 	 dd„Z'y)é    )ÚannotationsN)ÚSequence)ÚAnyé   )ÚClientProtocol)ÚHeadersLike)ÚClientExtensionFactory)Ú enable_client_permessage_deflate)Úvalidate_subprotocols)Ú
USER_AGENTÚResponse)Ú
CONNECTINGÚEvent)Ú
LoggerLikeÚOriginÚSubprotocol)Ú	parse_urié   )Ú
Connection)ÚDeadline)ÚconnectÚunix_connectÚClientConnectionc                  ót   ‡ — e Zd ZdZdddœ	 	 	 	 	 	 	 	 	 d
ˆ fd„Zdedf	 	 	 	 	 	 	 dd„Zdˆ fd„Zdˆ fd	„Zˆ xZ	S )r   a  
    :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 ``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.

    é
   é   ©Úclose_timeoutÚ	max_queuec               ób   •— |  t        j                  «       | _        t        ‰| �  ||||¬«       y )Nr   )Ú	threadingr   Úresponse_rcvdÚsuperÚ__init__)ÚselfÚsocketÚprotocolr   r   Ú	__class__s        €úXC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\websockets/sync/client.pyr$   zClientConnection.__init__4   s5   ø€ ñ 	Ü&Ÿ_™_Ó.ˆÔÜ‰ÑØØØ'Øð	 	õ 	
ó    Nc                ó
  — | j                  t        ¬«      5  | j                  j                  «       | _        |�%| j                  j
                  j                  |«       |�|| j                  j
                  d<   | j                  j                  | j                  «       ddd«       | j                  j                  |«      st        d«      ‚| j                  j                  �| j                  j                  ‚y# 1 sw Y   Œ\xY w)z1
        Perform the opening handshake.

        )Úexpected_stateNz
User-Agentztimed out during handshake)Úsend_contextr   r'   r   ÚrequestÚheadersÚupdateÚsend_requestr"   ÚwaitÚTimeoutErrorÚhandshake_exc)r%   Úadditional_headersÚuser_agent_headerÚtimeouts       r)   Ú	handshakezClientConnection.handshakeE   sÏ   € ð ×Ñ¬jÐÕ9ØŸ=™=×0Ñ0Ó2ˆDŒLØ!Ð-Ø—‘×$Ñ$×+Ñ+Ð,>Ô?Ø Ð,Ø5F�—‘×$Ñ$ \Ñ2Ø�M‰M×&Ñ& t§|¡|Ô4÷ :ð ×!Ñ!×&Ñ& wÔ/ÜÐ;Ó<Ð<ð �=‰=×&Ñ&Ð2Ø—-‘-×-Ñ-Ð-ð 3÷ :Ð9ús   —BC9Ã9Dc                ó¤   •— | j                   €4t        |t        «      sJ ‚|| _         | j                  j	                  «        yt
        ‰| �  |«       y)z.
        Process one incoming event.

        N)ÚresponseÚ
isinstancer   r"   Úsetr#   Úprocess_event)r%   Úeventr(   s     €r)   r=   zClientConnection.process_eventa   sG   ø€ ð �=‰=Ð Ü˜e¤XÔ.Ð.Ð.Ø!ˆDŒMØ×Ñ×"Ñ"Õ$ô ‰GÑ! %Õ(r*   c                ó–   •— 	 t         ‰| �  «        | j                  j                  «        y# | j                  j                  «        w xY w)zI
        Read incoming data from the socket and process events.

        N)r#   Úrecv_eventsr"   r<   )r%   r(   s    €r)   r@   zClientConnection.recv_eventso   s:   ø€ ð
	%Ü‰GÑÔ!ð ×Ñ×"Ñ"Õ$øˆD×Ñ×"Ñ"Õ$ús	   ƒ, ¬A)
r&   zsocket.socketr'   r   r   úfloat | Noner   ú*int | None | tuple[int | None, int | None]ÚreturnÚNone)r5   úHeadersLike | Noner6   ú
str | Noner7   rA   rC   rD   )r>   r   rC   rD   )rC   rD   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   r   r8   r=   r@   Ú__classcell__)r(   s   @r)   r   r      sŠ   ø„ ñð< ')Ø@Bñ
àð
ð !ð
ð
 $ð
ð >ð
ð 
õ
ð& 26Ø(2Ø $ð	.à.ð.ð &ð.ð ð	.ð
 
ó.õ8)÷	%ñ 	%r*   r   Údeflater   i   r   )ÚsockÚsslÚserver_hostnameÚoriginÚ
extensionsÚsubprotocolsr5   r6   ÚcompressionÚopen_timeoutr   Úmax_sizer   ÚloggerÚcreate_connectionc               óÂ  — |€/d|v r+|j                  d«      }t        j                  dt        «       t	        | «      }|j
                  s|�t        d«      ‚|j                  dd«      }|j                  dd«      }|r|€|€t        d«      ‚|�|�t        d	«      ‚|�t        |«       |	d
k(  rt        |«      }n|	�t        d|	› �«      ‚t        |
«      }|€t        }	 |€Æ|rgt        j                  t        j                  t        j                  «      }|j                  |j                  «       «       |€J ‚|j!                  |«       nL|j#                  d|j                  «       «       t        j$                  |j&                  |j(                  ffi |¤Ž}|j                  d«       |s/|j+                  t        j,                  t        j.                  d«       |j
                  rg|€t1        j2                  «       }|€|j&                  }|j                  |j                  «       «       |j5                  ||¬«      }|j                  d«       t7        ||||||¬«      } |||||¬«      }	 |j=                  |||j                  «       «       |S # t8        $ r |�|j;                  «        ‚ w xY w# t8        $ r, |j?                  «        |j@                  jC                  «        ‚ w xY w)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.
        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.
        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.
        open_timeout: Timeout for opening the connection in seconds.
            :obj:`None` disables the timeout.
        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_contextzssl_context was renamed to sslz-ssl argument is incompatible with a ws:// URIÚunixFÚpathzmissing path argumentz(path and sock arguments are incompatiblerL   zunsupported compression: r7   T)rO   )rP   rQ   rR   rU   rV   r   )"ÚpopÚwarningsÚwarnÚDeprecationWarningr   ÚsecureÚ
ValueErrorr   r
   r   r   r&   ÚAF_UNIXÚSOCK_STREAMÚ
settimeoutr7   r   Ú
setdefaultrW   ÚhostÚportÚ
setsockoptÚIPPROTO_TCPÚTCP_NODELAYÚ
ssl_moduleÚcreate_default_contextÚwrap_socketr   Ú	ExceptionÚcloser8   Úclose_socketÚrecv_events_threadÚjoin)ÚurirM   rN   rO   rP   rQ   rR   r5   r6   rS   rT   r   rU   r   rV   rW   ÚkwargsÚwsurirZ   r[   Údeadliner'   Ú
connections                          r)   r   r   {   sÈ  € ðz €{�}¨Ñ.Ø�j‰j˜Ó'ˆÜ�‰Ø,Üô	
ô
 �c‹N€EØ�<Š<˜C˜OÜÐHÓIÐIð —‘˜F EÓ*€DØ—z‘z &¨$Ó/€DáØˆ<˜D˜LÜÐ4Ó5Ð5ØÐ $Ð"2ÜÐGÓHÐHàÐÜ˜lÔ+à�iÒÜ5°jÓA‰
Ø	Ð	 ÜÐ4°[°MÐBÓCÐCô
 ˜Ó%€HàÐ Ü,Ðð4ð ˆ<ÙÜ—}‘}¤V§^¡^´V×5GÑ5GÓH�Ø—‘ × 0Ñ 0Ó 2Ô3ØÐ'Ð'Ð'Ø—‘˜TÕ"à×!Ñ! )¨X×-=Ñ-=Ó-?Ô@Ü×/Ñ/°·±¸U¿Z¹ZÐ0HÑSÈFÑS�Ø�O‰O˜DÔ!ñ Ø�O‰OœF×.Ñ.´×0BÑ0BÀDÔIð �<Š<Øˆ{Ü ×7Ñ7Ó9�ØÐ&Ø"'§*¡*�Ø�O‰O˜H×,Ñ,Ó.Ô/Ø—?‘? 4¸�?ÓIˆDØ�O‰O˜DÔ!ô "ØØØ!Ø%ØØô
ˆñ 'ØØØ'Øô	
ˆ
ð	Ø×ÑØØØ×ÑÓô	
ð Ðøô! ò ØÐØ�J‰JŒLØðûô ò Ø×ÑÔ!Ø×%Ñ%×*Ñ*Ô,Øðús   ÃF	J	 É&!J) Ê	J&Ê)5Kc                ór   — |€'|j                  d«      €|j                  d«      €d}nd}t        d|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/``.

    rN   rY   zws://localhost/zwss://localhost/T)rs   rZ   r[   © )Úgetr   )r[   rs   rt   s      r)   r   r   A  sG   € ð* €{à�:‰:�eÓÐ$¨¯©°MÓ)BÐ)JØ#‰Cà$ˆCÜÐ;�s ¨DÑ;°FÑ;Ð;r*   )$rs   ÚstrrM   zsocket.socket | NonerN   zssl_module.SSLContext | NonerO   rF   rP   zOrigin | NonerQ   z'Sequence[ClientExtensionFactory] | NonerR   zSequence[Subprotocol] | Noner5   rE   r6   rF   rS   rF   rT   rA   r   rA   rU   z
int | Noner   rB   rV   zLoggerLike | NonerW   ztype[ClientConnection] | Nonert   r   rC   r   )NN)r[   rF   rs   rF   rt   r   rC   r   )(Ú
__future__r   r&   rN   rk   r!   r]   Úcollections.abcr   Útypingr   Úclientr   Údatastructuresr   Úextensions.baser	   Úextensions.permessage_deflater
   r/   r   Úhttp11r   r   r'   r   r   r   r   r   rs   r   rw   r   Úutilsr   Ú__all__r   r   r   ry   r*   r)   Ú<module>r†      s  ðÝ "ã Û Û Û Ý $Ý å #Ý (Ý 4Ý LÝ +ß )ß (ß 4Ñ 4Ý Ý "Ý ò :€ô^%�zô ^%ðJ "&Ø(,Ø"&à Ø:>Ø15Ø-1Ø$.Ø'à!#Ø"$à Ø<>à $à7;ñ/CØ	ðCð ð	Cð
 
&ðCð  ðCð ðCð 8ðCð /ðCð +ðCð "ðCð ðCð ðCð   ð!Cð$ ð%Cð& :ð'Cð* ð+Cð. 5ð/Cð0 ð1Cð2 ó3CðN Øð<Ø
ð<à	ð<ð ð<ð ô	<r*   