
    Oj                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Zd dlZd dlmZmZmZ d dlmZ d dlmZmZmZmZmZmZ ddlmZmZmZ ddlmZm Z  dd	l!m"Z"m#Z#m$Z$m%Z%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l0m1Z1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 ddlm:Z:m;Z;m<Z<m=Z=m>Z> ddl?m@Z@mAZA ddlBmCZC ddlDmEZE g dZF eGej                  j                  dd            ZJ G d deC      ZK G d d      ZLedddddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d<d       ZMeddddddddddddddddddddd 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d=d!       ZMddddddd"de.d#ddd$d%d%d$d&d'dddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d>d(ZM	 	 d?	 	 	 	 	 	 	 d@d)ZNe	 	 dAdd*	 	 	 	 	 	 	 	 	 dBd+       ZOe	 	 dA	 	 	 	 	 	 	 	 	 dCd,       ZO	 	 d?dd*	 	 	 	 	 	 	 	 	 dDd-ZO	 d d.lPmQZQ d d/lRm4ZS eQj                  eQj                  eQj                  eQj                  d0ZVd#d1d#d1d0ZW	 	 	 	 	 	 	 	 	 	 dEd2ZXdFd4ZZdddd5	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dGd6Z[ ed7      Z\ ed8ede\f   9      Z] G d: d;      Z^y# eY$ r 	 	 	 	 	 	 	 	 	 	 dEd3ZXY Sw xY w)H    )annotationsN)	GeneratorIteratorSequence)TracebackType)AnyCallableLiteralTypeVarcastoverload   )ClientProtocolbackoffprocess_exception)HeadersHeadersLike)InvalidProxyMessageInvalidProxyStatusInvalidStatus
ProxyErrorSecurityError)ClientExtensionFactory) enable_client_permessage_deflate)validate_subprotocols)
USER_AGENTResponse)
CONNECTINGEvent)Proxy	get_proxyparse_proxyprepare_connect_request)StreamReader)	BytesLike
LoggerLikeOriginPathLikeSubprotocol)WebSocketURI	parse_uri   )
Connection)Deadline)connectunix_connect	reconnectunix_reconnectClientConnectionWEBSOCKETS_MAX_REDIRECTS10c                       e Zd ZdZddddd	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZd fdZddZd	ed	f	 	 	 	 	 	 	 dd
Zd fdZ	d fdZ
 xZS )r3   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               t    |  t        j                         | _        d| _        t        |   ||||||       y )NTr:   )	threadingr   response_rcvdpending_legacy_warningsuper__init__)selfsockprotocolr;   r<   r=   r>   	__class__s          m/var/www/origus_pro_usr/data/www/origus.pro/core/.venv/lib/python3.12/site-packages/websockets/sync/client.pyrD   zClientConnection.__init__E   sC     	&__.&*#'%' 	 	
    c                .    d| _         t        | 	         S )NF)rB   rC   	__enter__rE   rH   s    rI   rL   zClientConnection.__enter__[   s    &+#w ""rJ   c                d    | j                   r$d| _         t        j                  dt        d       y y )NFzconnect() must be used as a context manager: with connect(...) as websocket: ...; alternatively, use websocket = connect(..., legacy=True) to connect directly   )
stacklevel)rB   warningswarnDeprecationWarningrE   s    rI   maybe_raise_legacy_warningz+ClientConnection.maybe_raise_legacy_warning_   s2    &&*/D'MML # 'rJ   Nc                $   | j                   j                         | _        |%| j                  j                  j	                  |       |&| j                  j                  j                  d|       | j                  t              5  | 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.

        Nz
User-Agent)expected_statez.timed out while waiting for handshake response)rG   r/   requestheadersupdate
setdefaultsend_contextr   send_requestrA   waitTimeoutErrorhandshake_exc)rE   additional_headersuser_agent_headertimeouts       rI   	handshakezClientConnection.handshakej   s     }},,.)LL  ''(:;(LL  ++L:KLj9 	5MM&&t||4	5 !!&&w/OPP ==&&2----- 3	5 	5s   &DDc                    | j                   4t        |t              sJ || _         | j                  j	                          yt
        |   |       y)z.
        Process one incoming event.

        N)response
