
    ,hii                       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mZmZmZ d dlmZ d dlmZmZmZ ddl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!m"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, ddl-m.Z. ddlm/Z/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5 ddlm6Z6m7Z7 ddl8m9Z9m:Z: ddl;m<Z< ddl=m>Z> g dZ? G d de>      Z@ G d d      ZAeAZB	 	 d	 	 	 	 	 	 	 ddZCy)    )annotationsN)AsyncIterator	GeneratorSequence)TracebackType)AnyCallablecast   )asyncio_timeout)HeadersHeadersLike)InvalidHeaderInvalidHeaderValueInvalidMessageNegotiationError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   )InvalidStatusCodeRedirectHandshake)build_requestcheck_response)read_response)WebSocketCommonProtocol)connectunix_connectWebSocketClientProtocolc                       e Zd ZdZdZdZddddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZddZ	e
	 	 	 	 	 	 dd	       Ze
	 	 	 	 	 	 dd
       Z	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ xZS )r.   a  
    WebSocket client connection.

    :class:`WebSocketClientProtocol` provides :meth:`recv` and :meth:`send`
    coroutines for receiving and sending messages.

    It supports asynchronous iteration to receive 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) or without a close code. 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_headerc                   |t        j                  d      }t        |   dd|i| || _        || _        || _        || _        || _        y )Nwebsockets.clientr1    )	logging	getLoggersuper__init__r2   available_extensionsavailable_subprotocolsr5   r6   )	selfr1   r2   r3   r4   r5   r6   kwargs	__class__s	           Z/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/websockets/legacy/client.pyr=   z WebSocketClientProtocol.__init__M   sW     >&&':;F11&1$.!&2#*!2    c                T   || _         || _        | j                  rQ| j                  j                  d|       |j	                         D ]"  \  }}| j                  j                  d||       $ d| d}|t        |      z  }| j                  j                  |j                                y)zF
        Write request line and headers to the HTTP request.

        z> GET %s HTTP/1.1z> %s: %szGET z HTTP/1.1
N)	pathrequest_headersdebugr1   	raw_itemsstr	transportwriteencode)r@   rF   headerskeyvaluerequests         rC   write_http_requestz*WebSocketClientProtocol.write_http_requesta   s    
 	&::KK148%//1 :
U!!*c59:
 m,3w<W^^-.rD   c                r  K   	 t        | j                         d{   \  }}}| j                  rR| j
                  j	                  d||       |j                         D ]"  \  }}| j
                  j	                  d||       $ || _        || j                  fS 7 {# t        $ r}t        d      |d}~ww xY ww)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	Exceptionr   rH   r1   rI   response_headers)r@   status_codereasonrN   excrO   rP   s          rC   read_http_responsez*WebSocketClientProtocol.read_http_responseu   s     	S1>t{{1K+K(K ::KK0+vF%//1 :
U!!*c59: !(D1111 ,L 	S !HIsR	Ss8   B7B BB A3B7B 	B4#B//B44B7c                d   g }| j                  d      }|r|t        d      t        |D cg c]  }t        |       c}g       }|D ]Q  \  }}|D ]7  }|j                  |k7  r	 |j                  ||      }	|j                  |	        A t        d| d|        |S c c}w # t        $ r Y ^w xY w)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-Extensionszno extensions supportedzUnsupported extension: name = z, params = )get_allr   sumr   nameprocess_response_paramsappend)
rN   r>   accepted_extensionsheader_valuesheader_valueparsed_header_valuesr_   response_paramsextension_factory	extensions
             rC   process_extensionsz*WebSocketClientProtocol.process_extensions   s    > 02(BC#+&'@AA:=CPQ<.QSU;  *> %o)= %(--5 !$5$M$M+-@%	 (..y9 #, +""&{?2CE /8 #"? R , ! !s   B$B##	B/.B/c                    d}| j                  d      }|rs|t        d      t        |D cg c]  }t        |       c}g       }t	        |      dkD  rt        dddj                  |             |d   }||vrt        d|       |S c c}w )	z
        Handle the Sec-WebSocket-Protocol HTTP response header.

        Check that it contains exactly one supported subprotocol.

        Return the selected subprotocol.

        NSec-WebSocket-Protocolzno subprotocols supportedr%   zmultiple values: z, r   zunsupported subprotocol: )r]   r   r^   r   lenr   join)rN   r?   subprotocolrc   rd   re   s         rC   process_subprotocolz+WebSocketClientProtocol.process_subprotocol   s     +/(@A%-&'BCC:=ERS\"<0SUW;  '(1,(,'		2F(G'HI 
 /q1K"88&)B;-'PQQ Ts   Bc                  K   t               }t        |j                  |j                  |j                        |d<   |j
                  rt        |j
                   |d<   |||d<   t        |      }|8t        |D cg c]  }|j                  |j                         f  c}      }	|	|d<   |t        |      }
