
    g1                         d dl Z d dlZd dlmZ d dlmZmZ 	 	 d dlZdZ
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y# e	$ r d dlZY Jw xY w# e	$ r dZ
Y Uw xY w)    N)Executor)OptionalcastTFi   encodingsuppress_deflate_headerreturnc                 x    | dk(  rdt         j                  z   S |rt         j                   S t         j                  S )Ngzip   )zlib	MAX_WBITS)r   r   s     N/var/www/openai/venv/lib/python3.12/site-packages/aiohttp/compression_utils.pyencoding_to_moder      s2     6DNN""5DNN?I4>>I    c                   2    e Zd Zdefdedee   dee   fdZy)ZlibBaseHandlerNmodeexecutormax_sync_chunk_sizec                 .    || _         || _        || _        y N)_mode	_executor_max_sync_chunk_size)selfr   r   r   s       r   __init__zZlibBaseHandler.__init__   s     
!$7!r   )__name__
__module____qualname__MAX_SYNC_CHUNK_SIZEintr   r   r    r   r   r   r      s4     (,-@	88 8$8 &c]	8r   r   c                        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
ZdedefdZdedefdZej                  fde	defdZ xZS )ZLibCompressorNFr   r   levelwbitsstrategyr   r   c                    t         |   |t        ||      n|||       |'t        j                  | j
                  |      | _        n't        j                  | j
                  ||      | _        t        j                         | _	        y )Nr   r   r   )r&   r'   )r&   r'   r%   )
superr   r   r   compressobjr   _compressorasyncioLock_compress_lock)	r   r   r   r%   r&   r'   r   r   	__class__s	           r   r   zZLibCompressor.__init__*   s     	 = !+BC 3 	 	
 =#//djj8TD#//jj85 D &llnr   datar   c                 8    | j                   j                  |      S r   )r,   compressr   r1   s     r   compress_synczZLibCompressor.compress_syncE   s    ((..r   c                   K   | j                   4 d{    | j                  tt        |      | j                  kD  r\t        j                         j                  | j                  | j                  j                  |       d{   cddd      d{    S | j                  |      cddd      d{    S 7 7 97 +7 # 1 d{  7  sw Y   yxY ww)aC  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.
        N)
r/   r   lenr-   get_running_looprun_in_executorr   r,   r3   r5   r4   s     r   r3   zZLibCompressor.compressH   s      &&& ))5I 9 99$557GGNND$4$4$=$=t  '&& %%d+ '&& '&&&&su   CB:CA+CB<CCB>CC(C4C 5C<C>C CCC	CCr   c                 8    | j                   j                  |      S r   )r,   flush)r   r   s     r   r;   zZLibCompressor.flush_   s    %%d++r   )r   r   r   r   Z_DEFAULT_STRATEGYr    r   strboolr!   r   r   bytesr5   r3   Z_FINISHr;   __classcell__r0   s   @r   r$   r$   )   s     #'(-##//'+-@-3-- "&- }	-
 }- - 8$- &c]-6/% /E /,5 ,U ,. !% ,# ,% ,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ed
e
fd       Zed
e
fd       Z xZS )ZLibDecompressorNFr   r   r   r   c                     t         |   t        ||      ||       t        j                  | j
                        | _        y )Nr)   )r&   )r*   r   r   r   decompressobjr   _decompressor)r   r   r   r   r   r0   s        r   r   zZLibDecompressor.__init__d   sA     	!(,CD 3 	 	

 "//djjAr   r1   
max_lengthr   c                 :    | j                   j                  ||      S r   )rG   
decompressr   r1   rH   s      r   decompress_syncz ZLibDecompressor.decompress_syncr   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   r7   r-   r8   r9   r   rG   rJ   rL   rK   s      r   rJ   zZLibDecompressor.decompressu   sz      %%1D	D555 113CC 2 2 = =tZ   ##D*55s   A,B.B/Blengthc                 v    |dkD  r| j                   j                  |      S | j                   j                         S )Nr   )rG   r;   )r   rN   s     r   r;   zZLibDecompressor.flush   s?     z $$V,	
 ##))+	
r   c                 .    | j                   j                  S r   )rG   eofr   s    r   rQ   zZLibDecompressor.eof   s    !!%%%r   c                 .    | j                   j                  S r   )rG   unconsumed_tailrR   s    r   rT   z ZLibDecompressor.unconsumed_tail   s    !!111r   c                 .    | j                   j                  S r   )rG   unused_datarR   s    r   rV   zZLibDecompressor.unused_data   s    !!---r   )r   )r   r   r   r    r   r=   r>   r   r!   r   r?   rL   rJ   r;   propertyrQ   rT   rV   rA   rB   s   @r   rD   rD   c   s     #'(-'+-@B3-B "&B 8$	B
 &c]B?E ?s ?5 ?6U 6 6E 6 
C 
 
 &T & & 2 2 2 .U . .r   rD   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_objrR   s    r   r   zBrotliDecompressor.__init__   s)    1  '')	r   r1   c                     t        | j                  d      r)t        t        | j                  j	                  |            S t        t        | j                  j                  |            S )NrJ   )hasattrr_   r   r?   rJ   processr4   s     r   rL   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   )ra   r_   r   r?   r;   rR   s    r   r;   zBrotliDecompressor.flush   s+    499g&tyy011r   )r   N)r   r   r   r   r?   rL   r;   r"   r   r   rY   rY      s&    *4E 4e 4
u r   rY   )NF)r-   r   concurrent.futuresr   typingr   r   
brotlicffir]   ImportErrorr[   r    r=   r>   r!   r   r   r$   rD   rY   r"   r   r   <module>rh      s      ' !# J   #$)JsmJ!J 	J	8 	87,_ 7,t3. 3.l a    Js.   A A+ 	A(%A+ 'A((A+ +A54A5