
    i(                     Z   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	 	 d dlZd	Z	 ej                  dk\  rd dlmZ nd dlmZ d	ZdZ G d de	      Z G d de	      Z G d de	      Z G d de
d
      Z G d d      Z ee      Z ee!d<   deddfdZ"	 	 d*dee#   de$de%fdZ& G d  d!      Z' G d" d#e'      Z( G d$ d%e'      Z) G d& d'      Z* G d( d)      Z+y# e$ r d dlZY w xY w# e$ r d
ZY w xY w# e$ r d
ZY w xY w)+    N)Executor)AnyFinalOptionalProtocol	TypedDictcast)      )Buffer)Unionzmemoryview[int]zmemoryview[bytes]TF)r
      )ZstdDecompressori   c                   .    e Zd ZdedefdZddedefdZy)ZLibCompressObjProtocoldatareturnc                      y N selfr   s     T/var/www/html/binance/venv/lib/python3.12/site-packages/aiohttp/compression_utils.pycompressz ZLibCompressObjProtocol.compress'           modec                     y r   r   r   r   s     r   flushzZLibCompressObjProtocol.flush(   r   r   N.)__name__
__module____qualname__r   bytesr   intr    r   r   r   r   r   &   s    2V225#555r   r   c                   J    e Zd Zd	dededefdZd	dedefdZede	fd       Z
y)
ZLibDecompressObjProtocolr   
max_lengthr   c                      y r   r   r   r   r)   s      r   
decompressz$ZLibDecompressObjProtocol.decompress,   r   r   lengthc                     y r   r   r   r-   s     r   r    zZLibDecompressObjProtocol.flush-   r   r   c                      y r   r   r   s    r   eofzZLibDecompressObjProtocol.eof/   s    r   Nr!   )r"   r#   r$   r   r&   r%   r,   r    propertyboolr2   r   r   r   r(   r(   +   s4    KvK3KK7C7U7T r   r(   c                       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Z	 ddedede	fdZ
	 ddedededefdZ	 ddedededefdZy)ZLibBackendProtocol	MAX_WBITSZ_FULL_FLUSHZ_SYNC_FLUSHZ_BEST_SPEEDZ_FINISHlevelmethodwbitsmemLevelstrategyzdictr   c                      y r   r   )r   r<   r=   r>   r?   r@   rA   s          r   compressobjzZLibBackendProtocol.compressobj:   s     #&r   c                      y r   r   )r   r>   rA   s      r   decompressobjz!ZLibBackendProtocol.decompressobjC   s    $'r   r   c                     y r   r   )r   r   r<   r>   s       r   r   zZLibBackendProtocol.compressG       r   bufsizec                     y r   r   )r   r   r>   rH   s       r   r,   zZLibBackendProtocol.decompressJ   rG   r   N)......)..)r"   r#   r$   r&   __annotations__r   r   r   rC   r(   rE   r%   r   r,   r   r   r   r6   r6   3   s    NM "%&& & 	&
 & & & 
!& 14(('-(	"(
 ?B&)8;	 AD&):=	r   r6   c                   ,    e Zd ZU eed<   eed<   eed<   y)CompressObjArgsr>   r@   r<   N)r"   r#   r$   r&   rJ   r   r   r   rL   rL   O   s    JMJr   rL   )totalc                      e Zd ZdefdZedefd       Zedefd       Z	edefd       Z
