
     f                         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dS )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	dS )	ConnectionStatez1
    RFC 6455, Section 4 - Opening Handshake
    r   r	               N)
__name__
__module____qualname____doc__
CONNECTINGOPENREMOTE_CLOSINGLOCAL_CLOSINGCLOSED	REJECTING     U/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/wsproto/connection.pyr   r      s8         
 JDNMFIIIr(   r   c                       e Zd ZdZdZdZdS )ConnectionTypez#An enumeration of connection types.r	   r   N)r   r   r   r    CLIENTSERVERr'   r(   r)   r+   r+   -   s"        -- F FFFr(   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dS )
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``
    Nr(   connection_type
extensionstrailing_datareturnc                     |t           j        u | _        t                      | _        t          | j        |pg           | _        t          j        | _	        | 
                    |           d S N)r+   r,   clientr   _eventsr   _protor   r"   _statereceive_data)selfr0   r1   r2   s       r)   __init__zConnection.__init__I   sZ     &)>>%*WW#DK1ArBB%*-(((((r(   c                     | j         S r5   )r9   )r;   s    r)   statezConnection.stateU   s
    {r(   eventc                 F   d}t          |t                    r?| j        t          j        k    r*|| j                            |j        |j                  z  }nJt          |t                    r8| j        t          j        k    r#|| j        
                    |j                  z  }nt          |t                    r8| j        t          j        k    r#|| j                            |j                  z  }nt          |t                    r| j        t          j        t          j        hv ra|| j                            |j        |j                  z  }| j        t          j        k    rt          j        | _        n-t          j        | _        nt-          d| d| j         d          |S )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   sv   eW%% 	$*8L*L*LDK))%*e6LMMMDDt$$ 	7K)K)KDK$$U]333DDt$$ 	7K)K)KDK$$U]333DD// 	DJ *C
 5
 5
 DK%%ej%,???Dz_;;;-4-;$FFFFFF   r(   rD   c                 N   |E| j                             t          t          j                             t
          j        | _        dS | j        t
          j	        t
          j
        fv r| j                            |           dS | j        t
          j        u rt          d          dS )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     <
 L[5Q R R RSSS)0DKF:/.0MNNNK%%d+++++Z?111$%ABBBDr(   c              #     K   | j         r"| j                                         V  | j         "	 | j                                        D ]}|j        t
          j        u rK|j        r|j        sJ t          |j
        t          t          f          sJ t          |j
                  V  a|j        t
          j        u rK|j        r|j        sJ t          |j
        t          t          f          sJ t          |j
                  V  |j        t
          j        u rqt          |j
        t"                    sJ |j
        \  }}| j        t&          j        u rt&          j        | _        nt&          j        | _        t1          ||          V  C|j        t
          j        u rAt          |j
        t4                    sJ t7          |j
        |j        |j                  V  |j        t
          j        u rHt          |j
        t          t          f          sJ t;          |j
        |j        |j                  V  dS # t<          $ r0}t1          |j        t5          |                    V  Y d}~dS d}~ww xY 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      l 	),&&((((( l 	)(	B4466 % %<6;.. /JE4JJJJ%emeY5GHHHHHu}5555555\V[00 /JE4JJJJ%emeY5GHHHHHu}5555555\V\11%emU;;;;;#(=LD&z_%BBB&5&<&5&D)tFCCCCCCC\V[00%emS99999%"]',';).)?       \V]22%emeY5GHHHHH&"]',';).)?       K% %L  	B 	B 	B!sxCAAAAAAAAAAAA	Bs   HH< <
I6%I11I6)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)_-
) 	
)
 

) 
) 
) 
)     X% E    .% T    62B	%t"34 2B 2B 2B 2B 2B 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      s                3 3 3 3 3 3 3 3 3 3 3 3                  " ! ! ! ! ! K K K K K K K K K K K K ) ) ) ) ) )    d   &    T    
			BB BB BB BB BB BB BB BB BB BBr(   