
    rj-                     z   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\  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d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$e      Z- G d% d&      Z. G d' d(e-      Z/ G d) d*e-      Z0 G d+ d,e-      Z1y# 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)ABCabstractmethod)Executor)AnyFinalOptionalProtocol	TypedDictcast)      )Buffer)Unionzmemoryview[int]zmemoryview[bytes]TF)r      )ZstdDecompressori   i   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     F/DATA/.local/lib/python3.12/site-packages/aiohttp/compression_utils.pycompressz ZLibCompressObjProtocol.compress-   s    s    modec                     y r   r   r   r   s     r   flushzZLibCompressObjProtocol.flush.   s    #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.decompress2   s    r   lengthc                     y r   r   r   r/   s     r   r"   zZLibDecompressObjProtocol.flush3   s    Cr   c                      y r   r   r   s    r   eofzZLibDecompressObjProtocol.eof5   s    r   Nr#   )r$   r%   r&   r   r(   r'   r.   r"   propertyboolr4   r   r   r   r*   r*   1   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@   rA   rB   rC   s          r   compressobjzZLibBackendProtocol.compressobj@   s     #&r   c                      y r   r   )r   r@   rC   s      r   decompressobjz!ZLibBackendProtocol.decompressobjI   s    $'r   r   c                     y r   r   )r   r   r>   r@   s       r   r   zZLibBackendProtocol.compressM       r   bufsizec                     y r   r   )r   r   r@   rJ   s       r   r.   zZLibBackendProtocol.decompressP   rI   r   N)......)..)r$   r%   r&   r(   __annotations__r   r   r   rE   r*   rG   r'   r   r.   r   r   r   r8   r8   9   s    NM "%&& & 	&
 & & & 
!& 14(('-(	"(
 ?B&)8;	 AD&):=	r   r8   c                   ,    e Zd ZU eed<   eed<   eed<   y)CompressObjArgsr@   rB   r>   N)r$   r%   r&   r(   rL   r   r   r   rN   rN   U   s    JMJr   rN   )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   )rR   )r   rR   s     r   __init__zZLibBackendWrapper.__init__\   s
    2?r   r   c                 0    t        | j                  dd      S )Nr$   	undefinedgetattrrR   r3   s    r   namezZLibBackendWrapper.name_   s    t)):{CCr   c                 .    | j                   j                  S r   )rR   r9   r3   s    r   r9   zZLibBackendWrapper.MAX_WBITSc   s    !!+++r   c                 .    | j                   j                  S r   )rR   r:   r3   s    r   r:   zZLibBackendWrapper.Z_FULL_FLUSHg       !!...r   c                 .    | j                   j                  S r   )rR   r;   r3   s    r   r;   zZLibBackendWrapper.Z_SYNC_FLUSHk   r\   r   c                 .    | j                   j                  S r   )rR   r<   r3   s    r   r<   zZLibBackendWrapper.Z_BEST_SPEEDo   r\   r   c                 .    | j                   j                  S r   )rR   r=   r3   s    r   r=   zZLibBackendWrapper.Z_FINISHs   s    !!***r   argskwargsc                 :     | j                   j                  |i |S r   )rR   rE   r   r`   ra   s      r   rE   zZLibBackendWrapper.compressobjw   s     -t!!--t>v>>r   c                 :     | j                   j                  |i |S r   )rR   rG   rc   s      r   rG   z ZLibBackendWrapper.decompressobjz   s     /t!!//@@@r   r   c                 B     | j                   j                  |g|i |S r   )rR   r   r   r   r`   ra   s       r   r   zZLibBackendWrapper.compress}   s%    *t!!**4A$A&AAr   c                 B     | j                   j                  |g|i |S r   )rR   r.   rf   s       r   r.   zZLibBackendWrapper.decompress   s%    ,t!!,,TCDCFCCr   attrnamec                 .    t        | j                  |      S r   rW   )r   rh   s     r   __getattr__zZLibBackendWrapper.__getattr__   s    t))844r   N)r$   r%   r&   r8   rT   r5   strrY   r(   r9   r:   r;   r<   r=   r   r   rE   r*   rG   r   r'   r   r.   rj   r   r   r   rQ   rQ   [   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   rQ   ZLibBackendnew_zlib_backendr   c                     | t         _        y r   )rl   rR   )rm   s    r   set_zlib_backendro      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   )rl   r9   )rp   rq   s     r   encoding_to_moderu      s9     6K))))%<K!!!W+BWBWWr   c                   h    e Zd Zdefdee   dee   fdZee	fde
dede
fd       Ze	fde
dede
fd	Zy)
DecompressionBaseHandlerNexecutormax_sync_chunk_sizec                      || _         || _        y)z&Base class for decompression handlers.N)	_executor_max_sync_chunk_size)r   rx   ry   s      r   rT   z!DecompressionBaseHandler.__init__   s     "$7!r   r   r+   r   c                      yDecompress the given data.Nr   r-   s      r   decompress_syncz(DecompressionBaseHandler.decompress_sync   s    r   c                    K   | j                   Zt        |      | j                   kD  rBt        j                         j	                  | j
                  | j                  ||       d{   S | j                  ||      S 7 wr~   )r|   lenasyncioget_event_looprun_in_executorr{   r   r-   s      r   r.   z#DecompressionBaseHandler.decompress   st     
 %%1D	D555 //1AA 4 4dJ   ##D*55s   A"A=$A;%A=)r$   r%   r&   MAX_SYNC_CHUNK_SIZEr   r   r(   rT   r   ZLIB_MAX_LENGTH_UNLIMITEDr'   r   r.   r   r   r   rw   rw      s|     (,-@88$8 &c]8 -F))'*)	) ) .G66'*6	6r   rw   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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y)ZLibCompressorNFrp   rq   r>   r@   rB   rx   ry   c                    || _         || _        |t        ||      n|| _        t	        t
        j                        | _        i }| j                  |d<   |||d<   |||d<    | j                  j                  di || _        y )Nr@   rB   r>   r   )	r{   r|   ru   _moderQ   rl   rR   rE   _compressor)	r   rp   rq   r>   r@   rB   rx   ry   ra   s	            r   rT   zZLibCompressor.__init__   s     "$7! } X'>? 	

 %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|   r   r   get_running_loopr   r{   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"   rR   r=   r!   s     r   r"   zZLibCompressor.flush   s>     %%$D
 	
*.*<*<*E*E
 	
r   r   )r$   r%   r&   r   r   rk   r6   r(   r   rT   r'   r   r   r"   r   r   r   r   r      s     #'(-##"&'+-@D3-D "&D }	D
 }D 3-D 8$D &c]D6/% /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	e
