
    Ji\V                    P   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
JrJrJrJr  SSKJr  SSK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SKJrJr  SSK J!r!J"r"  SSK#J$r$J%r%J&r&J'r'  SSK(J)r)  SSK	J*r*J+r+J,r,J-r-  SSK.J/r/J0r0  SSK1J2r2  SSK3J4r4  / SQr5 " S S\25      r6SSSSSSSS\SSSSSSSSSSSS.                                             S0S jjr7  S1       S2S  jjr8 S S!K9J:r:  S S"K;J$r<  \:Rz                  \:Rz                  \:R|                  \:R|                  S#.r?SS$SS$S#.r@          S3S% jrAS4S' jrCSSSS(.               S5S) jjrD\" S*5      rE\" S+\S,\E4   S-9rF " S. S/5      rGg! \B a              S3S& jrA NUf = f)6    )annotationsN)Sequence)AnyCallableLiteralTypeVarcast   )ClientProtocol)HeadersLike)InvalidProxyMessageInvalidProxyStatus
ProxyError)ClientExtensionFactory) enable_client_permessage_deflate)validate_subprotocols)
USER_AGENTResponse)
CONNECTINGEvent)Proxy	get_proxyparse_proxyprepare_connect_request)StreamReader)	BytesLike
LoggerLikeOriginSubprotocol)WebSocketURI	parse_uri   )
Connection)Deadline)connectunix_connectClientConnectionc                     ^  \ rS rSrSrSS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 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_queuec          	     b   > U   [         R                  " 5       U l        [        TU ]  UUUUUUS9  g )Nr-   )	threadingr   response_rcvdsuper__init__)selfsocketprotocolr.   r/   r0   r1   	__class__s          X/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/websockets/sync/client.pyr6   ClientConnection.__init__7   s;     	&__.'%' 	 	
    Nc                8   U R                  [        S9   U R                  R                  5       U l        Ub%  U R                  R
                  R                  U5        Ub&  U R                  R
                  R                  SU5        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 while waiting for handshake response)send_contextr   r9   r%   requestheadersupdate
setdefaultsend_requestr4   waitTimeoutErrorhandshake_exc)r7   additional_headersuser_agent_headertimeouts       r;   	handshakeClientConnection.handshakeL   s     j9==002DL!-$$++,>? ,$$//>OPMM&&t||4 : !!&&w//OPP ==&&2----- 3 :9s   BD
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   r4   setr5   process_event)r7   eventr:   s     r;   rR   ClientConnection.process_eventh   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)r5   recv_eventsr4   rQ   )r7   r:   s    r;   rV   ClientConnection.recv_eventsv   s:    
	%G! ""$D""$s	   , A)rA   rO   r4   )r8   socket.socketr9   r   r.   float | Noner/   rY   r0   rY   r1   *int | None | tuple[int | None, int | None]returnNone)rI   HeadersLike | NonerJ   
