
    ,h                         d Z ddlmZ ddlmZ ddlmZmZmZ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mZmZmZ dd	lmZ  G d
 de      Z G d de      Zej:                  Zej<                  Z G d d      Zy)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                   (    e Zd ZdZdZdZdZdZdZdZ	y)	ConnectionStatez1
    RFC 6455, Section 4 - Opening Handshake
    r   r	               N)
__name__
__module____qualname____doc__
CONNECTINGOPENREMOTE_CLOSINGLOCAL_CLOSINGCLOSED	REJECTING     T/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/wsproto/connection.pyr   r      s'    
 JDNMFIr(   r   c                       e Zd ZdZdZdZy)ConnectionTypez#An enumeration of connection types.r	   r   N)r   r   r   r    CLIENTSERVERr'   r(   r)   r+   r+   -   s    - F Fr(   r+   c            	           e Zd ZdZ	 	 ddedeee      deddfdZ	e
defd       Zd	edefd
Zdee   ddfdZdeeddf   fdZy)
Connectiona  
    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                     |t         j                  u | _        t               | _        t        | j                  |xs g       | _        t        j                  | _	        | j                  |       y N)r+   r,   clientr   _eventsr   _protor   r"   _statereceive_data)selfr0   r1   r2   s       r)   __init__zConnection.__init__I   sQ     &)>)>>%*W#DKK1ArB%**-(r(   c                     | j                   S r5   )r9   )r;   s    r)   statezConnection.stateU   s    {{r(   eventc                    d}t        |t              rR| j                  t        j                  k(  r5|| j
                  j                  |j                  |j                        z  }|S t        |t              rG| j                  t        j                  k(  r*|| j
                  j                  |j                        z  }|S t        |t              rG| j                  t        j                  k(  r*|| j
                  j                  |j                        z  }|S t        |t              r| j                  t        j                  t        j                  hv r~|| j
                  j!                  |j"                  |j$                        z  }| j                  t        j                  k(  rt        j&                  | _        |S t        j*                  | _        |S t-        d| d| j                   d      )Nr(   zEvent z cannot be sent in state .)
isinstancer   r>   r   r"   r8   	send_datadatamessage_finishedr   pingpayloadr   pongr   r#   closecodereasonr%   r9   r$   r   )r;   r?   rD   s      r)   sendzConnection.sendY   s   eW%$**8L8L*LDKK))%**e6L6LMMD$ # t$7K7K)KDKK$$U]]33D   t$7K7K)KDKK$$U]]33D  /DJJ  **C
 5
 DKK%%ejj%,,??Dzz_;;;-44  .;;
  %8AF r(   rD   c                 x   |I| j                   j                  t        t        j                               t
        j                  | _        y| j                  t
        j                  t
        j                  fv r| j                  j                  |       y| j                  t
        j                  u rt        d      y)aO  
        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)rJ   zConnection already closed.)r7   appendr   r   ABNORMAL_CLOSUREr   r%   r9   r>   r"   r$   r8   receive_bytesr   )r;   rD   s     r)   r:   zConnection.receive_datap   s     <
 LL[5Q5Q RS)00DK::/..0M0MNNKK%%d+ZZ?111$%ABBr(   c              #     K   | j                   r)| j                   j                          | j                   r)	 | j                  j                         D ]Z  }|j                  t
        j                  u rU|j                  r|j                  sJ t        |j                  t        t        f      sJ t        |j                         u|j                  t
        j                  u rU|j                  r|j                  sJ t        |j                  t        t        f      sJ t        |j                         |j                  t
        j                   u rt        |j                  t"              sJ |j                  \  }}| j$                  t&        j(                  u rt&        j*                  | _        nt&        j.                  | _        t1        ||       |j                  t
        j2                  u rLt        |j                  t4              sJ t7        |j                  |j                  |j                         |j                  t
        j8                  u rRt        |j                  t        t        f      sJ t;        |j                  |j                  |j                         [] y# t<        $ r,}t1        |j>                  t5        |             Y d}~yd}~ww xY ww)z
        Return a generator that provides any events that have been generated
        by protocol activity.

        :returns: generator of :class:`Event <wsproto.events.Event>` subclasses
        )rG   )rJ   rK   )rD   frame_finishedrE   N) r7   popleftr8   received_framesopcoder   PINGrR   rE   rB   rG   bytes	bytearrayr   PONGr   CLOSEtupler>   r   r$   r%   r9   r#   r   TEXTstrr   BINARYr
   r   rJ   )r;   framerJ   rK   excs        r)   eventszConnection.events   s
     ll,,&&(( ll(	B446 %<<6;;. //E4J4JJ%emmeY5GHHu}}55\\V[[0 //E4J4JJ%emmeY5GHHu}}55\\V\\1%emmU;;#(==LD&zz_%B%BB&5&<&<&5&D&D)tFCC\\V[[0%emmS99%"]]',';';).)?)?  \\V]]2%emmeY5GHH&"]]',';';).)?)?  K%L  	B!sxxCAA	Bs/   5K*I8J2 1K*2	K';"K"K*"K''K*)Nr(   )r   r   r   r    r+   r   r   r   rW   r<   propertyr   r>   r   rL   r:   r   ra   r'   r(   r)   r/   r/   ;   s      15"	
)'
) T)_-
) 	
)
 

)   % E .% T 62B	%t"34 2Br(   r/   N) r    collectionsr   enumr   typingr   r   r   r   ra   r
   r   r   r   r   r   r   r1   r   frame_protocolr   r   r   r   	utilitiesr   r   r+   r,   r-   r/   r'   r(   r)   <module>rh      ss      3 3   " K K )d &T  
					BB BBr(   