File: //usr/local/lib/python3.10/dist-packages/aiohttp/__pycache__/compression_utils.cpython-310.pyc
o
���g1 � @ s� d dl Z d dlZd dlmZ d dlmZmZ zzd dlZW n
e y* d dlZY nw dZ
W n e y9 dZ
Y nw dZ ddee de
d efd
d�ZG dd
� d
�ZG dd� de�ZG dd� de�ZG dd� d�ZdS )� N)�Executor)�Optional�castTFi �encoding�suppress_deflate_header�returnc C s$ | dkr dt j S |rt j S t jS )N�gzip� )�zlib� MAX_WBITS)r r � r �D/usr/local/lib/python3.10/dist-packages/aiohttp/compression_utils.py�encoding_to_mode s
r c @ s0 e Zd Zdefdedee dee fdd�ZdS )�ZlibBaseHandlerN�mode�executor�max_sync_chunk_sizec C s || _ || _|| _d S �N)�_mode� _executor�_max_sync_chunk_size)�selfr r r r r r
�__init__ s
zZlibBaseHandler.__init__)�__name__�
__module__�__qualname__�MAX_SYNC_CHUNK_SIZE�intr r r r r r r
r s ����r c s� e Zd Zddddejdefdee dedee dee de dee
d ee f� fd
d�
Zded
efdd�Z
ded
efdd�Zejfde d
efdd�Z� ZS )�ZLibCompressorNFr r �level�wbits�strategyr r c sb t � j|d u rt||�n|||d� |d u r tj| j|d�| _n
tj| j||d�| _t�� | _ d S )N�r r r )r r! )r r! r )
�superr r r
�compressobjr �_compressor�asyncio�Lock�_compress_lock)r r r r r r! r r �� __class__r r
r * s
�� �zZLibCompressor.__init__�datar c C � | j �|�S r )r% �compress�r r+ r r r
�
compress_syncE � zZLibCompressor.compress_syncc � s� �| j 4 I dH �5 | jdur.t|�| jkr.t�� �| j| jj|�I dH W d �I dH S | � |�W d �I dH S 1 I dH sCw Y dS )aC Compress the data and returned the compressed bytes.
Note that flush() must be called after the last call to compress()
If the data size is large than the max_sync_chunk_size, the compression
will be done in the executor. Otherwise, the compression will be done
in the event loop.
N)
r( r �lenr&