HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/aiohttp/_websocket/__pycache__/writer.cpython-310.pyc
o

���g��@s�UdZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
ddlmZddl
mZddlmZd	d
lmZmZmZmZmZmZmZmZd	dlmZmZdZeeed
<dZ Gdd�d�Z!dS)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_LIMITic@s�eZdZdZdee��ddd�dedej	de
ded	ejd
ede
dd
fdd�Z	
dde
ded
eedd
fdd�Zd
edefdd�Zddedee
efdd
fdd�Zd
S)�WebSocketWritera3WebSocket 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�	transportrrrrr�returnNcCsH||_||_||_t|jd�|_||_||_d|_||_	d|_
d|_dS)zInitialize a WebSocket writer.� FrN)rrrr�getrandbits�get_random_bitsrr�_closing�_limit�_output_size�_compressobj)�selfrrrrrrr�r)�D/usr/local/lib/python3.10/dist-packages/aiohttp/_websocket/writer.py�__init__-s
zWebSocketWriter.__init__�message�opcodec
�s��|jr
|tj@s
td��d}|s|jrF|dkrFd}|r"|�|�}n
|js,|�|j�|_|j}|�|�IdH|�|jr>t	j
nt	j��t
�}t|�}|j}|rQdnd}d|B|B}	|dkrgt|	||B�}
d}n|d	krvt|	d|B|�}
d
}n
t|	d|B|�}
d}|j��r�td��|r�t|���}t|�}t||�|j�|
||�|jt7_n|tkr�|j�|
�|j�|�n|j�|
|�|j||7_|j|jkr�d|_|jjr�|j� �IdHdSdSdS)
z<Send a frame over the websocket with message as its payload.z!Cannot write to closing transportr��@N��~rr���
)!r$r�CLOSEr	r�_make_compress_objr'�flushr�zlib�Z_FULL_FLUSH�Z_SYNC_FLUSH�removesuffixr�lenrrrrr�
is_closingrr#�	bytearrayr�writer&rr
r%r�_paused�
_drain_helper)
r(r,r-r�rsv�compressobj�
msg_lengthr�mask_bit�
first_byte�header�
header_len�maskr)r)r*�
send_frameDsb����
	

�zWebSocketWriter.send_framecCsttj|td�S)N)�level�wbits�max_sync_chunk_size)r
r8�Z_BEST_SPEED�WEBSOCKET_MAX_SYNC_CHUNK_SIZE)r(rr)r)r*r6�s
�z"WebSocketWriter._make_compress_obj����codec�sJ�t|t�r|�d�}z|jt|�|tjd�IdHWd|_dSd|_w)z<Close the websocket, sending the specified code and message.zutf-8)r-NT)�
isinstance�str�encoderJrrr5r$)r(rRr,r)r)r*�close�s�

�zWebSocketWriter.close)N)rPrQ)�__name__�
__module__�__qualname__�__doc__rr�Randomr�asyncio�	Transport�bool�intr+�bytesrrJr
r6rrTrVr)r)r)r*r$sH
�������	�

�����
�]$r)"rZr\rr8�	functoolsr�typingrrrr�
base_protocolr�client_exceptionsr	�compression_utilsr
�helpersrr
rrrrrr�modelsrrrr_�__annotations__rOrr)r)r)r*�<module>s(