
    h                         U d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ d	d
lmZmZmZmZmZmZmZmZ d	dlmZmZ dZee         ed<   dZ  G d d          Z!dS )z%WebSocket protocol versions 13 and 8.    N)partial)AnyFinalOptionalUnion   )BaseProtocol)ClientConnectionResetError)ZLibCompressor   )MASK_LENMSG_SIZEPACK_CLOSE_CODE	PACK_LEN1	PACK_LEN2	PACK_LEN3PACK_RANDBITSwebsocket_mask)WS_DEFLATE_TRAILING	WSMsgType   DEFAULT_LIMITi   c                       e Zd ZdZde ej                    ddddedej	        de
ded	ej        d
ede
ddfdZ	 ddeded
ee         ddfdZd
edefdZddedeeef         ddfdZdS )WebSocketWritera3  WebSocket writer.

    The writer is responsible for sending messages to the client. It is
    created by the protocol when a connection is established. The writer
    should avoid implementing any application logic and should only be
    concerned with the low-level details of the WebSocket protocol.
    Fr   )use_masklimitrandomcompress
notakeoverprotocol	transportr   r   r   r   r   returnNc                    || _         || _        || _        t          |j        d          | _        || _        || _        d| _        || _	        d| _
        d| _        dS )zInitialize a WebSocket writer.    Fr   N)r    r!   r   r   getrandbitsget_random_bitsr   r   _closing_limit_output_size_compressobj)selfr    r!   r   r   r   r   r   s           [/var/www/html/prod/cognitive/venv/lib/python3.11/site-packages/aiohttp/_websocket/writer.py__init__zWebSocketWriter.__init__-   s`     !" &v'92>> $!%    messageopcodec                 b  K   | j         r|t          j        z  st          d          d}|s| j        r|dk     rd}|r|                     |          }n-| j        s|                     | j                  | _        | j        }|                    |           d{V |                    | j        rt          j
        nt          j                  z                       t                    }t          |          }| j        }|rdnd}d|z  |z  }	|dk     rt!          |	||z            }
d}n3|d	k     rt#          |	d|z  |          }
d
}nt%          |	d|z  |          }
d}| j                                        rt          d          |rvt+          |                                           }t/          |          }t1          ||           | j                            |
|z   |z              | xj        t6          z  c_        n]|t8          k    r5| j                            |
           | j                            |           n| j                            |
|z              | xj        ||z   z  c_        | j        | j        k    r4d| _        | j        j        r#| j                                          d{V  dS dS dS )z<Send a frame over the websocket with message as its payload.z!Cannot write to closing transportr      @   N   ~   r   r         
   )!r'   r   CLOSEr
   r   _make_compress_objr*   flushr   zlibZ_FULL_FLUSHZ_SYNC_FLUSHremovesuffixr   lenr   r   r   r   r!   
is_closingr   r&   	bytearrayr   writer)   r   r   r(   r    _paused_drain_helper)r+   r/   r0   r   rsvcompressobj
msg_lengthr   mask_bit
first_byteheader
header_lenmasks                r,   
send_framezWebSocketWriter.send_frameD   s      = 	R&9?": 	R,-PQQQ
   	0 	06A:: C 0"55h??( O(,(?(?(N(ND%"/ "**733333333##)-OD%%d>O  l.//  \\
=#*44 CZ&(
z:+@AAFJJ%z3>:FFFJJz3>:FFFJ>$$&& 	R,-PQQQ  
	3 !5!5!7!788D((G4)))N  $!8999)(""N  (((N  ))))N  '!1222Z*44 t{** !D}$ 4m1133333333333 +*4 4r.   c                 F    t          t          j        | t                    S )N)levelwbitsmax_sync_chunk_size)r   r<   Z_BEST_SPEEDWEBSOCKET_MAX_SYNC_CHUNK_SIZE)r+   r   s     r,   r:   z"WebSocketWriter._make_compress_obj   s'    #) =
 
 
 	
r.     r.   codec                    K   t          |t                    r|                    d          }	 |                     t	          |          |z   t
          j                   d{V  d| _        dS # d| _        w xY w)z<Close the websocket, sending the specified code and message.zutf-8)r0   NT)
isinstancestrencoderN   r   r   r9   r'   )r+   rV   r/   s      r,   closezWebSocketWriter.close   s      gs## 	.nnW--G	!//%%/	 "          !DMMMDDM    s   7A. .	A7)N)rU   r.   )__name__
__module____qualname____doc__r   r   Randomr	   asyncio	Transportboolintr-   bytesr   rN   r   r:   r   rY   r[    r.   r,   r   r   $   sP         " - & & && $&
 & & & & & 
& & & &0 FJ[4 [4[4&)[45=c][4	[4 [4 [4 [4z
3 
> 
 
 
 
	! 	! 	!U5#:5F 	!QU 	! 	! 	! 	! 	! 	!r.   r   )"r_   ra   r   r<   	functoolsr   typingr   r   r   r   base_protocolr	   client_exceptionsr
   compression_utilsr   helpersr   r   r   r   r   r   r   r   modelsr   r   r   rd   __annotations__rT   r   rf   r.   r,   <module>ro      sk   + + +          . . . . . . . . . . . . ( ( ( ( ( ( : : : : : : . . . . . .	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 3 2 2 2 2 2 2 2!uSz ! ! ! !) M! M! M! M! M! M! M! M! M! M!r.   