
     j,                       S r SSKJr  SSKrSSKrSSKrSSKrSSKJrJ	r	  SSK
Jr   " S S5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S5      r " S S5      r " S S5      r " S S5      r\\\\\S.r\c  \R1                  S5        \	c  \R1                  S5        gg) zq
Handlers for Content-Encoding.

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
    )annotationsN   )brotlizstd)DecodingErrorc                  (    \ rS rSrSS jrSS jrSrg)ContentDecoder   c                    [        5       eNNotImplementedErrorselfdatas     Y/home/ubuntu/second-brain/public-api/venv/lib/python3.13/site-packages/httpx/_decoders.pydecodeContentDecoder.decode       !##    c                    [        5       er   r   r   s    r   flushContentDecoder.flush   r   r    Nr   bytesreturnr   r   r   )__name__
__module____qualname____firstlineno__r   r   __static_attributes__r   r   r   r	   r	      s    $$r   r	   c                  ,    \ rS rSrSrSS jrSS jrSrg)	IdentityDecoder   z
Handle unencoded data.
c                    U$ r   r   r   s     r   r   IdentityDecoder.decode   s    r   c                    gNr   r   r   s    r   r   IdentityDecoder.flush"   s    r   r   Nr   r   )r    r!   r"   r#   __doc__r   r   r$   r   r   r   r&   r&      s    r   r&   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)DeflateDecoder&   zN
Handle 'deflate' decoding.

