o
    ii-                     @   s  U d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZ ejdkr7d dlmZ nd dlmZ eeedd	f Zzzd dlZW n eyY   d dlZY nw d
ZW n eyh   dZY nw zejdkrvd dlmZ nd dlmZ d
ZW n ey   dZY nw dZdZd ZdZ G dd deZ!G dd deZ"G dd deZ#G dd deddZ$G dd dZ%e%eZ&e%e'd< de#ddfdd Z(		d/d!ee) d"e*de+fd#d$Z,G d%d& d&eZ-G d'd( d(Z.G d)d* d*e-Z/G d+d, d,e-Z0G d-d. d.e-Z1dS )0    N)ABCabstractmethod)Executor)AnyFinalOptionalProtocol	TypedDictcast)      )Buffer)Unionzmemoryview[int]zmemoryview[bytes]TF)r      )ZstdDecompressori   i   c                   @   s2   e Zd ZdedefddZd
dedefddZd	S )ZLibCompressObjProtocoldatareturnc                 C      d S N selfr   r   r   a/var/www/scraper.webshop2u.hu/html/venv/lib/python3.10/site-packages/aiohttp/compression_utils.pycompress-       z ZLibCompressObjProtocol.compress.modec                C   r   r   r   r   r   r   r   r   flush.   r   zZLibCompressObjProtocol.flushN.)__name__
__module____qualname__r   bytesr   intr   r   r   r   r   r   ,   s    r   c                   @   sJ   e Z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
dS )ZLibDecompressObjProtocol.r   
max_lengthr   c                 C   r   r   r   r   r   r'   r   r   r   
decompress2   r   z$ZLibDecompressObjProtocol.decompresslengthc                C   r   r   r   r   r*   r   r   r   r   3   r   zZLibDecompressObjProtocol.flushc                 C   r   r   r   r   r   r   r   eof5      zZLibDecompressObjProtocol.eofNr    )r!   r"   r#   r   r%   r$   r)   r   propertyboolr-   r   r   r   r   r&   1   s
    r&   c                   @   s   e Zd ZU eed< eed< eed< eed< eed< 						ddeded	ed
ededee defddZ	dd	edede	fddZ
	dded	ededefddZ	dd	edededefddZdS )ZLibBackendProtocol	MAX_WBITSZ_FULL_FLUSHZ_SYNC_FLUSHZ_BEST_SPEEDZ_FINISH.levelmethodwbitsmemLevelstrategyzdictr   c                 C   r   r   r   )r   r7   r8   r9   r:   r;   r<   r   r   r   compressobj@   s   zZLibBackendProtocol.compressobjc                 C   r   r   r   )r   r9   r<   r   r   r   decompressobjI      z!ZLibBackendProtocol.decompressobjr   c                C   r   r   r   )r   r   r7   r9   r   r   r   r   M   r?   zZLibBackendProtocol.compressbufsizec                C   r   r   r   )r   r   r9   r@   r   r   r   r)   P   r?   zZLibBackendProtocol.decompressN)......)..)r!   r"   r#   r%   __annotations__r   r   r   r=   r&   r>   r$   r   r)   r   r   r   r   r1   9   sn   
 



r1   c                   @   s&   e Zd ZU eed< eed< eed< dS )CompressObjArgsr9   r;   r7   N)r!   r"   r#   r%   rA   r   r   r   r   rB   U   s   
 rB   )totalc                   @   s   e Zd Z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
edefddZedefddZedefddZdededefddZdededefddZdedededefddZdedededefddZdedefddZdS ) ZLibBackendWrapper_zlib_backendc                 C   s
   || _ d S r   )rE   )r   rE   r   r   r   __init__\      
zZLibBackendWrapper.__init__r   c                 C   s   t | jddS )Nr!   	undefinedgetattrrE   r,   r   r   r   name_   s   zZLibBackendWrapper.namec                 C      | j jS r   )rE   r2   r,   r   r   r   r2   c      zZLibBackendWrapper.MAX_WBITSc                 C   rL   r   )rE   r3   r,   r   r   r   r3   g   rM   zZLibBackendWrapper.Z_FULL_FLUSHc                 C   rL   r   )rE   r4   r,   r   r   r   r4   k   rM   zZLibBackendWrapper.Z_SYNC_FLUSHc                 C   rL   r   )rE   r5   r,   r   r   r   r5   o   rM   zZLibBackendWrapper.Z_BEST_SPEEDc                 C   rL   r   )rE   r6   r,   r   r   r   r6   s   rM   zZLibBackendWrapper.Z_FINISHargskwargsc                 O      | j j|i |S r   )rE   r=   r   rN   rO   r   r   r   r=   w      zZLibBackendWrapper.compressobjc                 O   rP   r   )rE   r>   rQ   r   r   r   r>   z   rR   z ZLibBackendWrapper.decompressobjr   c                 O      | j j|g|R i |S r   )rE   r   r   r   rN   rO   r   r   r   r   }      zZLibBackendWrapper.compressc                 O   rS   r   )rE   r)   rT   r   r   r   r)      rU   zZLibBackendWrapper.decompressattrnamec                 C   s   t | j|S r   rI   )r   rV   r   r   r   __getattr__      zZLibBackendWrapper.__getattr__N)r!   r"   r#   r1   rF   r/   strrK   r%   r2   r3   r4   r5   r6   r   r   r=   r&   r>   r   r$   r   r)   rW   r   r   r   r   rD   [   s&    rD   ZLibBackendnew_zlib_backendr   c                 C   s
   | t _d S r   )rZ   rE   )r[   r   r   r   set_zlib_backend   rG   r\   encodingsuppress_deflate_headerc                 C   s$   | dkr	dt j S |rt j S t jS )Ngzip   )rZ   r2   )r]   r^   r   r   r   encoding_to_mode   s   
ra   c                   @   sd   e Zd Zdefdee dee fddZee	fde
dede
fd	d
Ze	fde
dede
fddZdS )DecompressionBaseHandlerNexecutormax_sync_chunk_sizec                 C   s   || _ || _dS )z&Base class for decompression handlers.N)	_executor_max_sync_chunk_sizer   rc   rd   r   r   r   rF      s   
z!DecompressionBaseHandler.__init__r   r'   r   c                 C      dS Decompress the given data.Nr   r(   r   r   r   decompress_sync   r   z(DecompressionBaseHandler.decompress_syncc                    sD   | j durt|| j krt | j| j||I dH S | ||S ri   )rf   lenasyncioget_event_looprun_in_executorre   rk   r(   r   r   r   r)      s   

z#DecompressionBaseHandler.decompress)r!   r"   r#   MAX_SYNC_CHUNK_SIZEr   r   r%   rF   r   ZLIB_MAX_LENGTH_UNLIMITEDr$   rk   r)   r   r   r   r   rb      s2    
	rb   c                   @   s   e Zd Zddddddefdee dedee dee dee dee d	ee fd
dZ	de
de
fddZde
de
fddZddee de
fddZdS )ZLibCompressorNFr]   r^   r7   r9   r;   rc   rd   c           	      C   sv   || _ || _|d u rt||n|| _ttj| _i }| j|d< |d ur'||d< |d ur/||d< | jjdi || _d S )Nr9   r;   r7   r   )	re   rf   ra   _moderD   rZ   rE   r=   _compressor)	r   r]   r^   r7   r9   r;   rc   rd   rO   r   r   r   rF      s   


zZLibCompressor.__init__r   r   c                 C   s   | j |S r   )rt   r   r   r   r   r   compress_sync   rX   zZLibCompressor.compress_syncc                    sF   | j duot|| j k}|rt | j| jj|I dH S | |S )a  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.

        **WARNING: This method is NOT cancellation-safe when used with flush().**
        If this operation is cancelled, the compressor state may be corrupted.
        The connection MUST be closed after cancellation to avoid data corruption
        in subsequent compress operations.

        For cancellation-safe compression (e.g., WebSocket), the caller MUST wrap
        compress() + flush() + send operations in a shield and lock to ensure atomicity.
        N)	rf   rl   rm   get_running_loopro   re   rt   r   ru   )r   r   should_use_executorr   r   r   r      s   