isinstancer   rA   setrC   process_event)rE   eventrH   s     rI   ri   zClientConnection.process_event   sG     == eX...!DM""$ G!%(rJ   c                    	 t         |           | j                  j                          y# | j                  j                          w xY w)zI
        Read incoming data from the socket and process events.

        N)rC   recv_eventsrA   rh   rM   s    rI   rl   zClientConnection.recv_events   s:    
	%G! ""$D""$s	   , A)rF   socket.socketrG   r   r;   float | Noner<   rn   r=   rn   r>   *int | None | tuple[int | None, int | None]returnNonerp   r3   )rp   rq   )ra   HeadersLike | Nonerb   
str | Nonerc   rn   rp   rq   )rj   r   rp   rq   )__name__
__module____qualname____doc__rD   rL   rU   r   rd   ri   rl   __classcell__)rH   s   @rI   r3   r3   +   s    < ')%'&(@B

 !

 $
 #
 $
 >
 

,#	 26(2 $	... &. 	.
 
.8)	% 	%rJ   r3   c                      e Zd ZdZddddddddedddeddddeddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
ZddZddZ	ddZ
ddZddZddZ	 	 	 	 	 	 	 	 ddZddZy)r1   as  
    Similar to :func:`connect`, with support for automatic reconnection.

    :func:`reconnect` can also be treated as an infinite iterator to reconnect
    automatically on errors::

        for websocket in reconnect(...):
            try:
                ...
            except websockets.exceptions.ConnectionClosed:
                continue

    If the connection fails with a transient error, it is retried with
    exponential backoff. If it fails with a fatal error, the exception is
    raised, breaking out of the loop.

    The connection is closed automatically after each iteration of the loop.

    :func:`reconnect` accepts the same arguments as :func:`connect`, minus the
    ``legacy`` flag, plus those listed below. It raises the same exceptions.

    Args:
        process_exception: When reconnecting automatically, tell whether an
            error is transient or fatal. The default behavior is defined by
            :func:`~websockets.client.process_exception`. Refer to its
            documentation for details.
        reconnect_delays: Delays in seconds between reconnection attempts.
            Default is exponential backoff with 5s jitter, capped at 60s.

    .. admonition:: Why is :func:`reconnect` a separate API from :func:`connect`?
        :class: tip

        A new API was necessary to maintain backwards compatibility with this
        historical behavior of :func:`connect`::

            websocket = connect(...)
            for message in websocket:
                ...

        Once the deprecation period elapses, :func:`connect` will be changed to
        behave like :func:`reconnect` by default.

    NdeflateTr8   r7      r9   )rF   sslserver_hostnameorigin
extensionssubprotocolscompressionra   rb   proxy	proxy_sslproxy_server_hostnamer   open_timeoutr;   r<   r=   reconnect_delaysmax_sizer>   loggercreate_connectionc                  |/d|v r+|j                  d      }t        j                  dt               || _        t        |      | _        | j                  j                  s|t        d      |t        |       |dk(  rt        |      }n|t        d|       |t        j                  d      }|t        }|| _        || _        || _        |	| _        |
| _        || _        || _        || _        || _        || _        || _        || _        || _        || _        t9        |||||      | _        t9        ||||      | _        y )	Nssl_contextzssl_context was renamed to sslz-ssl argument is incompatible with a ws:// URIr{   zunsupported compression: zwebsockets.client)r   r   r   r   r   r:   )poprQ   rR   rS   urir+   ws_urisecure
ValueErrorr   r   logging	getLoggerr3   rF   r}   r~   ra   rb   r   r   r   r   r   r   r   r   open_socket_kwargsdictprotocol_kwargsconnection_kwargs)rE   r   rF   r}   r~   r   r   r   r   ra   rb   r   r   r   r   r   r;   r<   r=   r   r   r>   r   r   kwargss                            rI   rD   zreconnect.__init__   s_   J ;=F2**]+CMM0"
 n{{!!coLMM#!,/)#9*EJ$8FGG>&&':;F$ 0	."4!2
"%:"!2( 0!2"(#!% 
 "&'%'	"
rJ   c           	        | j                   j                         }|j                  dd      }| j                  }|rd}|du rt	        | j
                        }|rt        j                  t        j                  t        j                        }	 |j                  |j                                |j                  t        j                  |j                  d                   n8|t!        |      }|j"                  dd dk(  r*t%        || j
                  ||j                  dd      	      }n|j"                  dd
 dk(  ra|j"                  dk7  r| j&                  t)        d      t+        || j
                  |f| j,                  | j&                  | j.                  d|}n|t1        d      |j3                  d| j
                  j4                  | j
                  j6                  f       |j3                  d|j                                t        j8                  di |}|j                  d       |S # t        $ r |j                           w xY w)zFOpen a TCP or Unix connection to the server, possibly through a proxy.unixFNTpath   sockssource_address)
