
    vKg                         S r SSKJr  SSKJr  SSKJrJrJrJ	r	  SSK
Jr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  SS	KJr   " S
 S\5      r " S S\5      r\R:                  r\R<                  r " S S5      rg)zU
wsproto/connection
~~~~~~~~~~~~~~~~~~

An implementation of a WebSocket connection.
    )deque)Enum)Deque	GeneratorListOptional   )BytesMessageCloseConnectionEventMessagePingPongTextMessage)	Extension)CloseReasonFrameProtocolOpcodeParseFailed)LocalProtocolErrorc                   0    \ rS rSrSrSrSrSrSrSr	Sr
S	rg
)ConnectionState   z)
RFC 6455, Section 4 - Opening Handshake
r   r	                N)__name__
__module____qualname____firstlineno____doc__
CONNECTINGOPENREMOTE_CLOSINGLOCAL_CLOSINGCLOSED	REJECTING__static_attributes__r       R/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/wsproto/connection.pyr   r      s'    
 JDNMFIr+   r   c                        \ rS rSrSrSrSrSrg)ConnectionType-   z#An enumeration of connection types.r	   r   r   N)r   r    r!   r"   r#   CLIENTSERVERr*   r   r+   r,   r.   r.   -   s    - F Fr+   r.   c            	           \ rS rSrSr  SS\S\\\      S\	SS4S jjr
\S\4S	 j5       rS
\S\	4S jrS\\	   SS4S jrS\\SS4   4S jrSrg)
Connection;   a  
A low-level WebSocket connection object.

This wraps two other protocol objects, an HTTP/1.1 protocol object used
to do the initial HTTP upgrade handshake and a WebSocket frame protocol
object used to exchange messages and other control frames.

:param conn_type: Whether this object is on the client- or server-side of
    a connection. To initialise as a client pass ``CLIENT`` otherwise
    pass ``SERVER``.
:type conn_type: ``ConnectionType``
Nconnection_type
extensionstrailing_datareturnc                     U[         R                  L U l        [        5       U l        [        U R                  U=(       d    / 5      U l        [        R                  U l	        U R                  U5        g N)r.   r0   clientr   _eventsr   _protor   r%   _statereceive_data)selfr5   r6   r7   s       r,   __init__Connection.__init__I   sQ     &)>)>>%*W#DKK1ArB%**-(r+   c                     U R                   $ r:   )r>   )r@   s    r,   stateConnection.stateU   s    {{r+   eventc                     Sn[        U[        5      (       aR  U R                  [        R                  :X  a4  X R
                  R                  UR                  UR                  5      -  nU$ [        U[        5      (       aG  U R                  [        R                  :X  a)  X R
                  R                  UR                  5      -  nU$ [        U[        5      (       aG  U R                  [        R                  :X  a)  X R
                  R                  UR                  5      -  nU$ [        U[        5      (       a  U R                  [        R                  [        R                  1;   a  X R
                  R!                  UR"                  UR$                  5      -  nU R                  [        R                  :X  a  [        R&                  U l        U$ [        R*                  U l         U$ [-        SU SU R                   S35      e)Nr+   zEvent z cannot be sent in state .)
isinstancer   rD   r   r%   r=   	send_datadatamessage_finishedr   pingpayloadr   pongr   r&   closecodereasonr(   r>   r'   r   )r@   rF   rK   s      r,   sendConnection.sendY   s   eW%%$**8L8L*LKK))%**e6L6LMMD$ # t$$7K7K)KKK$$U]]33D   t$$7K7K)KKK$$U]]33D  //DJJ  **C
 5
 KK%%ejj%,,??Dzz_;;;-44  .;;
  %8AF r+   rK   c                 z   UcF  U R                   R                  [        [        R                  S95        [
        R                  U l        gU R                  [
        R                  [
        R                  4;   a  U R                  R                  U5        gU R                  [
        R                  L a  [        S5      eg)a  
Pass some received data to the connection for handling.

A list of events that the remote peer triggered by sending this data can
be retrieved with :meth:`~wsproto.connection.Connection.events`.

:param data: The data received from the remote peer on the network.
:type data: ``bytes``
N)rQ   zConnection already closed.)r<   appendr   r   ABNORMAL_CLOSUREr   r(   r>   rD   r%   r'   r=   receive_bytesr   )r@   rK   s     r,   r?   Connection.receive_datap   s     <
 LL[5Q5Q RS)00DK::/..0M0MNNKK%%d+ZZ?111$%ABBr+   c              #   >  #    U R                   (       a/  U R                   R                  5       v   U R                   (       a  M/   U R                  R                  5        GH  nUR                  [
        R                  L ab  UR                  (       a  UR                  (       d   e[        UR                  [        [        45      (       d   e[        UR                  S9v   M  UR                  [
        R                  L ac  UR                  (       a  UR                  (       d   e[        UR                  [        [        45      (       d   e[        UR                  S9v   GM  UR                  [
        R                   L a  [        UR                  ["        5      (       d   eUR                  u  p#U R$                  [&        R(                  L a  [&        R*                  U l        O[&        R.                  U l        [1        X#S9v   GM  UR                  [
        R2                  L aO  [        UR                  [4        5      (       d   e[7        UR                  UR                  UR                  S9v   GM  UR                  [
        R8                  L aU  [        UR                  [        [        45      (       d   e[;        UR                  UR                  UR                  S9v   GM  GM     g! [<         a)  n[1        UR>                  [5        U5      S9v    SnAgSnAff = f7f)z
Return a generator that provides any events that have been generated
by protocol activity.

:returns: generator of :class:`Event <wsproto.events.Event>` subclasses
)rN   )rQ   rR   )rK   frame_finishedrL   N) r<   popleftr=   received_framesopcoder   PINGr[   rL   rI   rN   bytes	bytearrayr   PONGr   CLOSEtuplerD   r   r'   r(   r>   r&   r   TEXTstrr   BINARYr
   r   rQ   )r@   framerQ   rR   excs        r,   eventsConnection.events   s&     ll,,&&(( lll(	B446<<6;;. //E4J4JJJ%emmeY5GHHHHu}}55\\V[[0 //E4J4JJJ%emmeY5GHHHHu}}55\\V\\1%emmU;;;;#(==LDzz_%B%BB&5&<&<&5&D&D)tCC\\V[[0%emmS9999%"]]',';';).)?)?  \\V]]2%emmeY5GHHHH&"]]',';';).)?)?  K 7L  	B!sxxCAA	Bs0   ?LJ"K' &L'
L1LLLL)r<   r=   r>   r;   )Nr+   )r   r    r!   r"   r#   r.   r   r   r   r`   rA   propertyr   rD   r   rS   r?   r   rj   r*   r   r+   r,   r3   r3   ;   s      15"	
)'
) T)_-
) 	
)
 

)   % E .% T 62B	%t"34 2Br+   r3   N) r#   collectionsr   enumr   typingr   r   r   r   rj   r
   r   r   r   r   r   r   r6   r   frame_protocolr   r   r   r   	utilitiesr   r   r.   r0   r1   r3   r   r+   r,   <module>rr      ss      3 3   " K K )d &T  
					BB BBr+   