
    vKg.                       S SK Jr  S SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJrJr  SSKJrJr  SSK	JrJrJr  SSKJr  SSK J!r!  SSK"J#r#  / SQr$ " S S\!5      r%SSSSSSS\SSSSSSSS.                                   SS jjr&  S       SS jjr'g)    )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                     ^  \ rS rSrSrSSS.         SU 4S jjjrS\S4       SS jjrSU 4S	 jjrSU 4S
 jjr	Sr
U =r$ )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               ^   > U   [         R                  " 5       U l        [        TU ]  UUUUS9  g )Nr   )	threadingr   response_rcvdsuper__init__)selfsocketprotocolr   r    	__class__s        V/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/websockets/sync/client.pyr%   ClientConnection.__init__4   s5     	&__.'	 	 	
    Nc                   U R                  [        S9   U R                  R                  5       U l        Ub%  U R                  R
                  R                  U5        Ub  X R                  R
                  S'   U R                  R                  U R                  5        SSS5        U R                  R                  U5      (       d  [        S5      eU R                  R                  b  U R                  R                  eg! , (       d  f       Ng= f)z!
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*   	handshakeClientConnection.handshakeE   s     j9==002DL!-$$++,>? ,5F$$\2MM&&t||4 : !!&&w//;<< ==&&2----- 3 :9s   BC==
Dc                   > U R                   c8  [        U[        5      (       d   eXl         U R                  R	                  5         g[
        TU ]  U5        g)z
Process one incoming event.

N)response
isinstancer   r#   setr$   process_event)r&   eventr)   s     r*   r@   ClientConnection.process_eventa   sH     == eX....!M""$ G!%(r,   c                   >  [         TU ]  5         U R                  R                  5         g! U R                  R                  5         f = f)z9
Read incoming data from the socket and process events.

N)r$   recv_eventsr#   r?   )r&   r)   s    r*   rD   ClientConnection.recv_eventso   s:    
	%G! ""$D""$s	   , A)r0   r=   r#   )
r'   zsocket.socketr(   r   r   float | Noner    *int | None | tuple[int | None, int | None]returnNone)r7   HeadersLike | Noner8   
str | Noner9   rF   rH   rI   )rA   r   rH   rI   )rH   rI   )__name__
__module____qualname____firstlineno____doc__r%   r   r:   r@   rD   __static_attributes____classcell__)r)   s   @r*   r   r      s    < ')@B

 !

 $
 >
 

 
& 26(2 $	... &. 	.
 
.8)	% 	%r,   r   deflater   i   r   )socksslserver_hostnameorigin
extensionssubprotocolsr7   r8   compressionopen_timeoutr   max_sizer    loggercreate_connectionc          	        Uc2  SU;   a,  UR                  S5      n[        R                  " S[        5        [	        U 5      nUR
                  (       d  Ub  [        S5      eUR                  SS5      nUR                  SS5      nU(       a"  Uc  Uc  [        S5      eUb  Ub  [        S	5      eUb  [        U5        U	S
:X  a  [        U5      nOU	b  [        SU	 35      e[        U
5      nUc  [        n Uc  U(       ai  [        R                  " [        R                  [        R                  5      nUR                  UR                  5       5        Uc   eUR!                  U5        OMUR#                  SUR                  5       5        [        R$                  " UR&                  UR(                  440 UD6nUR                  S5        U(       d/  UR+                  [        R,                  [        R.                  S5        UR
                  (       af  Uc  [0        R2                  " 5       nUc  UR&                  nUR                  UR                  5       5        UR5                  XS9nUR                  S5        [7        UUUUUUS9nU" UUUUS9n UR=                  UUUR                  5       5        U$ ! [8         a    Ub  UR;                  5         e f = f! [8         a,    UR?                  5         UR@                  RC                  5         e f = f)a5  
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 incompatiblerS   zunsupported compression: r9   T)rV   )rW   rX   rY   r\   r]   r   )"popwarningswarnDeprecationWarningr   secure
ValueErrorr   r
   r   r   r'   AF_UNIXSOCK_STREAM
settimeoutr9   r   
setdefaultr^   hostport
setsockoptIPPROTO_TCPTCP_NODELAY
ssl_modulecreate_default_contextwrap_socketr   	Exceptioncloser:   close_socketrecv_events_threadjoin)urirT   rU   rV   rW   rX   rY   r7   r8   rZ   r[   r   r\   r    r]   r^   kwargswsurira   rb   deadliner(   
connections                          r*   r   r   {   s   z {}.jj',	

 cNE<<COHII FE*Dzz&$/D<DL455$"2GHHl+i5jA
		 4[MBCC
 %H ,4 <}}V^^V5G5GH 0 0 23'''T"!!)X-=-=-?@//UZZ0HSFSOOD! OOF..0B0BDI <<{ 779&"'**OOH,,./??4?IDOOD! "!%
 ''	

		
 !  JJL  !%%**,s   3FJ, 	!K ,K6Lc                x    Uc)  UR                  S5      c  UR                  S5      c  SnOSn[        SUSU S.UD6$ )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/``.

rU   r`   zws://localhost/zwss://localhost/T)rz   ra   rb    )getr   )rb   rz   r{   s      r*   r   r   A  sG    * {::e$M)B)J#C$C;sD;F;;r,   )$rz   strrT   zsocket.socket | NonerU   zssl_module.SSLContext | NonerV   rK   rW   zOrigin | NonerX   z'Sequence[ClientExtensionFactory] | NonerY   zSequence[Subprotocol] | Noner7   rJ   r8   rK   rZ   rK   r[   rF   r   rF   r\   z
int | Noner    rG   r]   zLoggerLike | Noner^   ztype[ClientConnection] | Noner{   r   rH   r   )NN)rb   rK   rz   rK   r{   r   rH   r   )(
__future__r   r'   rU   rr   r"   rd   collections.abcr   typingr   clientr   datastructuresr   extensions.baser	   extensions.permessage_deflater
   r1   r   http11r   r   r(   r   r   r   r   r   rz   r   r~   r   utilsr   __all__r   r   r   r   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,   