o
    í6Wj	/  ã                   @  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 n e
y?   zddlZ	W n e
y<   dZ	Y nw Y nw zddlZW n e
yQ   dZY nw 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 r¶e d¡ edu rÁ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é   )ÚDecodingErrorc                   @  s    e Zd Zd	dd„Zd
dd„ZdS )ÚContentDecoderÚdataÚbytesÚreturnc                 C  ó   t ƒ ‚©N©ÚNotImplementedError©Úselfr   © r   ú^/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/httpx/_decoders.pyÚdecode%   ó   zContentDecoder.decodec                 C  r	   r
   r   ©r   r   r   r   Úflush(   r   zContentDecoder.flushN©r   r   r   r   ©r   r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   $   s    
r   c                   @  s$   e Zd ZdZd
dd„Zddd„Zd	S )ÚIdentityDecoderz 
    Handle unencoded data.
    r   r   r   c                 C  s   |S r
   r   r   r   r   r   r   1   ó   zIdentityDecoder.decodec                 C  s   dS ©Nó    r   r   r   r   r   r   4   r   zIdentityDecoder.flushNr   r   )r   r   r   Ú__doc__r   r   r   r   r   r   r   ,   s    
r   c                   @  ó.   e Zd ZdZddd„Zddd	„Zdd
d„ZdS )ÚDeflateDecoderzZ
    Handle 'deflate' decoding.

    See: https://stackoverflow.com/questions/1838699
    r   ÚNonec                 C  s   d| _ t ¡ | _d S ©NT)Úfirst_attemptÚzlibÚdecompressobjÚdecompressorr   r   r   r   Ú__init__?   s   zDeflateDecoder.__init__r   r   c              
   C  sn   | j }d| _ z| j |¡W S  tjy6 } z|r+t tj ¡| _|  |¡W  Y d }~S tt	|ƒƒ|‚d }~ww ©NF)
r#   r&   Ú
decompressr$   Úerrorr%   Ú	MAX_WBITSr   r   Ústr)r   r   Úwas_first_attemptÚexcr   r   r   r   C   s   €üzDeflateDecoder.decodec              
   C  ó6   z| j  ¡ W S  tjy } ztt|ƒƒ|‚d }~ww r
   ©r&   r   r$   r*   r   r,   ©r   r.   r   r   r   r   N   ó   €ÿzDeflateDecoder.flushN©r   r!   r   r   ©r   r   r   r   r'   r   r   r   r   r   r   r    8   s
    

r    c                   @  r   )Ú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'   \   ó   zGZipDecoder.__init__r   r   c              
   C  s8   z| j  |¡W S  tjy } ztt|ƒƒ|‚d }~ww r
   )r&   r)   r$   r*   r   r,   ©r   r   r.   r   r   r   r   _   s   €ÿzGZipDecoder.decodec              
   C  r/   r
   r0   r1   r   r   r   r   e   r2   zGZipDecoder.flushNr3   r   r   r4   r   r   r   r   r5   U   s
    

r5   c                   @  r   )Ú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  sN   t d u r	tdƒd ‚t  ¡ | _d| _|  t| jdƒr | jj| _d S | 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ÚImportErrorÚDecompressorr&   Ú	seen_dataÚhasattrr)   Ú_decompressÚprocessr   r   r   r   r'   v   s   ÿü
zBrotliDecoder.__init__r   r   c              
   C  sD   |sdS d| _ z|  |¡W S  tjy! } ztt|ƒƒ|‚d }~ww ©Nr   T)r=   r?   r:   r*   r   r,   r8   r   r   r   r   ˆ   s   €ÿzBrotliDecoder.decodec              
   C  sP   | j sdS zt| jdƒr| j ¡  W dS  tjy' } ztt|ƒƒ|‚d }~ww )Nr   Úfinish)r=   r>   r&   rB   r:   r*   r   r,   r1   r   r   r   r   ‘   s   
€ÿzBrotliDecoder.flushNr3   r   r   r4   r   r   r   r   r9   l   s
    
	
	r9   c                   @  r   )Ú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)Ú	zstandardr;   ÚZstdDecompressorr%   r&   r=   r   r   r   r   r'   ª   s   ÿý
zZStandardDecoder.__init__r   r   c              
   C  sÆ   t d usJ ‚d| _t ¡ }zA| | j |¡¡ | jjr@| jjrJ| jj}t  	¡  
¡ | _| | j |¡¡ | jjrE| jjsW | ¡ S W | ¡ S W | ¡ S W | ¡ S  t jyb } ztt|ƒƒ|‚d }~ww r"   )rD   r=   ÚioÚBytesIOÚwriter&   r)   ÚeofÚunused_datarE   r%   Ú	ZstdErrorr   r,   Úgetvalue)r   r   ÚoutputrJ   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)r=   r&   r   rI   r   r   )r   Úretr   r   r   r   Â   s   
zZStandardDecoder.flushNr3   r   r   r4   r   r   r   r   rC   ¡   s
    


