
    Yj:                       U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	m
Z
 	 ddlZej                  r&ej                  dk\  r	ddlmZmZ nddlmZmZ ded	<   n#	 ej                  dk\  r	ddlmZmZ nddlmZmZ d
ZdZ G d dej.                        Z G d d      Z G d d      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d d       Z! G d! d"      Z" G d# d$      Z# G d% d&      Z$eeeeed'Z%d(ed)<   ee%jM                  d*       ese%jM                  d+       yy# e$ r 	 ddlZn# e$ r dZY nw xY wY :w xY w# e$ r dZY w xY w),zq
Handlers for Content-Encoding.

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
    )annotationsN   )DecodingError)      )ZstdDecompressor	ZstdErrorbool_zstandard_installedTFi   c                  .    e Zd Zedd       ZddZddZy)Decompressorc                     y N selfs    O/var/www/html/vmm-quimica/venv/lib/python3.12/site-packages/httpx2/_decoders.pyunconsumed_tailzDecompressor.unconsumed_tail8   s    (+    c                     y r   r   )r   data
max_lengths      r   
decompresszDecompressor.decompress;       r   c                     y r   r   r   s    r   flushzDecompressor.flush=   r   r   Nreturnbytes)r   r   r   intr   r   )__name__
__module____qualname__propertyr   r   r   r   r   r   r   r   7   s    + +D!r   r   c                  (    e Zd ZdZddZddZddZy)	ZlibDecompressorz
    Drain a `zlib`/`gzip` decompressor in bounded pieces so a small compressed
    input cannot inflate to an unbounded buffer in a single call.
    c                    || _         y r   )decompressor)r   r(   s     r   __init__zZlibDecompressor.__init__F   s
    (r   c              #     K   | j                   j                  |t              }|r<| | j                   j                  | j                   j                  t              }|r;y y wr   )r(   r   MAX_DECODE_CHUNK_SIZEr   )r   r   decompresseds      r   r   zZlibDecompressor.decompressI   sR     ((33D:OP,,778I8I8Y8Y[pqL s   AA" A"c                6    | j                   j                         S r   )r(   r   r   s    r   r   zZlibDecompressor.flushO   s      &&((r   N)r(   r   r   Noner   r   r   typing.Iterator[bytes]r   )r!   r"   r#   __doc__r)   r   r   r   r   r   r&   r&   @   s    
)r)r   r&   c                      e Zd ZddZddZy)ContentDecoderc                    t               r   NotImplementedErrorr   r   s     r   decodezContentDecoder.decodeT       !##r   c                    t               r   r5   r   s    r   r   zContentDecoder.flushW   r9   r   Nr/   r   r0   )r!   r"   r#   r8   r   r   r   r   r3   r3   S   s    $$r   r3   c                       e Zd ZdZddZddZy)IdentityDecoderz 
    Handle unencoded data.
    c              #     K   | y wr   r   r7   s     r   r8   zIdentityDecoder.decode`   s     
s   c              #  $   K   dE d {    y 7 wNr   r   r   s    r   r   zIdentityDecoder.flushc   s     s   Nr/   r;   )r!   r"   r#   r1   r8   r   r   r   r   r=   r=   [   s    r   r=   c                  (    e Zd ZdZddZddZddZy)	DeflateDecoderzZ
    Handle 'deflate' decoding.

    See: https://stackoverflow.com/questions/1838699
    c                V    d| _         t        t        j                               | _        y )NT)first_attemptr&   zlibdecompressobjr(   r   s    r   r)   zDeflateDecoder.__init__n   s     !,T-?-?-ABr   c              #    K   | j                   }d| _         	 | j                  j                  |      E d {    y 7 # t        j                  $ rn}|rMt        t        j                  t        j                               | _        | j                  |      E d {  7   nt        t        |            |Y d }~y d }~ww xY wwNF)rD   r(   r   rE   errorr&   rF   	MAX_WBITSr8   r   str)r   r   was_first_attemptexcs       r   r8   zDeflateDecoder.decoder   s      .."	7((33D999zz 	7 $4T5G5G5X$Y!;;t,,,#CH-36 -	7sD   C= ;= C= B>AB9BB94C9B>>Cc              #     K   	 | j                   j                          y # t        j                  $ r}t	        t        |            |d }~ww xY wwr   r(   r   rE   rI   r   rK   r   rM   s     r   r   zDeflateDecoder.flush~   D     	3##))++zz 	3C)s2	3$   A! AAA		AANr   r.   r/   r;   r!   r"   r#   r1   r)   r8   r   r   r   r   rB   rB   g   s    C
