
    &th                        d dl mZ d dlZd dlmZmZmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZmZ 	 ddlmZ n# e$ r	 ddlmZ Y nw xY w G d d	e          Zdd
lmZmZmZ ddZddZdS )    )annotationsN)Any	AwaitableCallable
NamedTupleOptionalSequenceTuple   )
extensionsframes)PayloadTooBigProtocolError)
apply_maskc                      e Zd ZU ded<   ded<   ded<   dZded<   dZded	<   dZded
<   ed d            Zd!dZ	d"dZ
edddd#d            Zddd$dZdS )%Frameboolfinzframes.OpcodeopcodebytesdataFrsv1rsv2rsv3returnframes.Framec                p    t          j        | j        | j        | j        | j        | j        | j                  S N)r   r   r   r   r   r   r   r   selfs    m/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/websockets/legacy/framing.py	new_framezFrame.new_frame   s4    |KIHIII
 
 	
    strc                *    t          | j                  S r   )r$   r"   r   s    r!   __str__zFrame.__str__$   s    4>"""r#   Nonec                4    | j                                         S r   )r"   checkr   s    r!   r)   zFrame.check'   s    ~##%%%r#   N)max_sizer   reader!Callable[[int], Awaitable[bytes]]maskr*   Optional[int]r   (Optional[Sequence[extensions.Extension]]c                 K    |d           d{V }t          j        d|          \  }}|dz  rdnd}|dz  rdnd}	|dz  rdnd}
|d	z  rdnd}	 t          j        |d
z            }n"# t          $ r}t          d          |d}~ww xY w|dz  rdnd|k    rt          d          |dz  }|dk    r) |d           d{V }t          j        d|          \  }n.|dk    r( |d           d{V }t          j        d|          \  }|||k    rt          d| d| d          |r |d           d{V } ||           d{V }|rt          ||          }t          j        ||||	|
|          }|g }t          |          D ]}|
                    ||          }|                                  | |j        |j        |j        |j        |j        |j                  S )a@  
        Read a WebSocket frame.

        Args:
            reader: coroutine that reads exactly the requested number of
                bytes, unless the end of file is reached.
            mask: whether the frame should be masked i.e. whether the read
                happens on the server side.
            max_size: maximum payload size in bytes.
            extensions: list of extensions, applied in reverse order.

        Raises:
            PayloadTooBig: if the frame exceeds ``max_size``.
            ProtocolError: if the frame contains incorrect values.

        r   Nz!BB   TF@             zinvalid opcodezincorrect masking   ~   z!H   z!Qzover size limit (z > z bytes)   )r*   )structunpackr   Opcode
ValueErrorr   r   r   r   reverseddecoder)   r   r   r   r   r   r   )clsr+   r-   r*   r   r   head1head2r   r   r   r   r   exclength	mask_bitsr"   	extensions                     r!   readz
Frame.read*   s     6 VAYY}UD11u j(3ddez)4ttuz)4ttuz)4ttu	;]5:#566FF 	; 	; 	; 011s:	; J&1DDEd:: 3444#S==??????DdD11IVVs]]??????DdD11IVFX$5$5 PF P Px P P PQQQ 	($fQiiI VF^^###### 	/dI..DLsD$EE	J!*-- 	G 	GI!((X(FFIIsMNNNN
 
 	
s   A) )
B3BB)r   writeCallable[[bytes], Any]c               P     || j                             ||                     dS )a  
        Write a WebSocket frame.

        Args:
            frame: frame to write.
            write: function that writes bytes.
            mask: whether the frame should be masked i.e. whether the write
                happens on the client side.
            extensions: list of extensions, applied in order.

        Raises:
            ProtocolError: if the frame contains incorrect values.

        )r-   r   N)r"   	serialize)r    rH   r-   r   s       r!   rH   zFrame.writey   s/    0 	dn&&DZ&HHIIIIIr#   )r   r   )r   r$   )r   r'   )
r+   r,   r-   r   r*   r.   r   r/   r   r   )rH   rI   r-   r   r   r/   r   r'   )__name__
__module____qualname____annotations__r   r   r   propertyr"   r&   r)   classmethodrG   rH    r#   r!   r   r      s        IIIKKKDDD
 
 
 X
# # # #& & & &  #'?CL
 L
 L
 L
 L
 [L
f @DJ J J J J J J Jr#   r   )Closeprepare_ctrlprepare_datar   r   r   Tuple[int, str]c                F    t          j        |           }|j        |j        fS )z
    Parse the payload from a close frame.

    Returns:
        Tuple[int, str]: close code and reason.

    Raises:
        ProtocolError: if data is ill-formed.
        UnicodeDecodeError: if the reason isn't valid UTF-8.

    )rS   parsecodereason)r   closes     r!   parse_closer\      s"     KE:u|##r#   rY   intrZ   r$   c                F    t          | |                                          S )z3
    Serialize the payload for a close frame.

    )rS   rK   )rY   rZ   s     r!   serialize_closer_      s     
 v((***r#   )r   r   r   rV   )rY   r]   rZ   r$   r   r   )
__future__r   r:   typingr   r   r   r   r   r	   r
    r   r   
exceptionsr   r   speedupsr   ImportErrorutilsr   rS   rT   encode_datarU   r\   r_   rR   r#   r!   <module>rh      sa   " " " " " "  R R R R R R R R R R R R R R R R R R ! ! ! ! ! ! ! ! 5 5 5 5 5 5 5 5#%%%%%%% # # #""""""""#AJ AJ AJ AJ AJJ AJ AJ AJL F E E E E E E E E E$ $ $ $ + + + + + +s   5 AA