f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 )ZLibDecompressorNFrp   rq   rx   ry   c                     t         |   ||       t        ||      | _        t	        t
        j                        | _        | j                  j                  | j                        | _        y )Nrx   ry   )r@   )	superrT   ru   r   rQ   rl   rR   rG   _decompressor)r   rp   rq   rx   ry   	__class__s        r   rT   zZLibDecompressor.__init__  sZ     	(@ST%h0GH
$6{7P7P$Q!//==DJJ=Or   r   r+   r   c                 :    | j                   j                  ||      S r   )r   r.   r-   s      r   r   z ZLibDecompressor.decompress_sync  s     !!,,T:>>r   r/   c                 v    |dkD  r| j                   j                  |      S | j                   j                         S )Nr   )r   r"   r1   s     r   r"   zZLibDecompressor.flush  s?     z $$V,	
 ##))+	
r   c                 .    | j                   j                  S r   )r   r4   r3   s    r   r4   zZLibDecompressor.eof  s    !!%%%r   )r   )r$   r%   r&   r   r   rk   r6   r   r(   rT   r   r   r'   r   r"   r5   r4   __classcell__r   s   @r   r   r     s     #'(-'+-@
P3-
P "&
P 8$	
P
 &c]
P /H??(+?	?

C 
 
 &T & &r   r   c                   b     e Zd Zdefdee   dee   ddf fdZefde	dede
fdZde
fd	Z xZS )
BrotliDecompressorNrx   ry   r   c                 |    t         st        d      t        j                         | _        t
        |   ||       y)z)Decompress data using the Brotli library.zIThe brotli decompression is not available. Please install `Brotli` moduler   N)
HAS_BROTLIRuntimeErrorbrotliDecompressor_objr   rT   r   rx   ry   r   s      r   rT   zBrotliDecompressor.__init__$  s?     1  '')	(@STr   r   r+   c                     t        | j                  d      r*t        t        | j                  j	                  ||            S t        t        | j                  j                  ||            S )r   r.   )hasattrr   r   r'   r.   processr-   s      r   r   z"BrotliDecompressor.decompress_sync2  sN     499l+tyy33D*EFFE499,,T:>??r   c                     t        | j                  d      r(t        t        | j                  j	                               S y)zFlush the decompressor.r"   r   )r   r   r   r'   r"   r3   s    r   r"   zBrotliDecompressor.flush:  s+    499g&tyy011r   )r$   r%   r&   r   r   r   r(   rT   r   r   r'   r   r"   r   r   s   @r   r   r      sl     (,-@U8$U &c]U 
	U /H@@(+@	@u r   r   c                   b     e Zd Zdefdee   dee   ddf fdZefde	dede	fdZ
de	fd	Z xZS )
ZSTDDecompressorNrx   ry   r   c                 h    t         st        d      t               | _        t        |   ||       y )NzOThe zstd decompression is not available. Please install `backports.zstd` moduler   )HAS_ZSTDr   r   r   r   rT   r   s      r   rT   zZSTDDecompressor.__init__B  s9    
 9  %&	(@STr   r   r+   c                 \    |t         k(  rt        n|}| j                  j                  ||      S r   )r   ZSTD_MAX_LENGTH_UNLIMITEDr   r.   )r   r   r+   zstd_max_lengths       r   r   z ZSTDDecompressor.decompress_syncO  s3     66 & 	
 yy##D/::r   c                      y)Nr   r   r3   s    r   r"   zZSTDDecompressor.flush[  s    r   )r$   r%   r&   r   r   r   r(   rT   r   r'   r   r"   r   r   s   @r   r   r   A  sh     (,-@U8$U &c]U 
	U .G
;
;'*
;	
;u r   r   )NF)2r   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   r   DEFAULT_MAX_DECOMPRESS_SIZEr   r   r   r*   r8   rN   rQ   rl   rL   ro   rk   r6   r(   ru   rw   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6s 6<H
 H
V&/ &<1 B/ _	    J  HsB   D D# D0 	D D# D  D# #D-,D-0D:9D: