o
    LDi(                     @   s  U d dl Z d dlZd dl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r/d 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yQ   d dlZY nw d	ZW n ey`   d
ZY nw zejdkrnd dlmZ nd dlmZ d	ZW n ey   d
ZY nw 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#Z'G d$d% d%e'Z(G d&d' d'e'Z)G d(d) d)Z*G d*d+ d+Z+dS )-    N)Executor)AnyFinalOptionalProtocol	TypedDictcast)      )Buffer)Unionzmemoryview[int]zmemoryview[bytes]TF)r	      )ZstdDecompressori   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   e/var/www/www-root/data/www/77.83.87.30/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   
decompress,   r   z$ZLibDecompressObjProtocol.decompresslengthc                C   r   r   r   r   r'   r   r   r   r   -   r   zZLibDecompressObjProtocol.flushc                 C   r   r   r   r   r   r   r   eof/      zZLibDecompressObjProtocol.eofNr   )r   r   r    r   r"   r!   r&   r   propertyboolr*   r   r   r   r   r#   +   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   r4   r5   r6   r7   r8   r9   r   r   r   compressobj:   s   zZLibBackendProtocol.compressobjc                 C   r   r   r   )r   r6   r9   r   r   r   decompressobjC      z!ZLibBackendProtocol.decompressobjr   c                C   r   r   r   )r   r   r4   r6   r   r   r   r   G   r<   zZLibBackendProtocol.compressbufsizec                C   r   r   r   )r   r   r6   r=   r   r   r   r&   J   r<   zZLibBackendProtocol.decompressN)......)..)r   r   r    r"   __annotations__r   r   r   r:   r#   r;   r!   r   r&   r   r   r   r   r.   3   sn   
 



r.   c                   @   s&   e Zd ZU eed< eed< eed< dS )CompressObjArgsr6   r8   r4   N)r   r   r    r"   r>   r   r   r   r   r?   O   s   
 r?   )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   )rB   )r   rB   r   r   r   __init__V      
zZLibBackendWrapper.__init__r   c                 C   s   t | jddS )Nr   	undefinedgetattrrB   r)   r   r   r   nameY   s   zZLibBackendWrapper.namec                 C      | j jS r   )rB   r/   r)   r   r   r   r/   ]      zZLibBackendWrapper.MAX_WBITSc                 C   rI   r   )rB   r0   r)   r   r   r   r0   a   rJ   zZLibBackendWrapper.Z_FULL_FLUSHc                 C   rI   r   )rB   r1   r)   r   r   r   r1   e   rJ   zZLibBackendWrapper.Z_SYNC_FLUSHc                 C   rI   r   )rB   r2   r)   r   r   r   r2   i   rJ   zZLibBackendWrapper.Z_BEST_SPEEDc                 C   rI   r   )rB   r3   r)   r   r   r   r3   m   rJ   zZLibBackendWrapper.Z_FINISHargskwargsc                 O      | j j|i |S r   )rB   r:   r   rK   rL   r   r   r   r:   q      zZLibBackendWrapper.compressobjc                 O   rM   r   )rB   r;   rN   r   r   r   r;   t   rO   z ZLibBackendWrapper.decompressobjr   c                 O      | j j|g|R i |S r   )rB   r   r   r   rK   rL   r   r   r   r   w      zZLibBackendWrapper.compressc                 O   rP   r   )rB   r&   rQ   r   r   r   r&   z   rR   zZLibBackendWrapper.decompressattrnamec                 C   s   t | j|S r   rF   )r   rS   r   r   r   __getattr__~      zZLibBackendWrapper.__getattr__N)r   r   r    r.   rC   r,   strrH   r"   r/   r0   r1   r2   r3   r   r   r:   r#   r;   r   r!   r   r&   rT   r   r   r   r   rA   U   s&    rA   ZLibBackendnew_zlib_backendr   c                 C   s
   | t _d S r   )rW   rB   )rX   r   r   r   set_zlib_backend   rD   rY   encodingsuppress_deflate_headerc                 C   s$   | dkr	dt j S |rt j S t jS )Ngzip   )rW   r/   )rZ   r[   r   r   r   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 )ZlibBaseHandlerNr   executormax_sync_chunk_sizec                 C   s   || _ || _|| _d S r   )_mode	_executor_max_sync_chunk_size)r   r   r`   ra   r   r   r   rC      s   
zZlibBaseHandler.__init__)r   r   r    MAX_SYNC_CHUNK_SIZEr"   r   r   rC   r   r   r   r   r_      s    r_   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 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  ZS )ZLibCompressorNFrZ   r[   r4   r6   r8   r`   ra   c           	         sv   t  j|d u rt||n|||d ttj| _i }| j|d< |d ur'||d< |d ur/||d< | jjdi || _d S )Nr   r`   ra   r6   r8   r4   r   )	superrC   r^   rA   rW   rB   rb   r:   _compressor)	r   rZ   r[   r4   r6   r8   r`   ra   rL   	__class__r   r   rC      s   

	
zZLibCompressor.__init__r   r   c                 C      | j |S r   )ri   r   r   r   r   r   compress_sync   rU   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)	rd   lenasyncioget_running_looprun_in_executorrc   ri   r   rm   )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)ri   r   rB   r3   r   r   r   r   r      s
   