73r   rB   c                  (    e Zd ZdZddZddZddZy)	GZipDecoderzW
    Handle 'gzip' decoding.

    See: https://stackoverflow.com/questions/1838699
    c                l    t        t        j                  t        j                  dz              | _        y )N   )r&   rE   rF   rJ   r(   r   s    r   r)   zGZipDecoder.__init__   s$    ,T-?-?QS@S-TUr   c              #     K   	 | j                   j                  |      E d {    y 7 # t        j                  $ r}t	        t        |            |d }~ww xY wwr   )r(   r   rE   rI   r   rK   )r   r   rM   s      r   r8   zGZipDecoder.decode   sI     	3((33D999zz 	3C)s2	3s0   A* (* A* AAAAc              #     K   	 | j                   j                          y # t        j                  $ r}t	        t        |            |d }~ww xY wwr   rO   rP   s     r   r   zGZipDecoder.flush   rQ   rR   NrS   r/   r;   rT   r   r   r   rV   rV      s    V33r   rV   c                  (    e Zd ZdZddZddZddZy)	BrotliDecoderaT  
    Handle 'brotli' decoding.

    Requires `pip install brotlipy`. See: https://brotlipy.readthedocs.io/
        or   `pip install brotli`. See https://github.com/google/brotli
    Supports both 'brotlipy' and 'Brotli' packages since they share an import
    name. The top branches are for 'brotlipy' and bottom branches for 'Brotli'
    c                   t         t        d      d t        j                         | _        d| _        |  t        | j                  d      r| j                  j                  | _        y | j                  j                  | _        y )NzUsing 'BrotliDecoder', but neither of the 'brotlicffi' or 'brotli' packages have been installed. Make sure to install httpx using `pip install httpx[brotli]`.Fr   )	brotliImportErrorr   r(   	seen_datahasattrr   _decompressprocessr   s    r   r)   zBrotliDecoder.__init__   sv    >P 	 #//14$$l3#00;;D  $0088Dr   c              #     K   |sy d| _         	 t        dz  }| j                  ||      }|r| | j                  d|      }|ry y # t        j                  $ r}t        t        |            |d }~ww xY ww)NT   )output_buffer_limitr   )r`   r+   rb   r^   rI   r   rK   )r   r   rf   r,   rM   s        r   r8   zBrotliDecoder.decode   s     	3"71"<++DFY+ZL""#//I\/]  || 	3C)s2	3s(   A87A A8A5A00A55A8c              #     K   | j                   sy 	 t        | j                  d      r| j                  j                          dE d {    y # t        j
                  $ r}t        t        |            |d }~ww xY w7 5w)Nfinishr   )r`   ra   r(   rh   r^   rI   r   rK   rP   s     r   r   zBrotliDecoder.flush   sl     ~~		3t(((3 !!((*  || 	3C)s2	3s4   A>0A A>A<A>A9A44A99A>NrS   r/   r;   rT   r   r   r   r\   r\      s    9$3r   r\   c                  (    e Zd ZdZddZddZddZy)	ZStandardDecoderznHandle 'zstd' RFC 8878 decoding.

    On Python 3.13 and below, this requires `pip install httpx2[zstd]`.
    c                T    t         st        d      d t               | _        d| _        y )NzXUsing 'ZStandardDecoder', ...Make sure to install httpx using `pip install httpx[zstd]`.F)r   r_   r   r(   r`   r   s    r   r)   zZStandardDecoder.__init__   s,    #j -.r   c              #  |  K   |sy d| _         	 | j                  j                  r(| j                  j                  |z   }t	               | _        	 | j                  j                  |t              }|rT| | j                  j                  s| j                  j                  rn#| j                  j                  dt              }|rT| j                  j                  r| j                  j                  sy | j                  j                  }t	               | _        # t        $ r}t        t        |            |d }~ww xY ww)NTr   )r`   r(   eofunused_datar   r   r+   needs_inputr	   r   rK   )r   r   r,   rM   s       r   r8   zZStandardDecoder.decode   s    	3  $$((44t;$4$6!#00;;DBWX"&&((448I8I8M8M#'#4#4#?#?EZ#[L	 #
 ))--$2C2C2O2O((44$4$6!   	3C)s2	3s5   D<B4D ,D /D<0&D 	D9D44D99D<c              #     K   | j                   sy | j                  j                  st        d      dE d {    y 7 w)NzZstandard data is incompleter   )r`   r(   rm   r   r   s    r   r   zZStandardDecoder.flush   s2     ~~  $$ >??s   4><>NrS   r/   r;   rT   r   r   r   rj   rj      s    3,r   rj   c                  V    e Zd ZU dZdZded<   d
dZddZddZe		 	 	 	 	 	 dd       Z
y	)MultiDecoderzE
    Handle the case where multiple encodings have been applied.
       ztyping.ClassVar[int]max_decode_linksc                    |D cg c]  }|t         v s| }}t        |      | j                  kD  rt        d| j                   d      t	        |      D cg c]  }t        |           c}| _        yc c}w c c}w )zk
        'encodings' should be the content codings in the order in which
        each was applied.
        zCannot apply more than z content encodings.N)SUPPORTED_DECODERSlenrt   r   reversedchildren)r   	encodingsencodingcodingscodings        r   r)   zMultiDecoder.__init__  s|    
 -6XEW9W8XXw<$///"9$:O:O9PPc deeZbcjZk.lPV/A&/I/K.l	 Y /ms   A4A4A9c              #     K   t        |f      }| j                  D ]  }| j                  |j                  |      }  |E d {    y 7 wr   )iterry   _piper8   )r   r   streamschilds       r   r8   zMultiDecoder.decode  sA     *.w-]] 	8Ejjw7G	8s   ?A	AA	c              #     K   t        d      }| j                  D ]@  }t        j                  | j	                  |j
                  |      |j                               }B |E d {    y 7 wr@   )r   ry   	itertoolschainr   r8   r   )r   r   r   s      r   r   zMultiDecoder.flush  sR     *.r(]] 	XEoodjjw&GWG	Xs   A A*"A(#A*c              #  >   K   |D ]  } | |      E d {     y 7 wr   r   )r8   upstreamchunks      r   r   zMultiDecoder._pipe"  s'     
  	%Ee}$$	%$s   N)rz   ztyping.Sequence[str]r   r.   r/   r;   )r8   z0typing.Callable[[bytes], typing.Iterator[bytes]]r   r0   r   r0   )r!   r"   r#   r1   rt   __annotations__r)   r8   r   staticmethodr   r   r   r   rr   rr     sS     ./*.	m %@%(% 
 % %r   rr   c                  *    e Zd ZdZdddZddZd	dZy)
