
    +DCf&                    T   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mZ ddl	m
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      Z G d d      Z G d d      Z G d d      ZeeeedZeej-                  d       yy)zq
Handlers for Content-Encoding.

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
    )annotationsN   )brotli)DecodingErrorc                      e Zd ZddZddZy)ContentDecoderc                    t               NNotImplementedErrorselfdatas     O/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/httpx/_decoders.pydecodezContentDecoder.decode       !##    c                    t               r
   r   r   s    r   flushzContentDecoder.flush   r   r   Nr   bytesreturnr   r   r   )__name__
__module____qualname__r   r    r   r   r   r      s    $$r   r   c                       e Zd ZdZddZddZy)IdentityDecoderz 
    Handle unencoded data.
    c                    |S r
   r   r   s     r   r   zIdentityDecoder.decode   s    r   c                     yNr   r   r   s    r   r   zIdentityDecoder.flush!   s    r   Nr   r   )r   r   r   __doc__r   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                D    d| _         t        j                         | _        y )NT)first_attemptzlibdecompressobjdecompressorr   s    r   __init__zDeflateDecoder.__init__,   s    ! ..0r   c                B   | j                   }d| _         	 | j                  j                  |      S # t        j                  $ r[}|r?t        j
                  t        j                         | _        | j                  |      cY d }~S t        t        |            |d }~ww xY wNF)
r(   r+   
decompressr)   errorr*   	MAX_WBITSr   r   str)r   r   was_first_attemptexcs       r   r   zDeflateDecoder.decode0   s     .."	3$$//55zz 	3 $($6$6$G!{{4((C)s2		3s!   0 B;B>BBBc                    	 | j                   j                         S # t        j                  $ r}t	        t        |            |d }~ww xY wr
   r+   r   r)   r0   r   r2   r   r4   s     r   r   zDeflateDecoder.flush;   A    	3$$**,,zz 	3C)s2	3    A	AA	Nr   Noner   r   r   r   r   r$   r,   r   r   r   r   r   r&   r&   %   s    1	33r   r&   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                Z    t        j                  t         j                  dz        | _        y )N   )r)   r*   r1   r+   r   s    r   r,   zGZipDecoder.__init__I   s     ..t~~/BCr   c                    	 | j                   j                  |      S # t        j                  $ r}t	        t        |            |d }~ww xY wr
   )r+   r/   r)   r0   r   r2   r   r   r4   s      r   r   zGZipDecoder.decodeL   sC    	3$$//55zz 	3C)s2	3s    A
AA
c                    	 | j                   j                         S # t        j                  $ r}t	        t        |            |d }~ww xY wr
   r6   r7   s     r   r   zGZipDecoder.flushR   r8   r9   Nr:   r   r   r<   r   r   r   r>   r>   B   s    D33r   r>   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/   )	r   ImportErrorDecompressorr+   	seen_datahasattrr/   _decompressprocessr   s    r   r,   zBrotliDecoder.__init__c   sv    >P 	 #//14$$l3#00;;D  $0088Dr   c                    |syd| _         	 | j                  |      S # t        j                  $ r}t	        t        |            |d }~ww xY wNr   T)rI   rK   r   r0   r   r2   rB   s      r   r   zBrotliDecoder.decodeu   sJ    	3##D))|| 	3C)s2	3s    A
AA
c                    | j                   sy	 t        | j                  d      r| j                  j                          y# t        j
                  $ r}t        t        |            |d }~ww xY w)Nr   finish)rI   rJ   r+   rP   r   r0   r   r2   r7   s     r   r   zBrotliDecoder.flush~   s]    ~~
	3t(((3 !!((*|| 	3C)s2	3s   0A   A-A((A-Nr:   r   r   r<   r   r   r   rE   rE   Y   s    9$33r   rE   c                  (    e Zd ZdZddZddZddZy)	MultiDecoderzE
    Handle the case where multiple encodings have been applied.
    c                6    t        t        |            | _        y)zm
        'children' should be a sequence of decoders in the order in which
        each was applied.
        N)listreversedchildren)r   rV   s     r   r,   zMultiDecoder.__init__   s     Xh/0r   c                J    | j                   D ]  }|j                  |      } |S r
   )rV   r   r   r   childs      r   r   zMultiDecoder.decode   s(    ]] 	&E<<%D	&r   c                p    d}| j                   D ]$  }|j                  |      |j                         z   }& |S r#   )rV   r   r   rX   s      r   r   zMultiDecoder.flush   s8    ]] 	6E<<%5D	6r   N)rV   ztyping.Sequence[ContentDecoder]r   r;   r   r   r<   r   r   r   rR   rR      s    1
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__   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   	ra   r`   writetellgetvaluerangelenseektruncater   contentvalueichunkss        r   r   zByteChunker.decode   -   # 'G9/R/7#<<$"2"22LL))+E q#e*d.>.>? a!d.../F  6":$"2"22!!!$%%'!!!$""6":.%%'cr{"I   Ec                    | j                   j                         }| j                   j                  d       | j                   j                          |r|gS g S Nr   r`   rj   rm   rn   r   rq   s     r   r   zByteChunker.flush   E    %%'!w'R'r   r
   rc   z
int | Noner   r;   )rp   r   r   list[bytes])r   r|   r<   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`   ra   rb   s     r   r,   zTextChunker.__init__   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 re   rg   ro   s        r   r   zTextChunker.decode   rt   ru   c                    | j                   j                         }| j                   j                  d       | j                   j                          |r|gS g S rw   rx   ry   s     r   r   zTextChunker.flush   rz   r   r
   r{   )rp   r2   r   	list[str]r   r   r<   r   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)
TextDecoderz8
    Handles incrementally decoding bytes into text
    c                F     t        j                  |      d      | _        y )Nreplace)errors)codecsgetincrementaldecoderdecoder)r   encodings     r   r,   zTextDecoder.__init__   s    =v33H=YOr   c                8    | j                   j                  |      S r
   r   r   r   s     r   r   zTextDecoder.decode   s    ||""4((r   c                :    | j                   j                  dd      S rN   r   r   s    r   r   zTextDecoder.flush   s    ||""3--r   N)zutf-8)r   r2   r   r;   )r   r   r   r2   )r   r2   r<   r   r   r   r   r      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 r.   )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   
  FTrf   r   r    )r   endswith
splitlinesrl   r   appendjoinpop)r   textNEWLINE_CHARStrailing_newlineliness        r   r   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.flush6  s?    {{4#3#3I%& r   Nr:   )r   r2   r   r   r   r<   r   r   r   r   r     s    '$Lr   r   )identitygzipdeflatebrr   )r$   
__future__r   r   r^   typingr)   _compatr   _exceptionsr   r   r    r&   r>   rE   rR   r\   r   r   r   SUPPORTED_DECODERSr   r   r   r   <module>r      s   
 #  	    &$ $	n 	3^ 3:3. 3.23N 23j> 2$( $(N$( $(N. .9 9z  
	  
>4  r   