a
    ”˜ëj	/  ã                   @  s†  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 zddl	Z	W n6 e
y~   zddlZ	W n e
yx   dZ	Y n0 Y n0 zddlZW n e
y¢   dZY n0 G dd„ dƒZG dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZeeeeedœZe	du �rne d¡ edu �r‚e d¡ dS )zq
Handlers for Content-Encoding.

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
é    )ÚannotationsNé   )ÚDecodingErrorc                   @  s*   e Zd Zdddœdd„Zddœdd„ZdS )	ÚContentDecoderÚbytes©ÚdataÚreturnc                 C  s
   t ƒ ‚d S ©N©ÚNotImplementedError©Úselfr   © r   úN/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/httpx/_decoders.pyÚdecode%   s    zContentDecoder.decode©r	   c                 C  s
   t ƒ ‚d S r
   r   ©r   r   r   r   Úflush(   s    zContentDecoder.flushN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   $   s   r   c                   @  s.   e Zd ZdZdddœdd„Zddœdd„Zd	S )
ÚIdentityDecoderz 
    Handle unencoded data.
    r   r   c                 C  s   |S r
   r   r   r   r   r   r   1   s    zIdentityDecoder.decoder   c                 C  s   dS ©Nó    r   r   r   r   r   r   4   s    zIdentityDecoder.flushN)r   r   r   Ú__doc__r   r   r   r   r   r   r   ,   s   r   c                   @  s<   e Zd ZdZddœdd„Zdddœdd	„Zddœd
d„ZdS )ÚDeflateDecoderzZ
    Handle 'deflate' decoding.

    See: https://stackoverflow.com/questions/1838699
    ÚNoner   c                 C  s   d| _ t ¡ | _d S ©NT)Úfirst_attemptÚzlibÚdecompressobjÚdecompressorr   r   r   r   Ú__init__?   s    zDeflateDecoder.__init__r   r   c              
   C  s~   | j }d| _ z| j |¡W S  tjyx } zD|rVt tj ¡| _|  |¡W  Y d }~S tt	|ƒƒ|‚W Y d }~n
d }~0 0 d S ©NF)
r   r"   Ú
decompressr    Úerrorr!   Ú	MAX_WBITSr   r   Ústr)r   r   Zwas_first_attemptÚexcr   r   r   r   C   s    zDeflateDecoder.decodec              
   C  sF   z| j  ¡ W S  tjy@ } ztt|ƒƒ|‚W Y d }~n
d }~0 0 d S r
   ©r"   r   r    r&   r   r(   ©r   r)   r   r   r   r   N   s    zDeflateDecoder.flushN©r   r   r   r   r#   r   r   r   r   r   r   r   8   s   r   c                   @  s<   e Zd ZdZddœdd„Zdddœdd	„Zddœd
d„ZdS )ÚGZipDecoderzW
    Handle 'gzip' decoding.

    See: https://stackoverflow.com/questions/1838699
    r   r   c                 C  s   t  t jdB ¡| _d S )Né   )r    r!   r'   r"   r   r   r   r   r#   \   s    zGZipDecoder.__init__r   r   c              
   C  sH   z| j  |¡W S  tjyB } ztt|ƒƒ|‚W Y d }~n
d }~0 0 d S r
   )r"   r%   r    r&   r   r(   ©r   r   r)   r   r   r   r   _   s    zGZipDecoder.decodec              
   C  sF   z| j  ¡ W S  tjy@ } ztt|ƒƒ|‚W Y d }~n
d }~0 0 d S r
   r*   r+   r   r   r   r   e   s    zGZipDecoder.flushNr,   r   r   r   r   r-   U   s   r-   c                   @  s<   e Zd ZdZddœdd„Zdddœdd	„Zddœ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                 C  sL   t d u rtdƒd ‚t  ¡ | _d| _|  t| jdƒr>| jj| _n
| jj| _d S )NzžUsing 'BrotliDecoder', but neither of the 'brotlicffi' or 'brotli' packages have been installed. Make sure to install httpx using `pip install httpx[brotli]`.Fr%   )	ÚbrotliÚImportErrorZDecompressorr"   Ú	seen_dataÚhasattrr%   Ú_decompressÚprocessr   r   r   r   r#   v   s    ÿü
zBrotliDecoder.__init__r   r   c              
   C  sT   |sdS d| _ z|  |¡W S  tjyN } ztt|ƒƒ|‚W Y d }~n