ByteChunkerz>
    Handles returning byte content in fixed-size chunks.
    Nc                D    t        j                         | _        || _        y r   )ioBytesIO_buffer_chunk_sizer   
chunk_sizes     r   r)   zByteChunker.__init__0  s    zz|%r   c                   | j                   |r|gS g S | j                  j                  |       | j                  j                         | j                   k\  r| j                  j	                         }t        dt        |      | j                         D cg c]  }|||| j                   z     }}t        |d         | j                   k(  r7| j                  j                  d       | j                  j                          |S | j                  j                  d       | j                  j                  |d          | j                  j                          |d d S g S c c}w Nr   	r   r   writetellgetvaluerangerw   seektruncater   contentvalueichunkss        r   r8   zByteChunker.decode4  !   # 'G9/R/7#<<$"2"22LL))+E?DQE
TXTdTd?ef!eAD$4$4 45fFf6":$"2"22!!!$%%'!!!$""6":.%%'cr{"I g   Ec                    | j                   j                         }| j                   j                  d       | j                   j                          |r|gS g S Nr   r   r   r   r   r   r   s     r   r   zByteChunker.flushH  E    %%'!w'R'r   r   r   z
int | Noner   r.   )r   r   r   list[bytes])r   r   rT   r   r   r   r   r   +      &((r   r   c                  *    e Zd ZdZdddZddZd	dZy)
TextChunkerz>
    Handles returning text content in fixed-size chunks.
    Nc                D    t        j                         | _        || _        y r   )r   StringIOr   r   r   s     r   r)   zTextChunker.__init__T  s    {{}%r   c                   | j                   |r|gS g S | j                  j                  |       | j                  j                         | j                   k\  r| j                  j	                         }t        dt        |      | j                         D cg c]  }|||| j                   z     }}t        |d         | j                   k(  r7| j                  j                  d       | j                  j                          |S | j                  j                  d       | j                  j                  |d          | j                  j                          |d d S g S c c}w r   r   r   s        r   r8   zTextChunker.decodeX  r   r   c                    | j                   j                         }| j                   j                  d       | j                   j                          |r|gS g S r   r   r   s     r   r   zTextChunker.flushl  r   r   r   r   )r   rK   r   	list[str]r   r   rT   r   r   r   r   r   O  r   r   r   c                  *    e Zd ZdZdddZddZd	dZy)
