a
    Rf                     @   s   d dl Z d dlZd dlmZ d dlmZmZ z0zd dlZW n e	yT   d dlZY n0 dZ
W n e	yr   dZ
Y n0 dZdee eeddd	ZG d
d dZG dd deZG dd deZG dd dZdS )    N)Executor)OptionalcastTFi   )encodingsuppress_deflate_headerreturnc                 C   s$   | dkrdt j S |rt j S t jS )Ngzip   )zlib	MAX_WBITS)r   r    r   R/var/www/ai-form-bot/venv/lib/python3.9/site-packages/aiohttp/compression_utils.pyencoding_to_mode   s    
r   c                   @   s,   e Zd Zdefeee ee dddZdS )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    zZlibBaseHandler.__init__)__name__
__module____qualname__MAX_SYNC_CHUNK_SIZEintr   r   r   r   r   r   r   r      s   r   c                	       s   e Zd Zddddejdefee eee	 ee	 e	ee
 ee	 d fddZeedddZeedd	d
Zejfe	edddZ  ZS )ZLibCompressorNF)r   r   levelwbitsstrategyr   r   c                    sb   t  j|d u rt||n|||d |d u r@tj| j|d| _ntj| j||d| _t | _	d S )Nr   )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    
	zZLibCompressor.__init__datar   c                 C   s   | j |S r   )r%   compressr   r,   r   r   r   compress_syncE   s    zZLibCompressor.compress_syncc              	      s   | j 4 I d H h | jd urXt|| jkrXt | j| j|I d H W  d   I d H  S | |W  d   I d H  S 1 I d H s0    Y  d S r   )r(   r   lenr&   get_event_looprun_in_executorr   r/   r.   r   r   r   r-   H   s    
zZLibCompressor.compress)r   r   c                 C   s   | j |S r   )r%   flush)r   r   r   r   r   r3   W   s    zZLibCompressor.flush)r   r   r   r
   Z_DEFAULT_STRATEGYr   r   strboolr   r   r   bytesr/   r-   Z_FINISHr3   __classcell__r   r   r)   r   r   )   s&   r   c                       s   e Zd Zdddefee eee ee d fddZ	de
ee
ddd	Zde
ee
dd
dZdee
dddZeedddZee
dddZee
dddZ  ZS )ZLibDecompressorNF)r   r   r   r   c                    s,   t  jt||||d tj| jd| _d S )Nr   )r!   )r#   r   r   r
   decompressobjr   _decompressor)r   r   r   r   r   r)   r   r   r   \   s    zZLibDecompressor.__init__r   )r,   
max_lengthr   c                 C   s   | j ||S r   )r<   
decompressr   r,   r=   r   r   r   decompress_syncj   s    z ZLibDecompressor.decompress_syncc                    sB   | j d ur6t|| j kr6t | j| j||I d H S | ||S r   )r   r0   r&   r1   r2   r   r@   r?   r   r   r   r>   m   s    
zZLibDecompressor.decompress)lengthr   c                 C   s   |dkr| j |S | j  S )Nr   )r<   r3   )r   rA   r   r   r   r3   w   s    zZLibDecompressor.flushr   c                 C   s   | j jS r   )r<   eofr   r   r   r   rC   ~   s    zZLibDecompressor.eofc                 C   s   | j jS r   )r<   unconsumed_tailrD   r   r   r   rE      s    z ZLibDecompressor.unconsumed_tailc                 C   s   | j jS r   )r<   unused_datarD   r   r   r   rF      s    zZLibDecompressor.unused_data)r   )r   )r   )r   r   r   r   r   r5   r6   r   r   r   r7   r@   r>   r3   propertyrC   rE   rF   r9   r   r   r)   r   r:   [   s&   
r:   c                   @   s8   e Zd ZddddZeedddZeddd	ZdS )
BrotliDecompressorNrB   c                 C   s   t stdt | _d S )NzIThe brotli decompression is not available. Please install `Brotli` module)
HAS_BROTLIRuntimeErrorbrotliZDecompressor_objrD   r   r   r   r      s
    zBrotliDecompressor.__init__r+   c                 C   s0   t | jdrtt| j|S tt| j|S )Nr>   )hasattrrL   r   r7   r>   processr.   r   r   r   r@      s    z"BrotliDecompressor.decompress_syncc                 C   s    t | jdrtt| j S dS )Nr3       )rM   rL   r   r7   r3   rD   r   r   r   r3      s    zBrotliDecompressor.flush)r   r   r   r   r7   r@   r3   r   r   r   r   rH      s   rH   )NF)r&   r
   concurrent.futuresr   typingr   r   Z
brotlicffirK   ImportErrorrI   r   r5   r6   r   r   r   r   r:   rH   r   r   r   r   <module>   s.   
  
20