|
|d<   | j                  |j                  | j                         | j                  r|j                  d| j                         | j!                  |j"                  |       | j%                          d{   \  }}|dv rd	|vrt'        d	      t)        |d	         |d
k7  rt+        ||      t-        ||       | j/                  ||      | _        | j3                  ||      | _        | j7                          yc c}w 7 w)a9  
        Perform the client side of the opening handshake.

        Args:
            wsuri: URI of the WebSocket server.
            origin: Value of the ``Origin`` header.
            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.
            extra_headers: Arbitrary HTTP headers to add to the handshake request.

        Raises:
            InvalidHandshake: If the handshake fails.

        HostAuthorizationNr!   r\   rk   z
User-Agent)i-  i.  i/  i3  i4  Locatione   )r   r   hostportsecure	user_infor   r(   r   r_   get_request_paramsr   r5   updater6   
setdefaultrR   resource_namerZ   r   r'   r&   r)   ri   r3   ro   rn   connection_open)r@   wsurir2   r>   r?   r5   rG   rO   rg   extensions_headerprotocol_headerrW   rV   s                rC   	handshakez!WebSocketClientProtocol.handshake   s    0 ")",UZZU\\"R??/H0OO, (.OH%O,+ / .B) '++->-Q-Q-ST! ;LO67!-/0FGO8GO45)""4#5#56!!&&|T5K5KL 3 3_E.2.E.E.G(G%%33!11#J//#$4Z$@AAC#K1ABB'-112
  334
 	K& )Hs    A7G9#F=BG8G9B
G)r1   LoggerLike | Noner2   Origin | Noner3   'Sequence[ClientExtensionFactory] | Noner4   Sequence[Subprotocol] | Noner5   HeadersLike | Noner6   
str | NonerA   r   returnNone)rF   rJ   rN   r   r   r   )r   ztuple[int, Headers])rN   r   r>   r   r   zlist[Extension])rN   r   r?   r   r   zSubprotocol | None)NNNN)r~   r#   r2   r   r>   r   r?   r   r5   r   r   r   )__name__
__module____qualname____doc__	is_clientsider   r=   rR   rZ   staticmethodri   ro   r   __classcell__)rB   s   @rC   r.   r.   /   s=   4 ID
 %) $>B59,0(23 "3 	3
 <3 33 *3 &3 3 
3(/(24 F#F#EF# 
F# F#P ""2N"	" "N !%HL?C,0MM M F	M
 !=M *M 
MrD   r.   c                     e Zd ZdZ eej                  j                  dd            Zddddddde	dddddd	d
d
d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
ddZ eej                  j                  dd            Z eej                  j                  dd            Z eej                  j                  dd            Z eej                  j                  dd            ZddZddZ	 	 	 	 	 	 	 	 ddZd dZddZeZy)!Connecta  
    Connect to the WebSocket server at ``uri``.

    Awaiting :func:`connect` yields a :class:`WebSocketClientProtocol` which
    can then be used to send and receive messages.

    :func:`connect` can be used as a asynchronous context manager::

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

    The connection is closed automatically when exiting the context.

    :func:`connect` can be used as an infinite asynchronous iterator to
    reconnect automatically on errors::

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

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

    If an error occurs while establishing the connection, :func:`connect`
    retries with exponential backoff. The backoff delay starts at three
    seconds and increases up to one minute.

    If an error occurs in the body of the loop, you can handle the exception
    and :func:`connect` will reconnect with the next iteration; or you can
    let the exception bubble up and break out of the loop. This lets you
    decide which errors trigger a reconnection and which errors are fatal.

    Args:
        uri: URI of the WebSocket server.
        create_protocol: Factory for the :class:`asyncio.Protocol` managing
            the connection. It defaults to :class:`WebSocketClientProtocol`.
            Set it to a wrapper or a subclass to customize connection handling.
        logger: Logger for this client.
            It defaults to ``logging.getLogger("websockets.client")``.
            See the :doc:`logging guide <../../topics/logging>` for details.
        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.
        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.
        extra_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.
        open_timeout: Timeout for opening the connection in seconds.
            :obj:`None` disables the timeout.

    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``.

    Any other keyword arguments are passed the event loop's
    :meth:`~asyncio.loop.create_connection` method.

    For example:

    * You can set ``ssl`` to a :class:`~ssl.SSLContext` to enforce TLS
      settings. When connecting to a ``wss://`` URI, if ``ssl`` isn't
      provided, a TLS context is created
      with :func:`~ssl.create_default_context`.

    * You can set ``host`` and ``port`` 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.
        OSError: If the TCP connection fails.
        InvalidHandshake: If the opening handshake fails.
        ~asyncio.TimeoutError: If the opening handshake times out.

    WEBSOCKETS_MAX_REDIRECTS10Ndeflate
      i       i   )create_protocolr1   compressionr2   r3   r4   r5   r6   open_timeoutping_intervalping_timeoutclose_timeoutmax_size	max_queue
read_limitwrite_limitc                  |j                  dd       }|d}nt        j                  dt               ||}|j                  dd       }|t        }nt        j                  dt               ||}|j                  dd      }|j                  dd       }|t        j                         }n|}t        j                  d	t               t        |      }|j                  r|j                  d
d       n|j                  d
      t        d      |dk(  rt        |      }n|t        d|       |t        |       t        t        dt        f   |      }t!        j"                  |fi d|d|d|d|d|d|	d|d|d|d|d|d|d|d|j$                  d|j&                  d|j                  d|d|}|j                  d d      r5|j                  d!d       }t!        j"                  |j(                  ||fi |}n|j                  d"      |j$                  |j&                  }}n2d#\  }}|j                  d
      r|j                  d$|j$                         |j                  d|      }|j                  d|      }t!        j"                  |j*                  |||fi |}|
