
    vKgg                       S SK J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
JrJrJrJrJr  SSKJr  SSKJrJrJrJrJrJrJrJrJrJr  SS	KJrJr  SS
K J!r!  SSKJ"r"J#r#J$r$  / SQr%\\\\4   r&  " S S\RN                  5      r(\(RR                  r)\(RT                  r* " S S\RN                  5      r+\+RX                  r,\+RZ                  r-\+R\                  r.\+R^                  r/Sr0  " S S5      r1g)    )annotationsN)	Generator)Union   )ConnectionClosedConnectionClosedErrorConnectionClosedOKInvalidStatePayloadTooBigProtocolError)	Extension)
OK_CLOSE_CODES	OP_BINARYOP_CLOSEOP_CONTOP_PINGOP_PONGOP_TEXTClose	CloseCodeFrame)RequestResponse)StreamReader)
LoggerLikeOriginSubprotocol)ProtocolSideStateSEND_EOFc                  .    \ rS rSrSr\" S5      u  rrSrg)r   /   z6A WebSocket connection is either a server or a client.    N)	__name__
__module____qualname____firstlineno____doc__rangeSERVERCLIENT__static_attributes__r%       S/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/websockets/protocol.pyr   r   /   s    @1XNFFr/   r   c                  2    \ rS rSrSr\" S5      u  rrrr	Sr
g)r    9   z6A WebSocket connection is in one of these four states.   r%   N)r&   r'   r(   r)   r*   r+   
CONNECTINGOPENCLOSINGCLOSEDr.   r%   r/   r0   r    r    9   s    @(-a%Jgvr/   r    r/   c                  r   \ rS rSrSr\SSS.         SS jjr\SS j5       r\R                  S S j5       r\S!S	 j5       r
\S"S
 j5       r\S#S j5       rS$S jrS%S jrS&S jrS'S&S jjrS'S&S jjrS(S)S jjrS$S jrS$S j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S0S jrS0S jrS%S jrSrg)1r   I   a
  
Sans-I/O implementation of a WebSocket connection.

Args:
    side: :attr:`~Side.CLIENT` or :attr:`~Side.SERVER`.
    state: Initial state of the WebSocket connection.
    max_size: Maximum size of incoming messages in bytes;
        :obj:`None` disables the limit.
    logger: Logger for this connection; depending on ``side``,
        defaults to ``logging.getLogger("websockets.client")``
        or ``logging.getLogger("websockets.server")``;
        see the :doc:`logging guide <../../topics/logging>` for details.

i   N)statemax_sizeloggerc               F   [         R                  " 5       U l         Uc1  [        R                  " SUR
                  R                  5        35      nX@l         UR                  [        R                  5      U l
        Xl        X l        X0l        S U l        SU l        S U l        / U l        S U l        S U l        S U l        S U l        S U l         SU l        [1        5       U l        / U l        / U l        U R9                  5       U l        [=        U R:                  5        S U l        g )Nzwebsockets.F) uuiduuid4idlogging	getLoggernamelowerr<   isEnabledForDEBUGdebugsider:   r;   cur_sizeexpect_continuation_frameorigin
extensionssubprotocol
close_rcvd
close_sentclose_rcvd_then_senthandshake_exceof_sentr   readereventswritesparseparsernext
parser_exc)selfrH   r:   r;   r<   s        r0   __init__Protocol.__init__Y   s    "ZZ\B >&&TYY__5F4G'HIF"() ((7
 	 
 ! %) */& &*+-/3 )-(,15! 04	  #n#%#%jjlT[[,0r/   c                    U R                   $ )au  
State of the WebSocket connection.

Defined in 4.1_, 4.2_, 7.1.3_, and 7.1.4_ of :rfc:`6455`.

.. _4.1: https://datatracker.ietf.org/doc/html/rfc6455#section-4.1
.. _4.2: https://datatracker.ietf.org/doc/html/rfc6455#section-4.2
.. _7.1.3: https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.3
.. _7.1.4: https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.4

)_staterZ   s    r0   r:   Protocol.state   s     {{r/   c                ~    U R                   (       a&  U R                  R                  SUR                  5        Xl        g )Nz= connection is %s)rG   r<   rC   r^   )rZ   r:   s     r0   r:   r`      s'    ::KK2EJJ?r/   c                    U R                   [        La  gU R                  c  [        R                  $ U R                  R
                  $ )z
WebSocket close code received from the remote endpoint.

Defined in 7.1.5_ of :rfc:`6455`.

.. _7.1.5: https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.5

:obj:`None` if the connection isn't closed yet.

N)r:   r7   rN   r   ABNORMAL_CLOSUREcoder_   s    r0   
close_codeProtocol.close_code   s9     ::V#__$---??'''r/   c                r    U R                   [        La  gU R                  c  gU R                  R                  $ )z
WebSocket close reason  received from the remote endpoint.

Defined in 7.1.6_ of :rfc:`6455`.

.. _7.1.6: https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.6

:obj:`None` if the connection isn't closed yet.

N )r:   r7   rN   reasonr_   s    r0   close_reasonProtocol.close_reason   s0     ::V#__$??)))r/   c                r   U R                   [        L d   S5       eU R                  bP  U R                  bC  U R                  R                  [
        ;   a%  U R                  R                  [
        ;   a  [        nO[        nU" U R                  U R                  U R                  5      nU R                  Ul
        U$ )a  
Exception to raise when trying to interact with a closed connection.

Don't raise this exception while the connection :attr:`state`
is :attr:`~websockets.protocol.State.CLOSING`; wait until
it's :attr:`~websockets.protocol.State.CLOSED`.

Indeed, the exception includes the close code and reason, which are
known only once the connection is closed.

Raises:
    AssertionError: If the connection isn't closed yet.

zconnection isn't closed yet)r:   r7   rN   rO   rd   r   r	   r   rP   rY   	__cause__)rZ   exc_typeexcs      r0   	close_excProtocol.close_exc   s      zzV#B%BB# OO'+$$6$$6)H,H (OOOO%%!
 
r/   c                d    U R                   R                  U5        [        U R                  5        g)a  
Receive data from the network.

After calling this method:

- You must call :meth:`data_to_send` and send this data to the network.
- You should call :meth:`events_received` and process resulting events.

Raises:
    EOFError: If :meth:`receive_eof` was called earlier.

N)rS   	feed_datarX   rW   rZ   datas     r0   receive_dataProtocol.receive_data   s"     	d#T[[r/   c                    U R                   R                  (       a  gU R                   R                  5         [        U R                  5        g)aa  
Receive the end of the data stream from the network.

After calling this method:

- You must call :meth:`data_to_send` and send this data to the network;
  it will return ``[b""]``, signaling the end of the stream, or ``[]``.
- You aren't expected to call :meth:`events_received`; it won't return
  any new events.

:meth:`receive_eof` is idempotent.

N)rS   eoffeed_eofrX   rW   r_   s    r0   receive_eofProtocol.receive_eof  s.     ;;??T[[r/   c                   U R                   (       d  [        S5      eU R                  [        La0  [	        SU R
                  R                  R                  5        35      eU(       + U l         U R                  [        [        X5      5        g)a  
Send a `Continuation frame`_.

.. _Continuation frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.6

Parameters:
    data: payload containing the same kind of data
        as the initial frame.
    fin: FIN bit; set it to :obj:`True` if this is the last frame
        of a fragmented message and to :obj:`False` otherwise.

Raises:
    ProtocolError: If a fragmented message isn't in progress.

unexpected continuation frameconnection is N)rJ   r   r^   r5   r
   r:   rC   rD   
send_framer   r   rZ   ru   fins      r0   send_continuationProtocol.send_continuation#  sf    " -- ?@@;;d"

0E0E0G/HIJJ-0&gt12r/   c                   U R                   (       a  [        S5      eU R                  [        La0  [	        SU R
                  R                  R                  5        35      eU(       + U l         U R                  [        [        X5      5        g)aS  
Send a `Text frame`_.

.. _Text frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.6

Parameters:
    data: payload containing text encoded with UTF-8.
    fin: FIN bit; set it to :obj:`False` if this is the first frame of
        a fragmented message.

Raises:
    ProtocolError: If a fragmented message is in progress.

expected a continuation framer   N)rJ   r   r^   r5   r
   r:   rC   rD   r   r   r   r   s      r0   	send_textProtocol.send_text;  sf      )) ?@@;;d"

0E0E0G/HIJJ-0&gt12r/   c                   U R                   (       a  [        S5      eU R                  [        La0  [	        SU R
                  R                  R                  5        35      eU(       + U l         U R                  [        [        X5      5        g)aU  
Send a `Binary frame`_.

.. _Binary frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.6

Parameters:
    data: payload containing arbitrary binary data.
    fin: FIN bit; set it to :obj:`False` if this is the first frame of
        a fragmented message.

Raises:
    ProtocolError: If a fragmented message is in progress.

r   r   N)rJ   r   r^   r5   r
   r:   rC   rD   r   r   r   r   s      r0   send_binaryProtocol.send_binaryR  sf      )) ?@@;;d"

0E0E0G/HIJJ-0&i34r/   c                   U R                   [        La0  [        SU R                  R                  R                  5        35      eUc.  US:w  a  [        S5      e[        [        R                  S5      nSnO[        X5      nUR                  5       nU R                  [        [        U5      5        U R                  b   eX0l        [         U l        g)a  
Send a `Close frame`_.

.. _Close frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.1

Parameters:
    code: close code.
    reason: close reason.

Raises:
    ProtocolError: If the code isn't valid or if a reason is provided
        without a code.

r   Nrh   z#cannot send a reason without a coder/   )r^   r5   r
   r:   rC   rD   r   r   r   NO_STATUS_RCVD	serializer   r   r   rN   rO   r6   rZ   rd   ri   closeru   s        r0   
send_closeProtocol.send_closei  s    $ ;;d"

0E0E0G/HIJJ<|#$IJJ)22B7ED$'E??$Dh-. &&&
r/   c                    U R                   [        LaC  U R                   [        La0  [        SU R                  R
                  R                  5        35      eU R                  [        [        U5      5        g)z
Send a `Ping frame`_.

.. _Ping frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.2

Parameters:
    data: payload containing arbitrary binary data.

r   N)
r^   r5   r6   r
   r:   rC   rD   r   r   r   rt   s     r0   	send_pingProtocol.send_ping  R     ;;d"t{{''A

0E0E0G/HIJJgt,-r/   c                    U R                   [        LaC  U R                   [        La0  [        SU R                  R
                  R                  5        35      eU R                  [        [        U5      5        g)z
Send a `Pong frame`_.

.. _Pong frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.3

Parameters:
    data: payload containing arbitrary binary data.

r   N)
r^   r5   r6   r
   r:   rC   rD   r   r   r   rt   s     r0   	send_pongProtocol.send_pong  r   r/   c                   U R                   [        L as  U[        R                  :w  a_  [	        X5      nUR                  5       nU R                  [        [        U5      5        X0l	        U R                  b  SU l        [        U l         U R                  [        L a!  U R                  (       d  U R!                  5         U R#                  5       U l        ['        U R$                  5        g)z
`Fail the WebSocket connection`_.

.. _Fail the WebSocket connection:
    https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.7

Parameters:
    code: close code
    reason: close reason

Raises:
    ProtocolError: If the code isn't valid.
NT)r:   r5   r   rc   r   r   r   r   r   rO   rN   rP   r6   rH   r,   rR   send_eofdiscardrW   rX   r   s        r0   failProtocol.fail  s    & ::y111d+(h 56"'
 ??.04D-$
 99t}}MMO llnT[[r/   c                ,    U R                   / sol         U$ )z
Fetch events generated from data received from the network.

Call this method immediately after any of the ``receive_*()`` methods.

Process resulting events, likely by passing them to the application.

Returns:
    Events read from the connection.
)rT   )rZ   rT   s     r0   events_receivedProtocol.events_received  s     #kk2r/   c                ,    U R                   / sol         U$ )ay  
Obtain data to send to the network.

Call this method immediately after any of the ``receive_*()``,
``send_*()``, or :meth:`fail` methods.

Write resulting data to the connection.

The empty bytestring :data:`~websockets.protocol.SEND_EOF` signals
the end of the data stream. When you receive it, half-close the TCP
connection.

Returns:
    Data to write to the connection.

)rU   )rZ   rU   s     r0   data_to_sendProtocol.data_to_send  s    " #kk2r/   c                    U R                   [        L a  gU R                   [        L a  gU R                   [        L a  gU R                   [        L d   eU R
                  $ )ai  
Tell if the TCP connection is expected to close soon.

Call this method immediately after any of the ``receive_*()``,
``send_close()``, or :meth:`fail` methods.

If it returns :obj:`True`, schedule closing the TCP connection after a
short timeout if the other side hasn't already closed it.

Returns:
    Whether the TCP connection is expected to close soon.

FT)r:   r5   r6   r7   r4   rR   r_   s    r0   close_expectedProtocol.close_expected  sN    D :::: ::zzZ'''}}r/   c              #    #      U R                   R                  5        Sh  vN (       a7  U R                  (       a  U R                  R                  S5        [	        S5      eU R
                  c  SnO3U R                  c  U R
                  nOU R
                  U R                  -
  n[        R                  " U R                   R                  U R                  [        L UU R                  S9 Sh  vN nU R                  (       a  U R                  R                  SU5        U R                  U5        GM/   GN NH! [         a:  nU R                  [         R"                  [%        U5      5        X0l         SnAGOHSnAf[         a:  nU R                  [         R(                  [%        U5      5        X0l         SnAGOSnAf[*         aI  nU R                  [         R,                  UR.                   SUR0                   35        X0l         SnAOSnAf[2         aT  nUR5                  U R                  5        U R                  [         R6                  [%        U5      5        X0l         SnAOYSnAf[8         aI  nU R                  R;                  SSS	9  U R                  [         R<                  5        X0l         SnAOSnAff = fSv   [?        S
5      e7f)z
Parse incoming data into frames.

:meth:`receive_data` and :meth:`receive_eof` run this generator
coroutine until it needs more data or reaches EOF.

:meth:`parse` never raises an exception. Instead, it sets the
:attr:`parser_exc` and yields control.

TN< EOFzunexpected end of stream)maskr;   rL   z< %sz at position zparser failed)exc_infoz"parse() shouldn't step after error) rS   at_eofrG   r<   EOFErrorr;   rI   r   rV   
read_exactrH   r,   rL   
recv_framer   r   r   PROTOCOL_ERRORstrrY   rc   UnicodeDecodeErrorINVALID_DATAri   startr   set_current_sizeMESSAGE_TOO_BIG	ExceptionerrorINTERNAL_ERRORAssertionError)rZ   r;   framero   s       r0   rV   Protocol.parse/  s     6	"#{{11333zz))'2
 ##=>>==(#H]]*#}}H#}}t}}<H
 $);;KK**f,%#	$  ::KK%%fe4&= 3&  	"IIi..C9!OO 	"IIi00#c(;!OO! 	"IIi,,M#)).UV!OO 	"  /IIi//S:!OO 	"KKo=IIi../!OO		" 	ABBs   KD9 D4CD9 .D7/AD9 7D9 9
J=/E82K8J=/F:4K:J=?HKJ=A
I'"K'J=4?J83K8J==Kc              #  T  #    U R                   [        L =(       d    U R                  [        L U R                  :X  d   eU R
                  R                  5        Sh  vN (       dC  U R
                  R                  5         U R
                  R                  5        Sh  vN (       d  MC  U R                  (       a  U R                  R                  S5        U R                   [        L a#  U R                  [        La  U R                  5         [        U l        Sv   [        S5      e N N7f)z
Discard incoming data.

This coroutine replaces :meth:`parse`:

- after receiving a close frame, during a normal closure (1.4);
- after sending a close frame, during an abnormal closure (7.1.7).

Nr   z"discard() shouldn't step after EOF)rH   r,   r:   r4   rR   rS   r   r   rG   r<   r-   r   r7   r   r_   s    r0   r   Protocol.discardw  s      		V#?tzzZ'?T]]SSS"kk00222KK! #kk00222::KKg& 994::Z#?MMO
 ABB 3s,   AD(D$A D(D&	D((A=D(&D(c                   UR                   [        L d  UR                   [        L aE  U R                  b  [	        S5      eUR
                  (       d  [        UR                  5      U l        GOUR                   [        L a\  U R                  c  [	        S5      eUR
                  (       a	  SU l        GOU =R                  [        UR                  5      -  sl        GOUR                   [        L a-  [        [        UR                  5      nU R                  U5        GOUUR                   [        L a  GO@UR                   [        L Ga  [        R                  " UR                  5      U l        U R"                  [$        L a  U R&                  c   eSU l        U R                  b  [	        S5      eU R"                  [*        L aL  U R                  [        [        UR                  5      5        U R                   U l        SU l        [$        U l        U R,                  [.        L a  U R1                  5         U R3                  5       U l        [7        U R4                  5        O[9        SUR                   S 35      eU R:                  R=                  U5        g)	z
Process an incoming frame.

Nr   r~   Fzincomplete fragmented messageTzunexpected opcode: 02x)opcoder   r   rI   r   r   lenru   r   r   r   r   r   r   r   rV   rN   r:   r6   rO   rP   r5   rH   r,   r   r   rW   rX   r   rT   append)rZ   r   
pong_frames      r0   r   Protocol.recv_frame  s   
 <<7"elli&?}}(#$CDD99 #EJJ\\W$}}$#$CDDyy $UZZ0\\W$ w

3JOOJ'\\W$ \\X% $kk%**5DOzzW$222,1)}}(#$CDD zzT!
 h

 ;<"&//,0)$
 yyF" ,,.DK !#6u||C6H!IJJ5!r/   c                    U R                   (       a  U R                  R                  SU5        U R                  R                  UR	                  U R
                  [        L U R                  S95        g )Nz> %s)r   rL   )rG   r<   rU   r   r   rH   r-   rL   )rZ   r   s     r0   r   Protocol.send_frame  sS    ::KKfe,OOYY&(??  	
r/   c                    U R                   (       a   eSU l         U R                  (       a  U R                  R                  S5        U R                  R	                  [
        5        g )NTz> EOF)rR   rG   r<   rU   r   r!   r_   s    r0   r   Protocol.send_eof  sA    ==  ::KKg&8$r/   )r^   rN   rP   rO   rI   rG   rR   rT   rJ   rL   rQ   r@   r<   r;   rK   rW   rY   rS   rH   r:   rM   rU   )
rH   r   r:   r    r;   
int | Noner<   zLoggerLike | NonereturnNone)r   r    )r:   r    r   r   )r   r   )r   z
str | None)r   r   )ru   bytesr   r   )r   r   )ru   r   r   boolr   r   )T)Nrh   )rd   r   ri   r   r   r   )rh   )rd   intri   r   r   r   )r   zlist[Event])r   zlist[bytes])r   r   )r   zGenerator[None])r   r   r   r   )r&   r'   r(   r)   r*   r5   r[   propertyr:   setterre   rj   rp   rv   r{   r   r   r   r   r   r   r   r   r   r   rV   r   r   r   r   r.   r%   r/   r0   r   r   I   s   & $$(B1B1 	B1
 B1 "B1 
B1H   \\ 
 ( ($ * *$ ! !J *303.5."H. . -b ()ZFCPC<N"d
%r/   r   )2
__future__r   enumrA   r>   collections.abcr   typingr   
exceptionsr   r   r	   r
   r   r   rL   r   framesr   r   r   r   r   r   r   r   r   r   http11r   r   streamsr   r   r   r   __all__EventIntEnumr   r,   r-   r    r4   r5   r6   r7   r!   r   r%   r/   r0   <module>r      s    "    %   "   & ! 3 3 	gx&' ?4<<  
	1DLL 1 
zz
--	  Em
% m
%r/   