edefd       Zedefd       Zedefd	       Zd
ededefdZd
ededefdZded
ededefdZded
ededefdZdedefdZy)ZLibBackendWrapper_zlib_backendc                     || _         y r   )rP   )r   rP   s     r   __init__zZLibBackendWrapper.__init__V   s
    2?r   r   c                 0    t        | j                  dd      S )Nr"   	undefinedgetattrrP   r1   s    r   namezZLibBackendWrapper.nameY   s    t)):{CCr   c                 .    | j                   j                  S r   )rP   r7   r1   s    r   r7   zZLibBackendWrapper.MAX_WBITS]   s    !!+++r   c                 .    | j                   j                  S r   )rP   r8   r1   s    r   r8   zZLibBackendWrapper.Z_FULL_FLUSHa       !!...r   c                 .    | j                   j                  S r   )rP   r9   r1   s    r   r9   zZLibBackendWrapper.Z_SYNC_FLUSHe   rZ   r   c                 .    | j                   j                  S r   )rP   r:   r1   s    r   r:   zZLibBackendWrapper.Z_BEST_SPEEDi   rZ   r   c                 .    | j                   j                  S r   )rP   r;   r1   s    r   r;   zZLibBackendWrapper.Z_FINISHm   s    !!***r   argskwargsc                 :     | j                   j                  |i |S r   )rP   rC   r   r^   r_   s      r   rC   zZLibBackendWrapper.compressobjq   s     -t!!--t>v>>r   c                 :     | j                   j                  |i |S r   )rP   rE   ra   s      r   rE   z ZLibBackendWrapper.decompressobjt   s     /t!!//@@@r   r   c                 B     | j                   j                  |g|i |S r   )rP   r   r   r   r^   r_   s       r   r   zZLibBackendWrapper.compressw   s%    *t!!**4A$A&AAr   c                 B     | j                   j                  |g|i |S r   )rP   r,   rd   s       r   r,   zZLibBackendWrapper.decompressz   s%    ,t!!,,TCDCFCCr   attrnamec                 .    t        | j                  |      S r   rU   )r   rf   s     r   __getattr__zZLibBackendWrapper.__getattr__~   s    t))844r   N)r"   r#   r$   r6   rR   r3   strrW   r&   r7   r8   r9   r:   r;   r   r   rC   r(   rE   r   r%   r   r,   rh   r   r   r   rO   rO   U   sO   @&9 @ Dc D D ,3 , , /c / / /c / / /c / / +# + +? ? ?8O ?A3 A# A:S ABV BC B3 B5 BDv Dc DS DU D5C 5C 5r   rO   ZLibBackendnew_zlib_backendr   c                     | t         _        y r   )rj   rP   )rk   s    r   set_zlib_backendrm      s
     0Kr   encodingsuppress_deflate_headerc                 x    | dk(  rdt         j                  z   S |rt         j                   S t         j                  S )Ngzip   )rj   r7   )rn   ro   s     r   encoding_to_moders      s9     6K))))%<K!!!W+BWBWWr   c                   2    e Zd Zdefdedee   dee   fdZy)ZlibBaseHandlerNr   executormax_sync_chunk_sizec                 .    || _         || _        || _        y r   )_mode	_executor_max_sync_chunk_size)r   r   rv   rw   s       r   rR   zZlibBaseHandler.__init__   s     
!$7!r   )r"   r#   r$   MAX_SYNC_CHUNK_SIZEr&   r   r   rR   r   r   r   ru   ru      s4     (,-@	88 8$8 &c]	8r   ru   c                        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
Z	de
de
fdZde
de
fdZddee   de
fdZ xZS )ZLibCompressorNFrn   ro   r<   r>   r@   rv   rw   c                    t         	|   |t        ||      n|||       t        t        j
                        | _        i }| j                  |d<   |||d<   |||d<    | j
                  j                  di || _        y )Nr   rv   rw   r>   r@   r<   r   )	superrR   rs   rO   rj   rP   ry   rC   _compressor)
r   rn   ro   r<   r>   r@   rv   rw   r_   	__class__s
            r   rR   zZLibCompressor.__init__   s     	 = !+BC 3 	 	
 %7{7P7P$Q"$**w!)F:#F7O94--99CFCr   r   r   c                 8    | j                   j                  |      S r   )r   r   r   s     r   compress_synczZLibCompressor.compress_sync   s    ((..r   c                   K   | j                   duxr t        |      | j                   kD  }|rKt        j                         j	                  | j
                  | j                  j                  |       d{   S | j                  |      S 7 w)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)	r{   lenasyncioget_running_looprun_in_executorrz   r   r   r   )r   r   should_use_executors      r   r   zZLibCompressor.compress   s     & %%T1 6D	D555 	  113CC 0 0 9 94   !!$''s   A1B3B	4Br   c                 p    | j                   j                  ||      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.
        )r   r    rP   r;   r   s     r   r    zZLibCompressor.flush   s>     %%$D
 	
*.*<*<*E*E
 	