local_addr   httphttpsz8proxy_ssl argument is incompatible with an http:// proxyrb   r}   r~   z&parse_proxy returned unsupported proxyaddressrc    )r   copyr   r   r!   r   socketAF_UNIXSOCK_STREAM
settimeoutrc   r/   osfspath	Exceptioncloser"   schemeconnect_socks_proxyr   r   connect_http_proxyrb   r   AssertionErrorr[   hostportr   )rE   deadliner   r   r   rF   proxy_parseds          rI   open_socketzreconnect.open_socket(  s   ((--/zz&%(

ED=dkk*E==1C1CDD 0 0 23RYYvzz&'9:;
 &u-L""2A&'1* KK  &zz*:DA $$Ra(F2&&'1dnn6P$R  * KK '+&<&<$($>$>  %%MNN i$++*:*:DKK<L<L)MNi)9)9);<++5f5DS  

s   AH* *Ic                   | j                   t        j                         }n| j                   }| j                  | j                  j
                  }n| j                  }|j                  |j                                | j                  |j                  ||      }n(t        |||      }t        t        j                  |      }|j                  d       |S )zEnable TLS on the connection.Nr~   )r}   
ssl_modulecreate_default_contextr~   r   r   r   rc   r   wrap_socketSSLSSLSocketr   r   )rE   rF   r   r}   r~   sock_2s         rI   
enable_tlszreconnect.enable_tlsc  s    88335C((C'"kk..O"22O((*+>>!??4?ID!$_MFv.DrJ   c                   | j                   | j                  |      }n| j                   }	 |j                  t        j                  t        j
                  hv r/|j                  t        j                  t        j                  d       | j                  j                  r| j                  ||      }t        | j                  fi | j                  } | j                  ||fi | j                  }	 |j%                  | j&                  | j(                  |j+                                |S # t         $ r |j#                           w xY w# t         $ r, |j-                          |j.                  j1                           w xY w)zCreate a WebSocket connection.T)rF   r   familyr   AF_INETAF_INET6
setsockoptIPPROTO_TCPTCP_NODELAYr   r   r   r   r   r   r   r   r   rd   ra   rb   rc   close_socketrecv_events_threadjoin)rE   r   rF   rG   
connections        rI   open_connectionzreconnect.open_connectionw  sL   99##H-D99D	{{v~~v?? 2 2F4F4FM{{!!tX6%&&H 0// ((J		  ''&&  "   	JJL	  	##%))..0	s   CD% .5E %E 5E8c                   t        |t              r0|j                  j                  dv rd|j                  j                  v s|S | j
                  }t        j                  j                  | j                  |j                  j                  d         }t        |      }| j                  t        d| d      S |j                  r|j                  st        d|       S |j                  |j                  k7  s2|j                  |j                  k7  s|j                   |j                   k7  r| j"                  j%                  dd      rt        d| d	      S | j"                  j%                  d
      t        d| d      S | j&                  8t)        d t)        | j&                        j+                         D              | _        |S )z
        Determine whether a connection error is a redirect that can be followed.

        Return the new URI if it's a valid redirect. Else, return an exception.

        ),  i-  i.  i/  i3  i4  Locationzcannot follow redirect to z with a preexisting socketz)cannot follow redirect to non-secure URI r   Fz'cannot follow cross-origin redirect to z with a Unix socketr   z with an explicit host and portc              3  N   K   | ]  \  }}|j                         d vr||f  yw))authorizationcookiezproxy-authorizationN)lower).0keyvalues      rI   	<genexpr>z-reconnect.process_redirect.<locals>.<genexpr>  s2      &C99;QR es   #%)rg   r   rf   status_coderY   r   urllibparseurljoinr   r+   rF   r   r   r   r   r   r   getra   r   	raw_items)rE   exc
