o
    /h                     @  s   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 zddlmZ W n eyC   ddlmZ Y nw G dd	 d	eZdd
lmZmZmZ dddZdddZdS )    )annotationsN)Any	AwaitableCallable
NamedTupleOptionalSequenceTuple   )
extensionsframes)PayloadTooBigProtocolError)
apply_maskc                   @  s   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dZd&ddZ	d'ddZ
edddd(ddZdd d)d#d$ZdS )*Frameboolfinzframes.OpcodeopcodebytesdataFrsv1rsv2rsv3returnframes.Framec                 C  s    t | j| j| j| j| j| jS N)r   r   r   r   r   r   r   r   self r   R/var/www/html/govbot/env/lib/python3.10/site-packages/websockets/legacy/framing.py	new_frame   s   zFrame.new_framestrc                 C  s
   t | jS r   )r!   r    r   r   r   r   __str__#      
zFrame.__str__Nonec                 C  s
   | j  S r   )r    checkr   r   r   r   r%   &   r#   zFrame.checkN)max_sizer   reader!Callable[[int], Awaitable[bytes]]maskr&   Optional[int]r   (Optional[Sequence[extensions.Extension]]c             
     s  |dI dH }t d|\}}|d@ rdnd}|d@ rdnd}	|d@ r&dnd}
|d	@ r.dnd}z	t|d
@ }W n tyJ } ztd|d}~ww |d@ rQdnd|krYtd|d@ }|dkrp|dI dH }t d|\}n|dkr|dI dH }t d|\}|dur||krtd| d| d|r|dI dH }||I dH }|rt||}t||||	|
|}|du rg }t	|D ]	}|j
||d}q|  | |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    	extensionr   r   r   read)   sV   

z
Frame.read)r   writeCallable[[bytes], Any]c                C  s   || j j||d 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   rC   r)   r   r   r   r   rC   x   s   zFrame.write)r   r   )r   r!   )r   r$   )
r'   r(   r)   r   r&   r*   r   r+   r   r   )rC   rD   r)   r   r   r+   r   r$   )__name__
__module____qualname____annotations__r   r   r   propertyr    r"   r%   classmethodrB   rC   r   r   r   r   r      s"   
 


Sr   )Closeprepare_ctrlprepare_datar   r   r   Tuple[int, str]c                 C  s   t | }|j|jfS )z
    Parse the payload from a close frame.

    Returns:
        Close code and reason.

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

    )rL   parsecodereason)r   closer   r   r   parse_close   s   
rT   rQ   intrR   r!   c                 C  s   t | | S )z3
    Serialize the payload for a close frame.

    )rL   rE   )rQ   rR   r   r   r   serialize_close   s   rV   )r   r   r   rO   )rQ   rU   rR   r!   r   r   )
__future__r   r5   typingr   r   r   r   r   r   r	    r   r   
exceptionsr   r   speedupsr   ImportErrorutilsr   rL   rM   encode_datarN   rT   rV   r   r   r   r   <module>   s    $ 