rC   c                   @  s.   e Zd ZdZddd„Zdd
d„Zddd„ZdS )ÚMultiDecoderzE
    Handle the case where multiple encodings have been applied.
    Úchildrenútyping.Sequence[ContentDecoder]r   r!   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ÚreversedrP   )r   rP   r   r   r   r'   Ð   s   zMultiDecoder.__init__r   r   c                 C  s   | j D ]}| |¡}q|S r
   )rP   r   ©r   r   Úchildr   r   r   r   Ø   s   
zMultiDecoder.decodec                 C  s&   d}| j D ]}| |¡| ¡  }q|S r   )rP   r   r   rT   r   r   r   r   Ý   s   
zMultiDecoder.flushN)rP   rQ   r   r!   r   r   r4   r   r   r   r   rO   Ë   s
    

rO   c                   @  ó0   e Zd ZdZdddd„Zddd„Zddd„ZdS )ÚByteChunkerz>
    Handles returning byte content in fixed-size chunks.
    NÚ
chunk_sizeú
int | Noner   r!   c                 C  ó   t  ¡ | _|| _d S r
   )rF   rG   Ú_bufferÚ_chunk_size©r   rX   r   r   r   r'   é   ó   

zByteChunker.__init__Úcontentr   úlist[bytes]c                   óÂ   ˆ 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rFˆ j d¡ ˆ j ¡  |S ˆ j d¡ ˆ j |d ¡ ˆ j ¡  |d d… S g S )Nc                   ó   g | ]}ˆ||ˆ j  … ‘qS r   ©r\   ©Ú.0Úi©r   Úvaluer   r   Ú
<listcomp>ô   ó    ÿÿz&ByteChunker.decode.<locals>.<listcomp>r   éÿÿÿÿ©	r\   r[   rH   ÚtellrL   ÚrangeÚlenÚseekÚtruncate©r   r_   Úchunksr   rg   r   r   í   ó"   

þ

zByteChunker.decodec                 C  ó.   | j  ¡ }| j  d¡ | j  ¡  |r|gS g S ©Nr   ©r[   rL   rp   rq   rg   r   r   r   r     ó   

zByteChunker.flushr
   ©rX   rY   r   r!   )r_   r   r   r`   )r   r`   r4   r   r   r   r   rW   ä   ó
    
rW   c                   @  rV   )ÚTextChunkerz>
    Handles returning text content in fixed-size chunks.
    NrX   rY   r   r!   c                 C  rZ   r
   )rF   ÚStringIOr[   r\   r]   r   r   r   r'     r^   zTextChunker.__init__r_   r,   ú	list[str]c                   ra   )Nc                   rb   r   rc   rd   rg   r   r   ri     rj   z&TextChunker.decode.<locals>.<listcomp>r   rk   rl   rr   r   rg   r   r     rt   zTextChunker.decodec                 C  ru   rv   rw   rg   r   r   r   r   +  rx   zTextChunker.flushr
   ry   )r_   r,   r   r}   ©r   r}   r4   r   r   r   r   r{     rz   r{   c                   @  s0   e Zd ZdZdddd„Zddd„Zddd„ZdS )ÚTextDecoderz8
    Handles incrementally decoding bytes into text
    úutf-8Úencodingr,   r   r!   c                 C  s   t  |¡dd�| _d S )NÚreplace)Úerrors)ÚcodecsÚgetincrementaldecoderÚdecoder)r   r�   r   r   r   r'   7  r7   zTextDecoder.__init__r   r   c                 C  s   | j  |¡S r
   ©r†   r   r   r   r   r   r   :  s   zTextDecoder.decodec                 C  s   | j  dd¡S rA   r‡   r   r   r   r   r   =  s   zTextDecoder.flushN)r€   )r�   r,   r   r!   )r   r   r   r,   )r   r,   r4   r   r   r   r   r   2  s
    
r   c                   @  s.   e Zd ZdZddd„Zdd	d
„Z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__Útextr,   r}   c                 C  s¶   d}| j rd| }d| _ | d¡rd| _ |d d… }|sg S |d |v }| ¡ }t|ƒdkr:|s:| j |d ¡ g S | jrQd | j¡|d  g|dd …  }g | _|sY| ¡ g| _|S )	Nu   
Â…â€¨â€©úFTrk   r   r   Ú )rŠ   ÚendswithÚ
splitlinesro   r‰   ÚappendÚjoinÚpop)r   r‹   ÚNEWLINE_CHARSÚ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 )Nr�   F)r‰   rŠ   r‘   )r   r•   r   r   r   r   s  s   zLineDecoder.flushNr3   )r‹   r,   r   r}   r~   r4   r   r   r   r   rˆ   A  s
    

&rˆ   )ÚidentityÚgzipÚdeflateÚbrÚzstdr™   rš   )r   Ú
__future__r   r„   rF   Útypingr$   Ú_exceptionsr   r:   r;   Ú
brotlicffirD   r   r   r    r5   r9   rC   rO   rW   r{   r   rˆ   ÚSUPPORTED_DECODERSr’   r   r   r   r   Ú<module>   sX    ÿ€û
ÿ5*''=û	
ÿ