zZLibCompressor.flushr   )r   r   r    re   r   rV   r-   r"   r   rC   r!   rm   r   r   __classcell__r   r   rj   r   rf      s4     rf   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  ZS )ZLibDecompressorNFrZ   r[   r`   ra   c                    s:   t  jt||||d ttj| _| jj| jd| _d S )Nrg   )r6   )	rh   rC   r^   rA   rW   rB   r;   rb   _decompressor)r   rZ   r[   r`   ra   rj   r   r   rC      s   zZLibDecompressor.__init__r   r   r$   r   c                 C   s   | j ||S r   )ru   r&   r%   r   r   r   decompress_sync   s   z ZLibDecompressor.decompress_syncc                    sF   | j durt|| j krt | 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)	rd   rn   ro   rp   rq   rc   ru   r&   rv   r%   r   r   r   r&      s   

zZLibDecompressor.decompressr'   c                 C   s   |dkr
| j |S | j  S )Nr   )ru   r   r(   r   r   r   r     s
   
zZLibDecompressor.flushc                 C   rI   r   )ru   r*   r)   r   r   r   r*     rJ   zZLibDecompressor.eof)r   )r   r   r    re   r   rV   r-   r   r"   rC   r!   rv   r&   r   r,   r*   rs   r   r   rj   r   rt      s&    rt   c                   @   6   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brotliDecompressor_objr)   r   r   r   rC     s
   zBrotliDecompressor.__init__r   c                 C   s0   t | jdrtt| j|S tt| j|S )Nr&   )hasattrr}   r   r!   r&   processr   r   r   r   rv   '  s   z"BrotliDecompressor.decompress_syncc                 C   s    t | jdrtt| j S dS )Nr       )r~   r}   r   r!   r   r)   r   r   r   r   ,  s   zBrotliDecompressor.flushr   Nr   r   r    rC   r!   rv   r   r   r   r   r   rx     s    
rx   c                   @   rw   )ZSTDDecompressorr   Nc                 C   s   t stdt | _d S )NzOThe zstd decompression is not available. Please install `backports.zstd` module)HAS_ZSTDrz   r   r}   r)   r   r   r   rC   3  s
   zZSTDDecompressor.__init__r   c                 C   rl   r   )r}   r&   r   r   r   r   rv   ;  rU   z ZSTDDecompressor.decompress_syncc                 C   s   dS )Nr   r   r)   r   r   r   r   >  r+   zZSTDDecompressor.flushr   r   r   r   r   r   r   2  s    
r   )NF),ro   syszlibconcurrent.futuresr   typingr   r   r   r   r   r   version_infocollections.abcr   r   r!   	bytearray
brotlicffir{   ImportErrorry   compression.zstdr   backports.zstdr   re   r   r#   r.   r?   rA   rW   r>   rY   rV   r-   r"   r^   r_   rf   rt   rx   r   r   r   r   r   <module>   sb   
  

-

M/