old_ws_urinew_uri
new_ws_uris        rI   process_redirectzreconnect.process_redirect  s    sM*(( cll222J[[
,,&&txx1E1Ej1QRw'
 99 ,WI5OP 
 Z%6%6 #LWI!VWW !2!22*//1*//1 &&**659!=gY G) *  &&**95A!=gY G5 6  &&2*1*1$2I2I*J*T*T*V+' rJ   c                p   t        | j                        }t        t              D ]'  }	 | j	                  |      }|j                          |c S  t        dt         d      # t        $ rJ}| j                  |      }t        |t              r||u r |||| _	        t        |      | _        Y d}~d}~ww xY w)z3Connect to a WebSocket server, following redirects.Nz
more than z
 redirects)r.   r   rangeMAX_REDIRECTSr   start_keepaliver   r   rg   r   r+   r   r   )rE   r   _r   r   
exc_or_uris         rI   r/   zreconnect.connect  s    
 D--.}% 	HA"!11(;
  **,!!'	H*  *]O: FGG%  !2237
j)4!S((c1  *DH"+J"7DKs   A""	B5+A B00B5c                    t        | d      rt        d      | j                         | _        d| j                  _        | j                  S )Nr   zconnect() isn't reentrantF)hasattrRuntimeErrorr/   r   rB   rT   s    rI   rL   zreconnect.__enter__  s;    4&:;;,,.16.rJ   c                L    	 | j                   j                          | ` y # | ` w xY wN)r   r   )rE   exc_type	exc_valueexc_tracebacks       rI   __exit__zreconnect.__exit__  s"    	 OO!!#s    #c              #    K   d }	 	 | 5 }| d d d        d }# 1 sw Y   xY w# t         $ r}	 | j                  |      }n# t         $ r}|}Y d }~nd }~ww xY w||u r ||||| j                         }t        |      }| j                  j                  d|t        j                  |      d   j                                t        j                  |       Y d }~d }~ww xY ww)Nz0connect failed; reconnecting in %.1f seconds: %sr   )r   r   r   nextr   info	tracebackformat_exception_onlystriptimesleep)rE   delaysr   r   new_exc
raised_excdelays          rI   __iter__zreconnect.__iter__  s     *." %Z$$%B G % % "
)"44S9G  )(G)
 c>&!s* >!224FV  F33C8;AAC
 

5!!7"s_   C#% % C#"% 	C A C	A
ACAB CC#C  C#)2r   strrF   socket.socket | Noner}   ssl_module.SSLContext | Noner~   rt   r   Origin | Noner   'Sequence[ClientExtensionFactory] | Noner   Sequence[Subprotocol] | Noner   rt   ra   rs   rb   rt   r   str | Literal[True] | Noner   r   r   rt   r   z'Callable[[Exception], Exception | None]r   rn   r;   rn   r<   rn   r=   rn   r   zCallable[[], Generator[float]]r   ro   r>   ro   r   LoggerLike | Noner   type[ClientConnection] | Noner   r   rp   rq   )r   r.   rp   rm   )rF   rm   r   r.   rp   rm   )r   r.   rp   r3   )r   r   rp   zException | strrr   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Nonerp   rq   )rp   zIterator[ClientConnection])ru   rv   rw   rx   r   r   r   rD   r   r   r   r   r/   rL   r   r   r   rJ   rI   r1   r1      s   *b &*,0&* $>B59"+15(2,026,0EV%'&(%'&(;B?D@B$(;?AY
Y

 #Y
 *Y
 $Y
 Y
 <Y
 3Y
  Y
 /Y
 &Y
  *!Y