d }~0 0 d S ©Nr   T)r3   r5   r1   r&   r   r(   r/   r   r   r   r   ˆ   s    zBrotliDecoder.decodec              
   C  s`   | j s
dS zt| jdƒr"| j ¡  W dS  tjyZ } ztt|ƒƒ|‚W Y d }~n
d }~0 0 d S )Nr   Úfinish)r3   r4   r"   r8   r1   r&   r   r(   r+   r   r   r   r   ‘   s    
zBrotliDecoder.flushNr,   r   r   r   r   r0   l   s   		r0   c                   @  s<   e Zd ZdZddœdd„Zdddœdd	„Zddœ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                 C  s*   t d u rtdƒd ‚t  ¡  ¡ | _d| _d S )NzXUsing 'ZStandardDecoder', ...Make sure to install httpx using `pip install httpx[zstd]`.F)Ú	zstandardr2   ÚZstdDecompressorr!   r"   r3   r   r   r   r   r#   ª   s    ÿýzZStandardDecoder.__init__r   r   c              
   C  s¨   t d usJ ‚d| _t ¡ }zP| | j |¡¡ | jjrh| jjrh| jj}t  	¡  
¡ | _| | j |¡¡ q.W n4 t jyž } ztt|ƒƒ|‚W Y d }~n
d }~0 0 | ¡ S r   )r:   r3   ÚioÚBytesIOÚwriter"   r%   ÚeofÚunused_datar;   r!   Z	ZstdErrorr   r(   Úgetvalue)r   r   Úoutputr@   r)   r   r   r   r   ´   s    $zZStandardDecoder.decodec                 C  s,   | j s
dS | j ¡ }| jjs$tdƒ‚t|ƒS )Nr   zZstandard data is incomplete)r3   r"   r   r?   r   r   )r   Úretr   r   r   r   Â   s    
zZStandardDecoder.flushNr,   r   r   r   r   r9   ¡   s   
r9   c                   @  s>   e Zd ZdZdddœdd„Zdddœd	d
„Zddœdd„ZdS )ÚMultiDecoderzE
    Handle the case where multiple encodings have been applied.
    ztyping.Sequence[ContentDecoder]r   )Úchildrenr	   c                 C  s   t t|ƒƒ| _dS )zm
        'children' should be a sequence of decoders in the order in which
        each was applied.
        N)ÚlistÚreversedrE   )r   rE   r   r   r   r#   Ð   s    zMultiDecoder.__init__r   r   c                 C  s   | j D ]}| |¡}q|S r
   )rE   r   ©r   r   Úchildr   r   r   r   Ø   s    
zMultiDecoder.decoder   c                 C  s&   d}| j D ]}| |¡| ¡  }q
|S r   )rE   r   r   rH   r   r   r   r   Ý   s    
zMultiDecoder.flushNr,   r   r   r   r   rD   Ë   s   rD   c                   @  s@   e Zd ZdZddddœdd„Zdd	d
œdd„Zd	dœdd„ZdS )ÚByteChunkerz>
    Handles returning byte content in fixed-size chunks.
    Nú
int | Noner   ©Ú
chunk_sizer	   c                 C  s   t  ¡ | _|| _d S r
   )r<   r=   Ú_bufferÚ_chunk_size©r   rM   r   r   r   r#   é   s    
zByteChunker.__init__r   zlist[bytes]©Úcontentr	   c                   sÈ   ˆ j d u r|r|gS g S ˆ j |¡ ˆ j ¡ ˆ j krÀˆ j ¡ ‰‡ ‡fdd„tdtˆƒˆ j ƒD ƒ}t|d ƒˆ j krŒˆ j d¡ ˆ j ¡  |S ˆ j d¡ ˆ j |d ¡ ˆ j ¡  |d d… S ng S d S )Nc                   s   g | ]}ˆ||ˆ j  … ‘qS r   ©rO   ©Ú.0Úi©r   Úvaluer   r   Ú
<listcomp>ô   s   ÿz&ByteChunker.decode.<locals>.<listcomp>r   éÿÿÿÿ©	rO   rN   r>   ÚtellrA   ÚrangeÚlenÚseekÚtruncate©r   rR   Úchunksr   rW   r   r   í   s"    

þ

zByteChunker.decoder   c                 C  s.   | j  ¡ }| j  d¡ | j  ¡  |r*|gS g S ©Nr   ©rN   rA   r_   r`   rW   r   r   r   r     s    

zByteChunker.flush)Nr,   r   r   r   r   rJ   ä   s   rJ   c                   @  s@   e Zd ZdZddddœdd„Zdd	d
œdd„Zd	dœdd„ZdS )ÚTextChunkerz>
    Handles returning text content in fixed-size chunks.
    NrK   r   rL   c                 C  s   t  ¡ | _|| _d S r
   )r<   ÚStringIOrN   rO   rP   r   r   r   r#     s    
zTextChunker.__init__r(   ú	list[str]rQ   c                   sÈ   ˆ j d u r|r|gS g S ˆ j |¡ ˆ j ¡ ˆ j krÀˆ j ¡ ‰‡ ‡fdd„tdtˆƒˆ j ƒD ƒ}t|d ƒˆ j krŒˆ j d¡ ˆ j ¡  |S ˆ j d¡ ˆ j |d ¡ ˆ j ¡  |d d… S ng S d S )Nc                   s   g | ]}ˆ||ˆ j  … ‘qS r   rS   rT   rW   r   r   rY     s   ÿz&TextChunker.decode.<locals>.<listcomp>r   rZ   r[   ra   r   rW   r   r     s"    

þ

zTextChunker.decoder   c                 C  s.   | j  ¡ }| j  d¡ | j  ¡  |r*|gS g S rc   rd   rW   r   r   r   r   +  s    

zTextChunker.flush)Nr,   r   r   r   r   re     s   re   c                   @  s@   e Zd ZdZddddœdd„Zddd	œd
d„Zddœdd„ZdS )ÚTextDecoderz8
    Handles incrementally decoding bytes into text
    úutf-8r(   r   )Úencodingr	   c                 C  s   t  |¡dd�| _d S )NÚreplace)Úerrors)ÚcodecsÚgetincrementaldecoderÚdecoder)r   rj   r   r   r   r#   7  s    zTextDecoder.__init__r   r   c                 C  s   | j  |¡S r
   ©ro   r   r   r   r   r   r   :  s    zTextDecoder.decoder   c                 C  s   | j  dd¡S r7   rp   r   r   r   r   r   =  s    zTextDecoder.flushN)ri   r,   r   r   r   r   rh   2  s   rh   c                   @  s<   e Zd ZdZddœdd„Zdddœd	d
„Zddœ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                 C  s   g | _ d| _d S r$   )ÚbufferÚtrailing_crr   r   r   r   r#   I  s    zLineDecoder.__init__r(   rg   )Útextr	   c                 C  s¶   d}| j rd| }d| _ | d¡r4d| _ |d d… }|s<g S |d |v }| ¡ }t|ƒdkrt|st| j |d ¡ g S | jr¢d | j¡|d  g|dd …  }g | _|s²| ¡ g| _|S )	Nu   
Â…â€¨â€©úFTrZ   r   r   Ú )rs   ÚendswithÚ
splitlinesr^   rr   ÚappendÚjoinÚpop)r   rt   ZNEWLINE_CHARSZtrailing_newlineÚlinesr   r   r   r   M  s(    
"zLineDecoder.decodec                 C  s.   | j s| jsg S d | j ¡g}g | _ d| _|S )Nrv   F)rr   rs   rz   )r   r|   r   r   r   r   s  s    zLineDecoder.flushNr,   r   r   r   r   rq   A  s   &rq   )ÚidentityÚgzipÚdeflateÚbrÚzstdr€   r�   )r   Ú
__future__r   rm   r<   Útypingr    Ú_exceptionsr   r1   r2   Z
brotlicffir:   r   r   r   r-   r0   r9   rD   rJ   re   rh   rq   ZSUPPORTED_DECODERSr{   r   r   r   r   Ú<module>   sL   
5*''=û	