zZLibCompressor.compressr   c                 C   s   | j |dur
|S | jjS )a	  Flush the compressor synchronously.

        **WARNING: This method is NOT cancellation-safe when called after compress().**
        The flush() operation accesses shared compressor state. If compress() was
        cancelled, calling flush() may result in corrupted data. The connection MUST
        be closed after compress() cancellation.

        For cancellation-safe compression (e.g., WebSocket), the caller MUST wrap
        compress() + flush() + send operations in a shield and lock to ensure atomicity.
        N)rt   r   rE   r6   r   r   r   r   r      s
   
zZLibCompressor.flushr   )r!   r"   r#   rp   r   rY   r0   r%   r   rF   r$   ru   r   r   r   r   r   r   rr      s4    
rr   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	e
f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  ZS )ZLibDecompressorNFr]   r^   rc   rd   c                    s>   t  j||d t||| _ttj| _| jj| jd| _d S )Nrc   rd   )r9   )	superrF   ra   rs   rD   rZ   rE   r>   _decompressor)r   r]   r^   rc   rd   	__class__r   r   rF     s   zZLibDecompressor.__init__r   r'   r   c                 C   s   | j ||S r   )r{   r)   r(   r   r   r   rk     s   z ZLibDecompressor.decompress_syncr   r*   c                 C   s   |dkr
| j |S | j  S )Nr   )r{   r   r+   r   r   r   r     s
   
zZLibDecompressor.flushc                 C   rL   r   )r{   r-   r,   r   r   r   r-     rM   zZLibDecompressor.eof)r   )r!   r"   r#   rp   r   rY   r0   r   r%   rF   rq   r   r$   rk   r   r/   r-   __classcell__r   r   r|   r   rx     s2    
rx   c                       s`   e Zd Zdefdee dee ddf fddZefde	dede
fd	d
Zde
fddZ  ZS )BrotliDecompressorNrc   rd   r   c                    s*   t stdt | _t j||d dS )z)Decompress data using the Brotli library.zIThe brotli decompression is not available. Please install `Brotli` modulery   N)
HAS_BROTLIRuntimeErrorbrotliDecompressor_objrz   rF   rg   r|   r   r   rF   $  s   
zBrotliDecompressor.__init__r   r'   c                 C   s4   t | jdrtt| j||S tt| j||S )rj   r)   )hasattrr   r
   r$   r)   processr(   r   r   r   rk   2  s   z"BrotliDecompressor.decompress_syncc                 C   s    t | jdrtt| j S dS )zFlush the decompressor.r       )r   r   r
   r$   r   r,   r   r   r   r   :  s   zBrotliDecompressor.flush)r!   r"   r#   rp   r   r   r%   rF   rq   r   r$   rk   r   r~   r   r   r|   r   r      s&    
r   c                       s`   e Zd Zdefdee dee ddf fddZefde	dede	fd	d
Z
de	fddZ  ZS )ZSTDDecompressorNrc   rd   r   c                    s(   t stdt | _t j||d d S )NzOThe zstd decompression is not available. Please install `backports.zstd` modulery   )HAS_ZSTDr   r   r   rz   rF   rg   r|   r   r   rF   B  s   zZSTDDecompressor.__init__r   r'   c                 C   s   |t krtn|}| j||S r   )rq   ZSTD_MAX_LENGTH_UNLIMITEDr   r)   )r   r   r'   zstd_max_lengthr   r   r   rk   O  s
   z ZSTDDecompressor.decompress_syncc                 C   rh   )Nr   r   r,   r   r   r   r   [  r.   zZSTDDecompressor.flush)r!   r"   r#   rp   r   r   r%   rF   rq   r$   rk   r   r~   r   r   r|   r   r   A  s&    
r   )NF)2rm   syszlibabcr   r   concurrent.futuresr   typingr   r   r   r   r	   r
   version_infocollections.abcr   r   r$   	bytearray
brotlicffir   ImportErrorr   compression.zstdr   backports.zstdr   rp   DEFAULT_MAX_DECOMPRESS_SIZErq   r   r   r&   r1   rB   rD   rZ   rA   r\   rY   r0   r%   ra   rb   rr   rx   r   r   r   r   r   r   <module>   sj   
  

-

K!