" 0#Y
$  *%Y
& C'Y
* #+Y
, $-Y
. #/Y
0 $1Y
2 93Y
6 =7Y
8 >9Y
< "=Y
@ 9AY
D EY
F 
GY
v9v()VCJH@	 ,	  (	  ,		 
 
	 %rJ   r1   .)rF   r}   r~   r   r   r   r   ra   rb   r   r   r   r   r;   r<   r=   r   r>   r   r   legacyc                    y r   r   r   rF   r}   r~   r   r   r   r   ra   rb   r   r   r   r   r;   r<   r=   r   r>   r   r   r  r   s                          rI   r/   r/   C  s    F rJ   )rF   r}   r~   r   r   r   r   ra   rb   r   r   r   r   r;   r<   r=   r   r>   r   r   c                    y r   r   r	  s                          rI   r/   r/   i  s    F rJ   r{   Tr8   r7   r|   r9   c                   t        | fi d|d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|d|d|d|d||}|du r|S |j                         }|rd|_        |S )a  
    Connect to the WebSocket server at ``uri``.

    :func:`connect` should be treated as a context manager yielding a
    :class:`ClientConnection`, which can then receive and send messages::

        from websockets.sync.client import connect

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

    The connection is closed automatically when exiting the context.

    Use :func:`reconnect` to reconnect automatically on errors.

    For backwards compatibility, :func:`connect` can be called directly::

        websocket = connect(..., legacy=True)

    In that case, you're responsible for closing the connection with
    :meth:`ClientConnection.close` when no longer needed.

    When the ``legacy`` flag is enabled, :func:`connect` returns directly a
    :class:`ClientConnection` and iterating that connection yields messages.
    Currently, this is the default behavior when ``legacy`` isn't specified.

    When the ``legacy`` flag is explicitly disabled, :func:`connect` behaves
    like :func:`reconnect`: using it as an iterator returns a new connection
    at each iteration, making it easy to reconnect automatically on errors.

    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: 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.
        legacy: Set to :obj:`True` to opt into the historical behavior of
            returning a :class:`ClientConnection`, without deprecation warning.
        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`.
    For example, you can set ``address`` to a ``(host, port)`` tuple to connect
    to a different host and port from those found in ``uri``. This only changes
    the destination of the TCP connection. The host name from ``uri`` is still
    used in the TLS handshake for secure connections and in the ``Host`` header.

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

    rF   r}   r~   r   r   r   r   ra   rb   r   r   r   r   r;   r<   r=   r   r>   r   r   F)r1   r/   rB   )r   rF   r}   r~   r   r   r   r   ra   rb   r   r   r   r   r;   r<   r=   r   r>   r   r   r  r   	connecterr   s                            rI   r/   r/     s   J   (	
   "   . ,   4 " $  "!" $#$ %& '( )* ,
-I4 ""$J ,1
)rJ   c                    |j                  d      }| |t        d      | |t        d      |'|j                  d      |j                  d      d}nd}t        d
|d| d	|S )z
    Similar to :func:`unix_connect`, with support for automatic reconnection.

    Refer to the documentation of :func:`reconnect` for details on its behavior.

    rF   zmissing path argumentzpath is incompatible with sockr}   r   zws://localhost/zwss://localhost/T)r   r   r   r   )r   r   r1   )r   r   r   rF   s       rI   r2   r2   8  s     ::fD|011		d.9::
{::e$M)B)J#C$C=4d=f==rJ   )r  c                    y r   r   r   r   r  r   s       rI   r0   r0   S  s     rJ   c                    y r   r   r  s       rI   r0   r0   ]  s     rJ   c               ^    t        | |fi |}|du r|S |j                         }|r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/``.

    F)r2   r/   rB   )r   r   r  r   r  r   s         rI   r0   r0   g  sE    . tS3F3I ""$J ,1
)rJ   )	ProxyType)r    )socks5hsocks5socks4asocks4Fc           	        t        t        | j                     | j                  | j                  | j
                  | j                  t        | j                           }|j                  d|j                                	  |j                  |j                  |j                  fi |S # t        t        t        j                  f$ r  t        $ r}t        d      |d}~ww xY w)z0Connect via a SOCKS proxy and return the socket.rc   z failed to connect to SOCKS proxyN)
SocksProxySOCKS_PROXY_TYPESr   r   r   usernamepasswordSOCKS_PROXY_RDNSr[   rc   r/   OSErrorr_   r   r   r   )r   r   r   r   socks_proxyr   s         rI   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                    t        d      )Nz6connecting through a SOCKS proxy requires python-socks)ImportError)r   r   r   r   s       rI   r   r     s     RSSrJ   c                   t               }t        j                  |j                  |j                  |j
                  d      }	 	 | j                  |j                                | j                  d      }|r|j                  |       n|j                          t        |       `# t        $ rr}t        |j                  t              sJ |j                  }d|j                  cxk  rdk  r%n t!        |      |cY d }~| j                  d        S t!        |      d }~wt"        j                  $ r t%        d      t&        $ r}t)        d      |d }~ww xY w# | j                  d        w xY w)NT)r   i      r   z(timed out while connecting to HTTP proxyz0did not receive a valid HTTP response from proxy)r$   r   r   	read_line
