
    Ng,                       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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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ee                    d           e	e                    d           dS dS ) zq
Handlers for Content-Encoding.

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
    )annotationsN   )brotlizstd)DecodingErrorc                      e Zd ZddZddZdS )	ContentDecoderdatabytesreturnc                    t                      NNotImplementedErrorselfr
   s     K/var/www/html/ai-engine/env/lib/python3.11/site-packages/httpx/_decoders.pydecodezContentDecoder.decode       !###    c                    t                      r   r   r   s    r   flushzContentDecoder.flush   r   r   Nr
   r   r   r   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dS )
IdentityDecoderz 
    Handle unencoded data.
    r
   r   r   c                    |S r   r   r   s     r   r   zIdentityDecoder.decode   s    r   c                    dS Nr   r   r   s    r   r   zIdentityDecoder.flush"   s    sr   Nr   r   )r   r   r   __doc__r   r   r   r   r   r!   r!      sF                 r   r!   c                  *    e Zd ZdZd
dZddZddZd	S )DeflateDecoderzZ
    Handle 'deflate' decoding.

    See: https://stackoverflow.com/questions/1838699
    r   Nonec                D    d| _         t          j                    | _        d S )NT)first_attemptzlibdecompressobjdecompressorr   s    r   __init__zDeflateDecoder.__init__-   s!    ! .00r   r
   r   c                <   | j         }d| _         	 | j                            |          S # t          j        $ rb}|r>t          j        t          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.decode1   s     ."	3$//555z 	3 	3 	3  )$($6$G$G!{{4((((((((C))s2		3s    * B:B3B9BBc                    	 | j                                         S # t          j        $ r"}t	          t          |                    |d }~ww xY wr   r-   r   r+   r2   r   r4   r   r6   s     r   r   zDeflateDecoder.flush<   S    	3$**,,,z 	3 	3 	3C))s2	3    AAANr   r(   r   r   r   r   r   r%   r.   r   r   r   r   r   r'   r'   &   sZ         1 1 1 1	3 	3 	3 	33 3 3 3 3 3r   r'   c                  *    e Zd ZdZd
dZddZddZd	S )GZipDecoderzW
    Handle 'gzip' decoding.

    See: https://stackoverflow.com/questions/1838699
    r   r(   c                R    t          j        t           j        dz            | _        d S )N   )r+   r,   r3   r-   r   s    r   r.   zGZipDecoder.__init__J   s"     .t~/BCCr   r
   r   c                    	 | j                             |          S # t          j        $ r"}t	          t          |                    |d }~ww xY wr   )r-   r1   r+   r2   r   r4   r   r
   r6   s      r   r   zGZipDecoder.decodeM   sU    	3$//555z 	3 	3 	3C))s2	3s    AAAc                    	 | j                                         S # t          j        $ r"}t	          t          |                    |d }~ww xY wr   r8   r9   s     r   r   zGZipDecoder.flushS   r:   r;   Nr<   r   r   r=   r   r   r   r?   r?   C   s^         D D D D3 3 3 33 3 3 3 3 3r   r?   c                  *    e Zd ZdZd
dZddZddZd	S )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'
    r   r(   c                    t           t          d          d t          j                    | _        d| _        |  t          | j        d          r| j        j        | _        d S | j        j        | _        d S )NzUsing 'BrotliDecoder', but neither of the 'brotlicffi' or 'brotli' packages have been installed. Make sure to install httpx using `pip install httpx[brotli]`.Fr1   )	r   ImportErrorDecompressorr-   	seen_datahasattrr1   _decompressprocessr   s    r   r.   zBrotliDecoder.__init__d   s    >P  	 #/1194$l33 	9#0;D  $08Dr   r
   r   c                    |sdS d| _         	 |                     |          S # t          j        $ r"}t	          t          |                    |d }~ww xY wNr   T)rJ   rL   r   r2   r   r4   rC   s      r   r   zBrotliDecoder.decodev   sf     	3	3##D)))| 	3 	3 	3C))s2	3s   " AAAc                    | j         sdS 	 t          | j        d          r| j                                         dS # t          j        $ r"}t          t          |                    |d }~ww xY w)Nr   finish)rJ   rK   r-   rQ   r   r2   r   r4   r9   s     r   r   zBrotliDecoder.flush   s~    ~ 	3
	3t((33 + !((***3| 	3 	3 	3C))s2	3s   .; A,
A''A,Nr<   r   r   r=   r   r   r   rF   rF   Z   sZ         9 9 9 9$3 3 3 33 3 3 3 3 3r   rF   c                  *    e Zd ZdZd
dZddZddZd	S )ZStandardDecoderz
    Handle 'zstd' RFC 8878 decoding.

    Requires `pip install zstandard`.
    Can be installed as a dependency of httpx using `pip install httpx[zstd]`.
    r   r(   c                    t           t          d          d t          j                                                    | _        d S )NzXUsing 'ZStandardDecoder', ...Make sure to install httpx using `pip install httpx[zstd]`.)r   rH   ZstdDecompressorr,   r-   r   s    r   r.   zZStandardDecoder.__init__   sI    <N  
 !133AACCr   r
   r   c                N   t           J t          j                    }	 |                    | j                            |                     | j        j        r| j        j        r{| j        j        }t          j                    	                                | _        |                    | j                            |                     | j        j        r| j        j        {n4# t           j
        $ r"}t          t          |                    |d }~ww xY w|                                S r   )r   ioBytesIOwriter-   r1   eofunused_datarU   r,   	ZstdErrorr   r4   getvalue)r   r
   outputr[   r6   s        r   r   zZStandardDecoder.decode   s   	3LL*55d;;<<<#' HD,=,I H"/;$($9$;$;$I$I$K$K!T.99+FFGGG #' HD,=,I H ~ 	3 	3 	3C))s2	3   s   C C D.DDc                    | j                                         }| j         j        st          d          t	          |          S )NzZstandard data is incomplete)r-   r   rZ   r   r   )r   rets     r   r   zZStandardDecoder.flush   s@    %%'' $ 	@ >???Szzr   Nr<   r   r   r=   r   r   r   rS   rS      s^         D D D D! ! ! !     r   rS   c                  *    e Zd ZdZddZdd	Zdd
ZdS )MultiDecoderzE
    Handle the case where multiple encodings have been applied.
    childrentyping.Sequence[ContentDecoder]r   r(   c                H    t          t          |                    | _        dS )zm
        'children' should be a sequence of decoders in the order in which
        each was applied.
        N)listreversedrc   )r   rc   s     r   r.   zMultiDecoder.__init__   s     Xh//00r   r
   r   c                D    | j         D ]}|                    |          }|S r   )rc   r   r   r
   childs      r   r   zMultiDecoder.decode   s+    ] 	& 	&E<<%%DDr   c                r    d}| j         D ],}|                    |          |                                z   }-|S r$   )rc   r   r   ri   s      r   r   zMultiDecoder.flush   s=    ] 	6 	6E<<%%5DDr   N)rc   rd   r   r(   r   r   r=   r   r   r   rb   rb      sZ         1 1 1 1   
     r   rb   c                  ,    e Zd ZdZdddZddZddZdS )ByteChunkerz>
    Handles returning byte content in fixed-size chunks.
    N
chunk_size
int | Noner   r(   c                D    t          j                    | _        || _        d S r   )rW   rX   _buffer_chunk_sizer   rn   s     r   r.   zByteChunker.__init__   s    z||%r   contentr   list[bytes]c                     j         |r|gng S  j                            |            j                                         j         k    r j                                         fdt          dt                     j                   D             }t          |d                    j         k    r5 j                            d            j                                         |S  j                            d            j                            |d                     j                                         |d d         S g S )Nc                4    g | ]}||j         z            S r   rr   .0ir   values     r   
<listcomp>z&ByteChunker.decode.<locals>.<listcomp>   ;        a!d.../  r   r   	rr   rq   rY   tellr]   rangelenseektruncater   rt   chunksr|   s   `  @r   r   zByteChunker.decode   E   # '/G99R/7###<$"222L))++E    q#e**d.>??  F 6":$"222!!!$$$%%'''!!!$$$""6":...%%'''crc{"Ir   c                    | j                                         }| j                             d           | j                                          |r|gng S Nr   rq   r]   r   r   r   r|   s     r   r   zByteChunker.flush   P    %%''!'wwR'r   r   rn   ro   r   r(   )rt   r   r   ru   )r   ru   r=   r   r   r   rm   rm      _         & & & & &   .( ( ( ( ( (r   rm   c                  ,    e Zd ZdZdddZddZddZdS )TextChunkerz>
    Handles returning text content in fixed-size chunks.
    Nrn   ro   r   r(   c                D    t          j                    | _        || _        d S r   )rW   StringIOrq   rr   rs   s     r   r.   zTextChunker.__init__   s    {}}%r   rt   r4   	list[str]c                     j         |r|gng S  j                            |            j                                         j         k    r j                                         fdt          dt                     j                   D             }t          |d                    j         k    r5 j                            d            j                                         |S  j                            d            j                            |d                     j                                         |d d         S g S )Nc                4    g | ]}||j         z            S r   rx   ry   s     r   r}   z&TextChunker.decode.<locals>.<listcomp>  r~   r   r   r   r   r   s   `  @r   r   zTextChunker.decode   r   r   c                    | j                                         }| j                             d           | j                                          |r|gng S r   r   r   s     r   r   zTextChunker.flush  r   r   r   r   )rt   r4   r   r   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dS )TextDecoderz8
    Handles incrementally decoding bytes into text
    utf-8encodingr4   r   r(   c                L     t          j        |          d          | _        d S )Nreplace)errors)codecsgetincrementaldecoderdecoder)r   r   s     r   r.   zTextDecoder.__init__!  s%    =v3H==YOOOr   r
   r   c                6    | j                             |          S r   r   r   r   s     r   r   zTextDecoder.decode$  s    |""4(((r   c                8    | j                             dd          S rO   r   r   s    r   r   zTextDecoder.flush'  s    |""3---r   N)r   )r   r4   r   r(   )r
   r   r   r4   )r   r4   r=   r   r   r   r   r     sd         P P P P P) ) ) ). . . . . .r   r   c                  *    e Zd ZdZddZddZdd	Zd
S )LineDecoderz
    Handles incrementally reading lines from text.

    Has the same behaviour as the stdllib splitlines,
    but handling the input iteratively.
    r   r(   c                "    g | _         d| _        d S r0   )buffertrailing_crr   s    r   r.   zLineDecoder.__init__3  s    !#!&r   textr4   r   c                   d}| j         rd|z   }d| _         |                    d          rd| _         |d d         }|sg S |d         |v }|                                }t          |          dk    r$|s"| j                            |d                    g S | j        r6d                    | j                  |d         z   g|dd          z   }g | _        |s|                                g| _        |S )	Nu   
  FTr   r   r    )r   endswith
splitlinesr   r   appendjoinpop)r   r   NEWLINE_CHARStrailing_newlineliness        r   r   zLineDecoder.decode7  s   B  	%$;D$D== 	#D9D 	 I8}4!!u::??#3?KuQx(((I; 	 WWT[))E!H45abb	AEDK 	( !99;;-DKr   c                x    | j         s	| j        sg S d                    | j                   g}g | _         d| _        |S )Nr   F)r   r   r   )r   r   s     r   r   zLineDecoder.flush]  sE    { 	4#3 	I%%& r   Nr<   )r   r4   r   r   r   r=   r   r   r   r   r   +  s[         ' ' ' '$ $ $ $L     r   r   )identitygzipdeflatebrr   r   r   )r%   
__future__r   r   rW   typingr+   _compatr   r   _exceptionsr   r	   r!   r'   r?   rF   rS   rb   rm   r   r   r   SUPPORTED_DECODERSr   r   r   r   <module>r      s    # " " " " "  				   ! ! ! ! ! ! ! ! & & & & & &$ $ $ $ $ $ $ $	 	 	 	 	n 	 	 	3 3 3 3 3^ 3 3 3:3 3 3 3 3. 3 3 3.23 23 23 23 23N 23 23 23j# # # # #~ # # #L    >   2$( $( $( $( $( $( $( $(N$( $( $( $( $( $( $( $(N. . . . . . . .9 9 9 9 9 9 9 9z  
   
>4   <6""""" <r   