
    2Bf                        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  G d d	e      Zdd
lmZmZmZ ddZddZy# e$ r	 ddlmZ Y +w xY w)    )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y)Frameboolfinzframes.OpcodeopcodebytesdataFrsv1rsv2rsv3c                    t        j                  | j                  | j                  | j                  | j
                  | j                  | j                        S N)r   r   r   r   r   r   r   r   selfs    Y/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/websockets/legacy/framing.py	new_framezFrame.new_frame   s=    ||KKIIHHIIIIII
 	
    c                ,    t        | j                        S r   )strr    r   s    r   __str__zFrame.__str__#   s    4>>""r!   c                6    | j                   j                         S r   )r    checkr   s    r   r&   zFrame.check&   s    ~~##%%r!   N)max_sizer   c                 K    |d       d{   }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        }|dz  rdnd|k7  rt        d      |dz  }|dk(  r) |d       d{   }t        j                  d|      \  }n-|dk(  r( |d       d{   }t        j                  d|      \  }|||kD  rt        d| d| d      |r |d       d{   } ||       d{   }|rt        |      }t        j                  ||||	|
|      }|g }t        |      D ]  }|j                  ||      } |j                           | |j                  |j                  |j                  |j                  |j                   |j"                        S 7 # t        $ r}t        d      |d}~ww xY w7 N7 #7 7 ԭw)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   )clsreadermaskr'   r   r   head1head2r   r   r   r   r   exclength	mask_bitsr    	extensions                     r   readz
Frame.read)   s    6 AY}}UD1u j(dez)tuz)tuz)tu	;]]5:#56F J&DEd: 344#S=?DdD1IVs]?DdD1IVFX$5"3F83xj PQQ$QiI F^#dI.DLLsD$E	J!*- 	GI!((X(FI	G 	MMNNNNNNNN
 	
W   	; 01s:	; # #
 ( $sx   G-GAG-G ),G-G#-G-G&AG-G)G-G+B-G-	G GG  G-&G-)G-+G-)r   c               J     || j                   j                  ||             y)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   writer:   r   s       r   rD   zFrame.writex   s     0 	dnn&&DZ&HIr!   )returnzframes.Frame)rE   r#   )rE   None)
r9   z!Callable[[int], Awaitable[bytes]]r:   r   r'   zOptional[int]r   (Optional[Sequence[extensions.Extension]]rE   r   )rD   zCallable[[bytes], Any]r:   r   r   rG   rE   rF   )__name__
__module____qualname____annotations__r   r   r   propertyr    r$   r&   classmethodrA   rD    r!   r   r   r      s    	I
KD$D$D$
 
#&  #'?CL
1L
 	L

  L
 =L
 
L
 L
f @DJ%J 	J
 =J 
Jr!   r   )Closeprepare_ctrlprepare_datac                \    t        j                  |       }|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.

    )rO   parsecodereason)r   closes     r   parse_closerW      s%     KKE::u||##r!   c                6    t        | |      j                         S )z3
    Serialize the payload for a close frame.

    )rO   rC   )rT   rU   s     r   serialize_closerY      s    
 v((**r!   )r   r   rE   zTuple[int, str])rT   intrU   r#   rE   r   )
__future__r   r2   typingr   r   r   r   r   r	   r
    r   r   
exceptionsr   r   speedupsr   ImportErrorutilsr   rO   rP   encode_datarQ   rW   rY   rN   r!   r   <module>rc      s\    "  R R R ! 5#%
@JJ @JH $ +  #"#s   A A A 