read_exactread_to_eofr   rc   recv	feed_datafeed_eofr   StopIterationrg   r   r   r   r   r_   r   r   )rF   r   readerparserdatar   rf   s          rI   read_connect_responser-    s;   ^F^^	FOOH,,./99T?D  &!L   /#))X...99(&&,, %X.. O 	 %X..>> GEFF !>
	
 	sD   A!B$ $	E-AD8E9E D)EEEE E*r   c                  |j                  d|j                                t        j                  | j                  | j
                  ffi |}| j                  dk(  rg|t        j                         }|| j                  }|j                  |j                                |j                  ||      }|j                  d        t        | ||      }|j                  |       	 t        ||       |S # t        $ r |j                           w xY w)Nrc   r   r   )r[   rc   r   r   r   r   r   r   r   r   r   r#   sendallr-  r   r   )	r   r   r   rb   r}   r~   r   rF   rX   s	            rI   r   r     s     i!1!1!34##UZZ$<GGD ||w;335C"#jjO((*+t_E &eV5FGGLLdH-
 K	  

s   "C0 0DTF)boundc                  V    e Zd ZdZdZ	 d
	 	 	 	 	 	 	 ddZddZddZddZddZ	dd	Z
y)r   zr
    Socket-like object providing TLS-in-TLS.

    Only methods that are used by websockets are implemented.

    i   Nc                   t        j                         | _        t        j                         | _        || _        |j                  | j                  | j                  |      | _        | j                  | j                  j                         y )Nr   )	r   	MemoryBIOincomingoutgoing
ssl_socketwrap_bio
ssl_objectrun_iodo_handshake)rE   rF   r   r~   s       rI   rD   zSSLSSLSocket.__init__  sk     #,,.",,.%..MMMM+ / 

 	DOO001rJ   c                   	 d}d}	  || }| j                  j	                         }|r| j
                  j                  |       |r^| j
                  j                  | j                        }|r| j                  j                  |       n| j                  j                          |rS # t         j                  $ r d}Y t         j                  $ r d}Y w xY w)NTF)r   SSLWantReadErrorSSLWantWriteErrorr7  readr8  r/  r&  recv_bufsizer6  write	write_eof)rE   funcargs	want_read
want_writeresultr,  s          rI   r;  zSSLSSLSocket.run_io)  s    IJ"t ==%%'D''- ++D,=,=>MM''-MM++-M- .. ! 	// "!
"s   B( (C?CCc                    	 | j                  | j                  j                  |      S # t        j                  $ r Y yw xY w)NrJ   )r;  r:  r@  r   SSLEOFError)rE   buflens     rI   r&  zSSLSSLSocket.recvG  s:    	;;t33V<<%% 		s   %( >>c                N    | j                  | j                  j                  |      S r   )r;  r:  rB  )rE   r,  s     rI   sendzSSLSSLSocket.sendM  s    {{4??00$77rJ   c                    d}t        |      5 }|j                  d      5 }t        |      }||k  r|| j                  ||d        z  }||k  rd d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   B)
memoryviewr   lenrM  )rE   r,  countview	byte_viewamounts         rI   r/  zSSLSSLSocket.sendallP  sz     	6tyy~ 	6^F&.9UV#455 &.	6 	6 	6 	6 	6 	6s"   A+-AA+A(	$A++A4c                .    t        | j                  |      S r   )getattrr8  )rE   names     rI   __getattr__zSSLSSLSocket.__getattr__[  s    t--rJ   r   )rF   rm   r   zssl_module.SSLContextr~   rt   rp   rq   )rD  zCallable[..., T]rE  r   rp   r0  )rK  intrp   bytes)r,  r%   rp   rZ  )r,  r%   rp   rq   )rX  r   rp   r   )ru   rv   rw   rx   rA  rD   r;  r&  rM  r/  rY  r   rJ   rI   r   r     sW     L '+	22 +2 $	2
 
