U
    ;g1                     @   s   d dl Z d dlZd dlmZ d dlmZmZ z2zd dlZW n e	k
rV   d dlZY nX dZ
W n e	k
rv   dZ
Y nX 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   Y/opt/bot/vods_filmes/script/venv/lib/python3.8/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 krt||n|||d |d k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 f | jdk	rXt|| jkrXt | j| jj|I dH W  5 Q I dH R  S | 	|W  5 Q I dH R  S Q I dH R X dS )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&   get_running_looprun_in_executorr   r%   r-   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   _   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   d   s    zZLibDecompressor.__init__r   )r,   
max_lengthr   c                 C   s   | j ||S r   )r<   
decompressr   r,   r=   r   r   r   decompress_syncr   s    z ZLibDecompressor.decompress_syncc                    sD   | j dk	r8t|| j kr8t | j| jj||I dH S | ||S )zDecompress the data and return the decompressed bytes.

        If the data size is large than the max_sync_chunk_size, the decompression
        will be done in the executor. Otherwise, the decompression will be done
        in the event loop.
        N)	r   r0   r&   r1   r2   r   r<   r>   r@   r?   r   r   r   r>   u   s       
zZLibDecompressor.decompress)lengthr   c                 C   s   |dkr| j |S | j  S )Nr   )r<   r3   )r   rA   r   r   r   r3      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:   c   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.   
  
:6