o
    )f                     @   s   d dl Z d dlZd dlmZ d dlmZmZ zzd dlZW n e	y*   d dlZY nw dZ
W n e	y9   dZ
Y nw dZ		ddee ded	ef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   9lib/python3.10/site-packages/aiohttp/compression_utils.pyencoding_to_mode   s   
r   c                   @   s0   e Zd Zdefdedee dee f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dee dedee	 dee	 de	dee
 d	ee	 f fd
dZdedefddZdedefddZejfde	defddZ  ZS )ZLibCompressorNFr   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 )Nr   r   r   )r    r!   )r    r!   r   )
superr   r   r
   compressobjr   _compressorasyncioZLock_compress_lock)r   r   r   r   r    r!   r   r   	__class__r   r   r   *   s   

zZLibCompressor.__init__datar   c                 C      | j |S r   )r%   compressr   r*   r   r   r   compress_syncC      zZLibCompressor.compress_syncc              	      s   | j 4 I d H 4 | jd ur-t|| jkr-t | j| j|I d H W  d   I d H  S | |W  d   I d H  S 1 I d H sBw   Y  d S r   )r'   r   lenr&   get_event_looprun_in_executorr   r.   r-   r   r   r   r,   F   s   

0zZLibCompressor.compressr   c                 C   r+   r   )r%   flush)r   r   r   r   r   r3   U   r/   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   )   s4     r   c                
       s   e Zd Zdddefdee dedee dee f fddZ	dd
e
dede
fddZdd
e
dede
fddZddede
fddZedefddZede
fddZede
fddZ  ZS )ZLibDecompressorNFr   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   Z   s   zZLibDecompressor.__init__r   r*   
max_lengthr   c                 C   s   | j ||S r   )r<   
decompressr   r*   r=   r   r   r   decompress_synch   s   z ZLibDecompressor.decompress_syncc                    sD   | j d urt|| j krt | j| j||I d H S | ||S r   )r   r0   r&   r1   r2   r   r@   r?   r   r   r   r>   k   s   

zZLibDecompressor.decompresslengthc                 C   s   |dkr
| j |S | j  S )Nr   )r<   r3   )r   rA   r   r   r   r3   u   s
   
zZLibDecompressor.flushc                 C      | j jS r   )r<   eofr   r   r   r   rC   |      zZLibDecompressor.eofc                 C   rB   r   )r<   unconsumed_tailrD   r   r   r   rF      rE   z ZLibDecompressor.unconsumed_tailc                 C   rB   r   )r<   unused_datarD   r   r   r   rG      rE   zZLibDecompressor.unused_data)r   )r   r   r   r   r   r5   r6   r   r   r   r7   r@   r>   r3   propertyrC   rF   rG   r9   r   r   r(   r   r:   Y   s.    
r:   c                   @   s6   e Zd Zd
ddZdedefddZdefdd	ZdS )BrotliDecompressorr   Nc                 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>   )hasattrrM   r   r7   r>   Zprocessr-   r   r   r   r@      s   z"BrotliDecompressor.decompress_syncc                 C   s    t | jdrtt| j S dS )Nr3       )rN   rM   r   r7   r3   rD   r   r   r   r3      s   zBrotliDecompressor.flush)r   N)r   r   r   r   r7   r@   r3   r   r   r   r   rI      s    
rI   )NF)r&   r
   Zconcurrent.futuresr   typingr   r   Z
brotlicffirL   ImportErrorrJ   r   r5   r6   r   r   r   r   r:   rI   r   r   r   r   <module>   s8    

00