2 <86.rJ   r   )0r   r   rF   r   r}   r   r~   rt   r   r  r   r  r   r  r   rt   ra   rs   rb   rt   r   r  r   r   r   rt   r   rn   r;   rn   r<   rn   r=   rn   r   ro   r>   ro   r   r  r   r  r  Literal[True] | Noner   r   rp   r3   )0r   r   rF   r   r}   r   r~   rt   r   r  r   r  r   r  r   rt   ra   rs   rb   rt   r   r  r   r   r   rt   r   rn   r;   rn   r<   rn   r=   rn   r   ro   r>   ro   r   r  r   r  r  Literal[False]r   r   rp   r1   )0r   r   rF   r   r}   r   r~   rt   r   r  r   r  r   r  r   rt   ra   rs   rb   rt   r   r  r   r   r   rt   r   rn   r;   rn   r<   rn   r=   rn   r   ro   r>   ro   r   r  r   r  r  bool | Noner   r   rp   ClientConnection | reconnect)NN)r   PathLike | Noner   rt   r   r   rp   r1   )..)
r   r`  r   rt   r  r\  r   r   rp   r3   )
r   r`  r   rt   r  r]  r   r   rp   r1   )
r   r`  r   rt   r  r^  r   r   rp   r_  )
r   r    r   r*   r   r.   r   r   rp   rm   )rF   rm   r   r.   rp   r   )r   r    r   r*   r   r.   rb   rt   r}   r   r~   rt   r   r   rp   rm   )_
__future__r   r   r   r   r}   r   r@   r   r   urllib.parser   rQ   collections.abcr   r   r   typesr   typingr   r	   r
   r   r   r   clientr   r   r   datastructuresr   r   
exceptionsr   r   r   r   r   extensions.baser   extensions.permessage_deflater   rY   r   http11r   r   rG   r   r   r   r    r!   r"   r#   streamsr$   r%   r&   r'   r(   r)   r   r*   r+   r   r-   utilsr.   __all__rZ  environr   r   r3   r1   r/   r2   r0   python_socksr  python_socks.syncr  SOCKS5SOCKS4r  r  r   r   r-  r   r0  r1  r   r   rJ   rI   <module>rt     s   "  	        9 9  B B ? ? 1  5 L + ) ( J J " I I ) "  YBJJNN#=tDEr%z r%j` `F 

 "%(+"%:=14!-0$'(+.1(+!$"%!$"%;><? #7:#&?"	" 	"
 
&"  " " 8" /" " +" "" &"  ,!"" &#"& '"(  )"* +",  -"0 91"2 :3"6 7": 5;"> !?"B C"D E" 
"J 

 "%(+"%:=14!-0$'(+.1(+!$"%!$"%;><? #7:;"	" 	"
 
&"  " " 8" /" " +" "" &"  ,!"" &#"& '"(  )"* +",  -"0 91"2 :3"6 7": 5;"> ?"B C"D E" 
"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B CfD "EfT !>
>	> > 	>6 
 $'	
	 !	
   
 

	 	
   
 !! 	!
!	! 	!
 ! "!H4J&5 ##""##""	 	JJJ J 	J
 
J4N %)(,"&$$$ $
 "$ 
&$  $ $ $N CLCxQ'(M. M.A  TTTT T 	T
 
TTs   2K   KK