TextDecoderz8
    Handles incrementally decoding bytes into text
    c                F     t        j                  |      d      | _        y )Nreplace)errors)codecsgetincrementaldecoderdecoder)r   r{   s     r   r)   zTextDecoder.__init__x  s    =v33H=YOr   c                8    | j                   j                  |      S r   r   r8   r7   s     r   r8   zTextDecoder.decode{  s    ||""4((r   c                :    | j                   j                  dd      S )Nr   Tr   r   s    r   r   zTextDecoder.flush~  s    ||""3--r   N)zutf-8)r{   rK   r   r.   )r   r   r   rK   )r   rK   rT   r   r   r   r   r   s  s    P).r   r   c                  (    e Zd ZdZddZddZddZy)	LineDecoderz
    Handles incrementally reading lines from text.

    Has the same behaviour as the stdllib splitlines,
    but handling the input iteratively.
    c                     g | _         d| _        y rH   )buffertrailing_crr   s    r   r)   zLineDecoder.__init__  s    !#!&r   c                   d}| j                   rd|z   }d| _         |j                  d      rd| _         |d d }|sg S |d   |v }|j                         }t        |      dk(  r"|s | j                  j                  |d          g S | j                  r/dj                  | j                        |d   z   g|dd  z   }g | _        |s|j                         g| _        |S )	Nu   
  FTr   r   r    )r   endswith
splitlinesrw   r   appendjoinpop)r   textNEWLINE_CHARStrailing_newlineliness        r   r8   zLineDecoder.decode  s    B $;D$D==#D9D I8}4!u:?#3KKuQx(I;; WWT[[)E!H45ab	AEDK !99;-DKr   c                    | j                   s| j                  sg S dj                  | j                         g}g | _         d| _        |S )Nr   F)r   r   r   )r   r   s     r   r   zLineDecoder.flush  s?    {{4#3#3I%& r   NrS   )r   rK   r   r   r   rT   r   r   r   r   r     s    '$Lr   r   )identitygzipdeflatebrzstdzdict[str, type[ContentDecoder]]rv   r   r   )'r1   
__future__r   r   r   r   systypingrE   _exceptionsr   r^   r_   
brotlicffiTYPE_CHECKINGversion_infocompression.zstdr   r	   backports.zstdr   r   r+   Protocolr   r&   r3   r=   rB   rV   r\   rj   rr   r   r   r   r   rv   r   r   r   r   <module>r      s   #  	  
   &	 

7"@@>%w&DDB#
  "6?? ") )&$ $	n 	3^ 3<3. 3.7N 7t+~ +\$%> $%N!( !(H!( !(H. .9 9z  
7 3  
>4 6" g   	$ 4  %$%sG   E  "E+ E(EE(E!E( E!!E('E(+E54E5