| _        |t/        j0                  d%      }|| _        || _        || _        || _        y )&Ntimeoutr   zrename timeout to close_timeoutklasszrename klass to create_protocollegacy_recvFloopzremove loop argumentsslTzQconnect() received a ssl argument for a ws:// URI, use a wss:// URI to enable TLSr   zunsupported compression: .r1   r2   r3   r4   r5   r6   r   r   r   r   r   r   r   ru   rv   rw   unixrF   sock)NNserver_hostnamer8   )popwarningswarnDeprecationWarningr.   asyncioget_event_loopr$   rw   r{   get
ValueErrorr   r   r
   r	   	functoolspartialru   rv   create_unix_connectioncreate_connectionr   r:   r;   r1   _create_connection_uri_wsuri)r@   urir   r1   r   r2   r3   r4   r5   r6   r   r   r   r   r   r   r   r   rA   r   r   r   _loopr   r~   factoryrF   r   ru   rv   s                                 rC   r=   zConnect.__init__  s=   . !'

9d ;?GMM;=OP #M 7=jj$6O=+EMM;=OP"#O #JJ}e< 39**VT2J=))+DDMM02DE#<<eT*ZZ*1 
 )#9*EJ$8FGG#!,/ x-D(DEW##

 
 "	

 &
 (
 0
 (
 &
 (
 
  
 "
 $
 
  !
" <<#
$ $%
& '
, ::fe$%zz&$7D ) 1 1++Wd!>D! zz&!)"ZZd (
d::e$%%&7D::fd+D::fd+D ) 1 1&&t!?E! )>&&':;F #4	rD   c           	        | j                   }| j                  }t        j                  j	                  ||      }t        |      }|j                  r|j                  st        d      |j                  |j                  k(  xr4 |j                  |j                  k(  xr |j                  |j                  k(  }|s| j                  j                  d   }|j                  sA|j                  r5d|j                  d<   | j                  j                  j                  dd       t        j                  |j                   g|j                  i t#        |j                  |j                  |j                        }t        j                  | j                  j                   g||j                  |j                  fi | j                  j                  | _
        || _         || _        y )Nzredirect from WSS to WSr   Trw   r   )ru   rv   )r   r   urllibparseurljoinr$   rw   r   ru   rv   r   argskeywordsr{   r   r   funcdict)r@   r   old_uri	old_wsurinew_uri	new_wsurisame_originr   s           rC   handle_redirectzConnect.handle_redirect"  s   ))KK	,,&&w4g&	 I$4$4 9:: 	 0 00 1)..01)..0 	 --2215G##	(8(8-1  *''00;;E4H'' w''inn9>>RG '0&7&7'',,'9>>9>>:' ))22'D# 	rD    WEBSOCKETS_BACKOFF_INITIAL_DELAY5WEBSOCKETS_BACKOFF_MIN_DELAYz3.1WEBSOCKETS_BACKOFF_MAX_DELAYz90.0WEBSOCKETS_BACKOFF_FACTORz1.618c           
    p  K   | j                   | j                  z  }	 	 | 4 d {   }| d d d       d {    | j                   }.7 &7 # 1 d {  7  sw Y   #xY w# t        $ rE}|| j                   k(  rt        j                         | j                  z  }| j
                  j                  d|t        j                  t        |      |      d   j                                t        j                  |       d {  7   n{| j
                  j                  dt        |      t        j                  t        |      |      d   j                                t        j                  t        |             d {  7   || j                  z  }t        || j                        }Y d }~d }~ww xY ww)Nz0connect failed; reconnecting in %.1f seconds: %sr   z0connect failed again; retrying in %d seconds: %s)BACKOFF_MINBACKOFF_FACTORrU   randomBACKOFF_INITIALr1   info	tracebackformat_exception_onlytypestripr   sleepintminBACKOFF_MAX)r@   backoff_delayprotocolrY   initial_delays        rC   	__aiter__zConnect.__aiter__T  so    ((4+>+>>1 # #8"N# #8 !% 0 0= # # # # #  !D$4$44$*MMOd6J6J$JMKK$$J%!77S	3GJPPR	 "--666KK$$JM*!77S	3GJPPR	 "--M(:;;; -0C0C C #M43C3C D/s   F6A$ AA$ AA$ AA$ F6A$ A$ A!AA!A$ $
F3.BF.DA;F.=F >*F.(F6.F33F6c                "   K   |  d {   S 7 wNr9   r@   s    rC   
__aenter__zConnect.__aenter__x  s     zzs   c                T   K   | j                   j                          d {    y 7 wr   )r   close)r@   exc_type	exc_valuer   s       rC   	__aexit__zConnect.__aexit__{  s      mm!!###s   (&(c                >    | j                         j                         S r   )__await_impl__	__await__r   s    rC   r   zConnect.__await__  s    ""$..00rD   c           	       K   t        | j                        4 d {    t        | j                        D ]  }| j	                          d {   \  }}	 |j                  | j                  |j                  |j                  |j                  |j                         d {    || _        |c cd d d       d {    S  t)        d      7 7 7 07 # t        $ rN}|j                          |j                          d {  7   | j                  |j                          Y d }~d }~wt"        t$        j&                  f$ r+ |j                          |j                          d {  7    w xY w# 1 d {  7  sw Y   y xY ww)N)r2   r>   r?   r5   ztoo many redirects)r   r   rangeMAX_REDIRECTS_ALLOWEDr   r   r   r2   r>   r?   r5   r   r'   fail_connectionwait_closedr   r   rU   r   CancelledErrorr   )r@   
_redirects
_transportr   rY   s        rC   r   zConnect.__await_impl__  sa    "4#4#45 	: 	:#D$>$>? :
-1-D-D-F'F$
H$",,'-5-J-J/7/N/N&.&<&< -   " %-DM#O-	: 	: 	::. $$8991	:'F		: ) 2,,."..000((11!7#9#9: ,,."..000!	: 	: 	:s   FCF,E1CE1AC C!C%
E1/F;C<FE1FE1CF	E.#D'D
 D'"E1'?E.&E)
'E..E11F7E:8F?F)&r   rJ   r   z-Callable[..., WebSocketClientProtocol] | Noner1   r   r   r   r2   r   r3   r   r4   r   r5   r   r6   r   r   float | Noner   r   r   r   r   r   r   
int | Noner   r   r   r   r   r   rA   r   r   r   )r   rJ   r   r   )r   z&AsyncIterator[WebSocketClientProtocol])r   r.   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Noner   r   )r   z-Generator[Any, None, WebSocketClientProtocol])r   r   r   r   r   osenvironr   r   r   r=   r   floatr   r   r   r   r   r   r   r   r   __iter__r9   rD   rC   r   r   M  s   Qf  

/I4 PQ JN$("+ $>B59,0(2%'&(%'&*$ $ '}} G	}
 "}  } } <} 3} *} &} #} $} #} $}  !}" #}$ %}& '}( )}* 
+}~) Z BJJNN+MsSTO

'EuMNK

'EvNOK2::>>*EwOPN 1H$,$ ($ (	$
 
$1:: HrD   r   c                     t        d|| dd|S )a  
    Similar to :func:`connect`, but for connecting to a Unix socket.

    This function builds upon the event loop's
    :meth:`~asyncio.loop.create_unix_connection` method.

    It is 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; the host is used in the TLS
            handshake for secure connections and in the ``Host`` header.

    T)r   rF   r   r9   )r,   )rF   r   rA   s      rC   r-   r-     s    * ;sD;F;;rD   )Nzws://localhost/)rF   r   r   rJ   rA   r   r   r   )D
__future__r   r   r   r:   r   r   r   urllib.parser   r   collections.abcr   r   r   typesr   typingr   r	   r
   asyncio.compatibilityr   datastructuresr   r   
exceptionsr   r   r   r   r   r3   r   r   extensions.permessage_deflater   rN   r   r   r   r   r   r   r   http11r   r   r    r!   r"   r   r#   r$   r&   r'   r   r(   r)   httpr*   r   r+   __all__r.   r   r,   r-   r9   rD   rC   <module>r     s    "    	     > >  & & 3 1  ; L     E E ) < 4  - A[5 [|Y Yx
   <
<	< < 	<rD   