See: https://stackoverflow.com/questions/1838699
c                F    SU l         [        R                  " 5       U l        g )NT)first_attemptzlibdecompressobjdecompressorr   s    r   __init__DeflateDecoder.__init__-   s    ! ..0r   c                P   U R                   nSU l          U R                  R                  U5      $ ! [        R                   aa  nU(       a@  [        R
                  " [        R                  * 5      U l        U R                  U5      s S nA$ [        [        U5      5      UeS nAff = fNF)
r2   r5   
decompressr3   errorr4   	MAX_WBITSr   r   str)r   r   was_first_attemptexcs       r   r   DeflateDecoder.decode1   s     .."	3$$//55zz 	3 $($6$6$G!{{4((C)s2		3s"   0 B%AB B%B  B%c                     U R                   R                  5       $ ! [        R                   a  n[	        [        U5      5      UeS nAff = fr   r5   r   r3   r;   r   r=   r   r?   s     r   r   DeflateDecoder.flush<   A    	3$$**,,zz 	3C)s2	3    A
AA
)r5   r2   Nr   Noner   r   	r    r!   r"   r#   r-   r6   r   r   r$   r   r   r   r/   r/   &   s    1	33r   r/   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)GZipDecoderC   zK
Handle 'gzip' decoding.

See: https://stackoverflow.com/questions/1838699
c                \    [         R                  " [         R                  S-  5      U l        g )N   )r3   r4   r<   r5   r   s    r   r6   GZipDecoder.__init__J   s     ..t~~/BCr   c                     U R                   R                  U5      $ ! [        R                   a  n[	        [        U5      5      UeS nAff = fr   )r5   r:   r3   r;   r   r=   r   r   r?   s      r   r   GZipDecoder.decodeM   sC    	3$$//55zz 	3C)s2	3s    AAAc                     U R                   R                  5       $ ! [        R                   a  n[	        [        U5      5      UeS nAff = fr   rB   rC   s     r   r   GZipDecoder.flushS   rE   rF   r5   NrG   r   r   rI   r   r   r   rK   rK   C   s    D33r   rK   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)BrotliDecoderZ   a<  
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                   [         c  [        S5      S e[         R                  " 5       U l        SU l        U   [        U R                  S5      (       a  U R                  R                  U l        g U R                  R                  U l        g )NzUsing 'BrotliDecoder', but neither of the 'brotlicffi' or 'brotli' packages have been installed. Make sure to install httpx using `pip install httpx[brotli]`.Fr:   )	r   ImportErrorDecompressorr5   	seen_datahasattrr:   _decompressprocessr   s    r   r6   BrotliDecoder.__init__d   sy    >P 	 #//14$$l33#00;;D  $0088Dr   c                    U(       d  gSU l          U R                  U5      $ ! [        R                   a  n[	        [        U5      5      UeS nAff = fNr   T)r\   r^   r   r;   r   r=   rQ   s      r   r   BrotliDecoder.decodev   sJ    	3##D))|| 	3C)s2	3s   " AAAc                    U R                   (       d  g [        U R                  S5      (       a  U R                  R                  5         g! [        R
                   a  n[        [        U5      5      UeS nAff = f)Nr   finish)r\   r]   r5   re   r   r;   r   r=   rC   s     r   r   BrotliDecoder.flush   s`    ~~
	3t(((33 !!((*|| 	3C)s2	3s   5A
 
A8A33A8)r^   r5   r\   NrG   r   r   rI   r   r   r   rW   rW   Z   s    9$33r   rW   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)ZStandardDecoder   z
Handle 'zstd' RFC 8878 decoding.

Requires `pip install zstandard`.
Can be installed as a dependency of httpx using `pip install httpx[zstd]`.
c                z    [         c  [        S5      S e[         R                  " 5       R                  5       U l        g )NzXUsing 'ZStandardDecoder', ...Make sure to install httpx using `pip install httpx[zstd]`.)r   rZ   ZstdDecompressorr4   r5   r   s    r   r6   ZStandardDecoder.__init__   s;    <N 
 !113AACr   c                   [         c   e[        R                  " 5       n UR                  U R                  R                  U5      5        U R                  R                  (       a  U R                  R                  (       a  U R                  R                  n[         R                  " 5       R                  5       U l        UR                  U R                  R                  U5      5        U R                  R                  (       a  U R                  R                  (       a  M  UR                  5       $ ! [         R                   a  n[        [        U5      5      UeS nAff = fr   )r   ioBytesIOwriter5   r:   eofunused_datark   r4   	ZstdErrorr   r=   getvalue)r   r   outputrr   r?   s        r   r   ZStandardDecoder.decode   s    	3LL**55d;<##''D,=,=,I,I"//;;$($9$9$;$I$I$K!T..99+FG ##''D,=,=,I,I,I    ~~ 	3C)s2	3s   C>D0 0EEEc                    U R                   R                  5       nU R                   R                  (       d  [        S5      e[	        U5      $ )NzZstandard data is incomplete)r5   r   rq   r   r   )r   rets     r   r   ZStandardDecoder.flush   s;    %%'  $$ >??Szr   rU   NrG   r   r   rI   r   r   r   rh   rh      s    D!r   rh   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)MultiDecoder   z=
Handle the case where multiple encodings have been applied.
c                6    [        [        U5      5      U l        g)zU
'children' should be a sequence of decoders in the order in which
each was applied.
N)listreversedchildren)r   r   s     r   r6   MultiDecoder.__init__   s     Xh/0r   c                N    U R                    H  nUR                  U5      nM     U$ r   )r   r   r   r   childs      r   r   MultiDecoder.decode   s#    ]]E<<%D #r   c                t    SnU R                    H%  nUR                  U5      UR                  5       -   nM'     U$ r+   )r   r   r   r   s      r   r   MultiDecoder.flush   s3    ]]E<<%5D #r   )r   N)r   ztyping.Sequence[ContentDecoder]r   rH   r   r   rI   r   r   r   r{   r{      s    1
r   r{   c                  :    \ rS rSrSrSS	S jjrS
S jrSS jrSrg)ByteChunker   z6
Handles returning byte content in fixed-size chunks.
Nc                D    [         R                  " 5       U l        Xl        g r   )rn   ro   _buffer_chunk_sizer   
chunk_sizes     r   r6   ByteChunker.__init__   s    zz|%r   c                   U R                   c  U(       a  U/$ / $ U R                  R                  U5        U R                  R                  5       U R                   :  Ga  U R                  R	                  5       n[        S[        U5      U R                   5       Vs/ s H  nX#X0R                   -    PM     nn[        US   5      U R                   :X  a7  U R                  R                  S5        U R                  R                  5         U$ U R                  R                  S5        U R                  R                  US   5        U R                  R                  5         US S $ / $ s  snf Nr   	r   r   rp   tellrt   rangelenseektruncater   contentvalueichunkss        r   r   ByteChunker.decode   ,   # 'G9/R/7#<<$"2"22LL))+E q#e*d.>.>??A !.../?   6":$"2"22!!!$%%'!!!$""6":.%%'cr{"I   E#c                    U R                   R                  5       nU R                   R                  S5        U R                   R                  5         U(       a  U/$ / $ Nr   r   rt   r   r   r   r   s     r   r   ByteChunker.flush   E    %%'!w'R'r   r   r   r   r   z
int | Noner   rH   )r   r   r   list[bytes])r   r   rI   r   r   r   r   r          &.(r   r   c                  :    \ rS rSrSrSS	S jjrS
S jrSS jrSrg)TextChunker   z6
Handles returning text content in fixed-size chunks.
Nc                D    [         R                  " 5       U l        Xl        g r   )rn   StringIOr   r   r   s     r   r6   TextChunker.__init__   s    {{}%r   c                   U R                   c  U(       a  U/$ / $ U R                  R                  U5        U R                  R                  5       U R                   :  Ga  U R                  R	                  5       n[        S[        U5      U R                   5       Vs/ s H  nX#X0R                   -    PM     nn[        US   5      U R                   :X  a7  U R                  R                  S5        U R                  R                  5         U$ U R                  R                  S5        U R                  R                  US   5        U R                  R                  5         US S $ / $ s  snf r   r   r   s        r   r   TextChunker.decode   r   r   c                    U R                   R                  5       nU R                   R                  S5        U R                   R                  5         U(       a  U/$ / $ r   r   r   s     r   r   TextChunker.flush  r   r   r   r   r   )r   r=   r   	list[str]r   r   rI   r   r   r   r   r      r   r   r   c                  :    \ rS rSrSrSS	S jjrS
S jrSS jrSrg)TextDecoderi  z0
Handles incrementally decoding bytes into text
c                B    [         R                  " U5      " SS9U l        g )Nreplace)errors)codecsgetincrementaldecoderdecoder)r   encodings     r   r6   TextDecoder.__init__!  s    33H=YOr   c                8    U R                   R                  U5      $ r   r   r   r   s     r   r   TextDecoder.decode$  s    ||""4((r   c                :    U R                   R                  SS5      $ rb   r   r   s    r   r   TextDecoder.flush'  s    ||""3--r   )r   N)zutf-8)r   r=   r   rH   )r   r   r   r=   )r   r=   rI   r   r   r   r   r     s    P).r   r   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)LineDecoderi+  z
Handles incrementally reading lines from text.

Has the same behaviour as the stdllib splitlines,
but handling the input iteratively.
c                     / U l         SU l        g r9   buffertrailing_crr   s    r   r6   LineDecoder.__init__3  s    !#!&r   c                   SnU R                   (       a  SU-   nSU l         UR                  S5      (       a  SU l         US S nU(       d  / $ US   U;   nUR                  5       n[        U5      S:X  a'  U(       d   U R                  R                  US   5        / $ U R                  (       a/  SR                  U R                  5      US   -   /USS  -   n/ U l        U(       d  UR                  5       /U l        U$ )	Nu   
  FTr   r   r    )r   endswith
splitlinesr   r   appendjoinpop)r   textNEWLINE_CHARStrailing_newlineliness        r   r   LineDecoder.decode7  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                    U R                   (       d  U R                  (       d  / $ SR                  U R                   5      /n/ U l         SU l        U$ )Nr   F)r   r   r   )r   r   s     r   r   LineDecoder.flush]  s?    {{4#3#3I%& r   r   NrG   )r   r=   r   r   r   rI   r   r   r   r   r   +  s    '$Lr   r   )identitygzipdeflatebrr   r   r   )r-   
__future__r   r   rn   typingr3   _compatr   r   _exceptionsr   r	   r&   r/   rK   rW   rh   r{   r   r   r   r   SUPPORTED_DECODERSr   r   r   r   <module>r      s    #  	   ! &$ $	n 	3^ 3:3. 3.23N 23j#~ #L> 2$( $(N$( $(N. .9 9z  
  
>4 <6" r   