r   r   )r"   r#   r$   r|   r   ri   r4   r&   r   rR   r%   r   r   r    __classcell__r   s   @r   r~   r~      s     #'(-##"&'+-@D3-D "&D }	D
 }D 3-D 8$D &c]D:/% /E /(5 (U (8
(3- 
5 
r   r~   c            
            e Zd Zdddefdee   dedee   dee   f fdZ	dde
d	ed
e
fdZdde
d	ed
e
fdZdded
e
fdZed
efd       Z xZS )ZLibDecompressorNFrn   ro   rv   rw   c                     t         |   t        ||      ||       t        t        j
                        | _        | j
                  j                  | j                        | _        y )Nr   )r>   )	r   rR   rs   rO   rj   rP   rE   ry   _decompressor)r   rn   ro   rv   rw   r   s        r   rR   zZLibDecompressor.__init__   s]     	!(,CD 3 	 	

 %7{7P7P$Q!//==DJJ=Or   r   r)   r   c                 :    | j                   j                  ||      S r   )r   r,   r+   s      r   decompress_syncz ZLibDecompressor.decompress_sync   s    !!,,T:>>r   c                   K   | j                   dt        |      | j                   kD  rLt        j                         j	                  | j
                  | j                  j                  ||       d{   S | j                  ||      S 7 w)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{   r   r   r   r   rz   r   r,   r   r+   s      r   r,   zZLibDecompressor.decompress   sz      %%1D	D555 113CC 2 2 = =tZ   ##D*55s   A,B.B/Br-   c                 v    |dkD  r| j                   j                  |      S | j                   j                         S )Nr   )r   r    r/   s     r   r    zZLibDecompressor.flush  s?     z $$V,	
 ##))+	
r   c                 .    | j                   j                  S r   )r   r2   r1   s    r   r2   zZLibDecompressor.eof  s    !!%%%r   )r   )r"   r#   r$   r|   r   ri   r4   r   r&   rR   r%   r   r,   r    r3   r2   r   r   s   @r   r   r      s     #'(-'+-@P3-P "&P 8$	P
 &c]P?E ?s ?5 ?6U 6 6E 6 
C 
 
 &T & &r   r   c                   0    e Zd ZddZdedefdZdefdZy)BrotliDecompressorr   Nc                 X    t         st        d      t        j                         | _        y )NzIThe brotli decompression is not available. Please install `Brotli` module)
HAS_BROTLIRuntimeErrorbrotliDecompressor_objr1   s    r   rR   zBrotliDecompressor.__init__  s)    1  '')	r   r   c                     t        | j                  d      r)t        t        | j                  j	                  |            S t        t        | j                  j                  |            S )Nr,   )hasattrr   r	   r%   r,   processr   s     r   r   z"BrotliDecompressor.decompress_sync'  sH    499l+tyy33D9::E499,,T233r   c                     t        | j                  d      r(t        t        | j                  j	                               S y)Nr    r   )r   r   r	   r%   r    r1   s    r   r    zBrotliDecompressor.flush,  s+    499g&tyy011r   r   Nr"   r#   r$   rR   r%   r   r    r   r   r   r   r     s&    *4E 4e 4
u r   r   c                   0    e Zd ZddZdedefdZdefdZy)ZSTDDecompressorr   Nc                 D    t         st        d      t               | _        y )NzOThe zstd decompression is not available. Please install `backports.zstd` module)HAS_ZSTDr   r   r   r1   s    r   rR   zZSTDDecompressor.__init__3  s#    9  %&	r   r   c                 8    | j                   j                  |      S r   )r   r,   r   s     r   r   z ZSTDDecompressor.decompress_sync;  s    yy##D))r   c                      y)Nr   r   r1   s    r   r    zZSTDDecompressor.flush>  s    r   r   r   r   r   r   r   r   2  s&    '*E *e *u r   r   )NF),r   syszlibconcurrent.futuresr   typingr   r   r   r   r   r	   version_infocollections.abcr   r   r%   	bytearray
brotlicffir   ImportErrorr   compression.zstdr   backports.zstdr   r|   r   r(   r6   rL   rO   rj   rJ   rm   ri   r4   r&   rs   ru   r~   r   r   r   r   r   r   <module>r      s    
  ' B Bw&5)%68KKLF# J
7"53H
  6h 6
 ( 8iu *5 *5Z #5T": :1': 1t 1
 #$)XsmX!X 	X	8 	8J
_ J
Z,& ,&^ . C	    J  HsB   D D D  	DD DD DD D*)D*