str | NonerK   rY   r[   r\   )rS   r   r[   r\   )r[   r\   )__name__
__module____qualname____firstlineno____doc__r6   r   rL   rR   rV   __static_attributes____classcell__)r:   s   @r;   r'   r'      s    < ')%'&(@B

 !

 $
 #
 $
 >
 

 
. 26(2 $	... &. 	.
 
.8)	% 	%r=   r'   deflateTr+   r*   i   r,   )socksslserver_hostnameorigin
extensionssubprotocolscompressionrI   rJ   proxy	proxy_sslproxy_server_hostnameopen_timeoutr.   r/   r0   max_sizer1   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(       a  Sn
Ub  Sn
U
SL a  [        U5      n
[        U5      nUc  [        n UGc[  U(       ai  [        R                  " [        R                  [        R                  5      nUR                  UR!                  5       5        Uc   eUR#                  U5        OU
b  [%        U
5      nUR&                  SS S:X  a  [)        UUUUR                  SS5      S9nOUR&                  SS S:X  a1  UR&                  S:w  a  Ub  [        S5      e[+        UUU4U	UUS.UD6nOX[-        S5      eUR/                  SUR!                  5       5        [        R0                  " UR2                  UR4                  440 UD6nUR                  S5        U(       d/  UR7                  [        R8                  [        R:                  S5        UR
                  (       a  Uc  [<        R>                  " 5       nUc  UR2                  nUR                  UR!                  5       5        Uc  URA                  XS9nO$[C        XUS9n[E        [        R                  U5      nUR                  S5        [G        UUUUUUS9nU" UUUUUUS9n URM                  UU	UR!                  5       5        URU                  5         U$ ! [H         a    Ub  URK                  5         e f = f! [H         a,    URO                  5         URP                  RS                  5         e f = f)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. You may pass a ``(max_message_size,
        max_fragment_size)`` tuple to set different limits for messages and
        fragments when you expect long messages sent in short fragments.
    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 incompatiblerf   zunsupported compression: T   sockssource_address)
local_addr   httphttpsz8proxy_ssl argument is incompatible with an http:// proxyrJ   rh   ri   zunsupported proxyrK   ri   )rj   rk   rl   rr   rs   r-   )+popwarningswarnDeprecationWarningr!   secure
ValueErrorr   r   r   r$   r'   r8   AF_UNIXSOCK_STREAM
settimeoutrK   r%   r   schemeconnect_socks_proxyconnect_http_proxyAssertionErrorrD   rt   hostport
setsockoptIPPROTO_TCPTCP_NODELAY
ssl_modulecreate_default_contextwrap_socketSSLSSLSocketr	   r   	ExceptioncloserL   close_socketrecv_events_threadjoinstart_keepalive)urirg   rh   ri   rj   rk   rl   rm   rI   rJ   rn   ro   rp   rq   r.   r/   r0   rr   r1   rs   rt   kwargsws_urirw   rx   deadlineproxy_parsedsock_2r9   
connections                                 r;   r%   r%      s   ` {}.jj',	

 s^F==S_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 ,\ <}}V^^V5G5GH 0 0 23'''T""*51&&r*g5.$  $*::.>#ED "((!,6#**g5):O(V  .$  +<%(= !D ))<==!!)X-=-=-?@//[[&++. OOD! OOF..0B0BDI =={ 779&"(++OOH,,./ tM%dQFMM62OOD! "!%
 ''%'

		
  #  JJL  !%%**,s   IN !N4 N146O*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/``.

rh   rv   zws://localhost/zwss://localhost/T)r   rw   rx    )getr%   )rx   r   r   s      r;   r&   r&     sG    * {::e$M)B)J#C$C;sD;F;;r=   )	ProxyType)r   )socks5hsocks5socks4asocks4Fc           	        [        [        U R                     U R                  U R                  U R
                  U R                  [        U R                     5      nUR                  SUR                  5       5         UR                  " UR                  UR                  40 UD6$ ! [        [        [        R                  4 a    e [         a  n[        S5      UeSnAff = f)z0Connect via a SOCKS proxy and return the socket.rK   z failed to connect to SOCKS proxyN)
SocksProxySOCKS_PROXY_TYPESr   r   r   usernamepasswordSOCKS_PROXY_RDNSrD   rK   r%   OSErrorrG   r8   r   r   )rn   r   r   r   socks_proxyexcs         r;   r   r     s     !ell+JJJJNNNNU\\*
 	)X%5%5%78	J&&v{{FKKJ6JJv~~6 	 	J?@cI	Js   <'B$ $)CCCc                    [        S5      e)Nz6connecting through a SOCKS proxy requires python-socks)ImportError)rn   r   r   r   s       r;   r   r     s     RSSr=   c                   [        5       n[        R                  " UR                  UR                  UR
                  SS9n  U R                  UR                  5       5        U R                  S5      nU(       a  UR                  U5        OUR                  5         [        U5        Mf  ! [         ao  n[        UR                  [        5      (       d   eUR                  nSUR                  s=::  a  S:  a  O  OUs S nAU R                  S 5        $ [!        U5      eS nAf["        R                   a    [%        S5      e[&         a  n[)        S5      UeS nAff = f! U R                  S 5        f = f)NT)rn   i      i,  z(timed out while connecting to HTTP proxyz0did not receive a valid HTTP response from proxy)r   r   parse	read_line
read_exactread_to_eofr   rK   recv	feed_datafeed_eofnextStopIterationrP   valuestatus_coder   r8   rG   r   r   )rg   r   readerparserdatar   rO   s          r;   read_connect_responser     s/   ^F^^	FOOH,,./99T?D  &!L   /#))X....99(&&,,O 	 %X..>> GEFF !>
	
 	sD   A'B( (
E2AD:E;E D+EEEE E.r   c                  UR                  SUR                  5       5        [        R                  " U R                  U R
                  440 UD6nU R                  S:X  af  Uc  [        R                  " 5       nUc  U R                  nUR                  UR                  5       5        UR                  XuS9nUR                  S 5        UR                  [        XU5      5         [        Xr5        U$ ! [         a    UR                  5         e f = f)NrK   r   r   )rD   rK   r8   rt   r   r   r   r   r   r   r   sendallr   r   r   r   )rn   r   r   rJ   rh   ri   r   rg   s           r;   r   r     s     i!1!1!34##UZZ$<GGD ||w;335C"#jjO((*+tE 	LL(8IJKd-
 K	  

s    C- -D	TF.)boundc                  l    \ rS rSrSrSr S       SS jjrSS jrSS jrSS jr	SS	 jr
SS
 jrSrg)r   i,  zf
Socket-like object providing TLS-in-TLS.

Only methods that are used by websockets are implemented.

i   Nc                   [         R                  " 5       U l        [         R                  " 5       U l        Xl        UR                  U R                  U R                  US9U l        U R                  U R                  R                  5        g )Nr   )	r   	MemoryBIOincomingoutgoing
ssl_socketwrap_bio
ssl_objectrun_iodo_handshake)r7   rg   rv   ri   s       r;   r6   SSLSSLSocket.__init__6  si     #,,.",,.%..MMMM+ / 

 	DOO001r=   c                    SnSn U" U6 nU R                  R	                  5       nU(       a  U R
                  R                  U5        U(       ad  U R
                  R                  U R                  5      nU(       a  U R                  R                  U5        OU R                  R                  5         M  U(       a  M  W$ ! [         R                   a    Sn N[         R                   a    Sn Nf = f)NTF)r   SSLWantReadErrorSSLWantWriteErrorr   readr   r   r   recv_bufsizer   write	write_eof)r7   funcargs	want_read
want_writeresultr   s          r;   r   SSLSSLSocket.run_ioF  s    IJ"t ==%%'D''- ++D,=,=>MM''-MM++-M- .. ! 	// "!
"s   B> >C.C.-C.c                     U R                  U R                  R                  U5      $ ! [        R                   a     gf = f)Nr=   )r   r   r   r   SSLEOFError)r7   buflens     r;   r   SSLSSLSocket.recvd  s:    	;;t33V<<%% 		s   %( ??c                N    U R                  U R                  R                  U5      $ N)r   r   r   )r7   r   s     r;   sendSSLSSLSocket.sendj  s    {{4??00$77r=   c                    Sn[        U5       o3R                  S5       n[        U5      nX%:  a  X R                  XBS  5      -  nX%:  a  M  S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr   B)
memoryviewr	   lenr   )r7   r   countview	byte_viewamounts         r;   r   SSLSSLSocket.sendallm  s]    yy~^F.9V#455 . (6~~s"   A.+AA.
A+	'A..
A<c                .    [        U R                  U5      $ r   )getattrr   )r7   names     r;   __getattr__SSLSSLSocket.__getattr__x  s    t--r=   )r   r   r   r   r   )rg   rX   rv   zssl_module.SSLContextri   r^   r[   r\   )r   zCallable[..., T]r   r   r[   r   )r   intr[   bytes)r   r   r[   r   )r   r   r[   r\   )r   strr[   r   )r_   r`   ra   rb   rc   r   r6   r   r   r   r   r   rd   r   r=   r;   r   r   ,  sW     L '+	22 +2 $	2
 
2 <86.r=   r   ).r   r   rg   zsocket.socket | Nonerh   ssl_module.SSLContext | Noneri   r^   rj   zOrigin | Nonerk   z'Sequence[ClientExtensionFactory] | Nonerl   zSequence[Subprotocol] | Nonerm   r^   rI   r]   rJ   r^   rn   zstr | Literal[True] | Nonero   r   rp   r^   rq   rY   r.   rY   r/   rY   r0   rY   rr   rZ   r1   rZ   rs   zLoggerLike | Nonert   ztype[ClientConnection] | Noner   r   r[   r'   )NN)rx   r^   r   r^   r   r   r[   r'   )
rn   r   r   r    r   r$   r   r   r[   rX   )rg   rX   r   r$   r[   r   )rn   r   r   r    r   r$   rJ   r^   rh   r   ri   r^   r   r   r[   rX   )H
__future__r   r8   rh   r   r3   r   collections.abcr   typingr   r   r   r   r	   clientr   datastructuresr   
exceptionsr   r   r   extensions.baser   extensions.permessage_deflater   rB   r   http11r   r   r9   r   r   rn   r   r   r   r   streamsr   r   r   r   r   r   r    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;   <module>r     s<   "     $ 8 8 # ( L L 4 L + ) ( J J " ? ? ) "  :b%z b%R "&(,"& :>15'-1$.(,.2(,!#"$!#"$;@<> $7;;F	F 	F
 
&F  F F 8F /F F +F "F &F  ,!F" &#F& 'F(  )F* +F,  -F0 91F2 :3F6 7F: 5;F< =F> ?FT <
<	< < 	<<4J&5 ##""##""	 	JJJ J 	J
 
J4N %)(,"&### #
 "# 
&#  # # #L CLCxQ'(M. M.  TTTT T 	T
 
TTs   >F F%$F%