a
    ù!f&  ã                   @   sö   d 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„ 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ƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZe
eeedœZ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
é    Né   )Úbrotli)ÚDecodingErrorc                   @   s*   e Zd Zeedœdd„Zedœdd„ZdS )ÚContentDecoder©ÚdataÚreturnc                 C   s
   t ƒ ‚d S ©N©ÚNotImplementedError©Úselfr   © r   úP/var/www/html/python-backend/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__Úbytesr   r   r   r   r   r   r      s   r   c                   @   s.   e Zd ZdZeedœdd„Zedœdd„ZdS )	ÚIdentityDecoderz 
    Handle unencoded data.
    r   c                 C   s   |S r	   r   r   r   r   r   r      s    zIdentityDecoder.decoder   c                 C   s   dS ©Nó    r   r   r   r   r   r      s    zIdentityDecoder.flushN)r   r   r   Ú__doc__r   r   r   r   r   r   r   r      s   r   c                   @   s<   e Zd ZdZddœdd„Zeedœdd„Zedœd	d
„ZdS )ÚDeflateDecoderzZ
    Handle 'deflate' decoding.

    See: https://stackoverflow.com/questions/1838699
    Nr   c                 C   s   d| _ t ¡ | _d S )NT)Úfirst_attemptÚzlibÚdecompressobjÚdecompressorr   r   r   r   Ú__init__*   s    zDeflateDecoder.__init__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   .   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   9   s    zDeflateDecoder.flush©r   r   r   r   r!   r   r   r   r   r   r   r   r   #   s   r   c                   @   s<   e Zd ZdZddœdd„Zeedœdd„Zedœd	d
„ZdS )ÚGZipDecoderzW
    Handle 'gzip' decoding.

    See: https://stackoverflow.com/questions/1838699
    Nr   c                 C   s   t  t jdB ¡| _d S )Né   )r   r   r%   r    r   r   r   r   r!   G   s    zGZipDecoder.__init__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   J   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   P   s    zGZipDecoder.flushr*   r   r   r   r   r+   @   s   r+   c                   @   s<   e Zd ZdZddœdd„Zeedœdd„Ze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'
    Nr   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#   )	r   ÚImportErrorZDecompressorr    Ú	seen_dataÚhasattrr#   Ú_decompressÚprocessr   r   r   r   r!   a   s    ÿü
zBrotliDecoder.__init__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)r0   r2   r   r$   r   r&   r-   r   r   r   r   s   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)r0   r1   r    r5   r   r$   r   r&   r)   r   r   r   r   |   s    
zBrotliDecoder.flushr*   r   r   r   r   r.   W   s   		r.   c                   @   sD   e Zd ZdZeje ddœdd„Zeedœdd„Z	ed	œd
d„Z
dS )ÚMultiDecoderzE
    Handle the case where multiple encodings have been applied.
    N)Ú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Úreversedr7   )r   r7   r   r   r   r!   ‘   s    zMultiDecoder.__init__r   c                 C   s   | j D ]}| |¡}q|S r	   )r7   r   ©r   r   Úchildr   r   r   r   ™   s    
zMultiDecoder.decoder   c                 C   s&   d}| j D ]}| |¡| ¡  }q
|S r   )r7   r   r   r:   r   r   r   r   ž   s    
zMultiDecoder.flush)r   r   r   r   ÚtypingÚSequencer   r!   r   r   r   r   r   r   r   r6   Œ   s   r6   c                   @   sR   e Zd ZdZdeje ddœdd„Zeej	e dœdd„Z
ej	e d	œd
d„ZdS )ÚByteChunkerz>
    Handles returning byte content in fixed-size chunks.
    N©Ú
chunk_sizer   c                 C   s   t  ¡ | _|| _d S r	   )ÚioÚBytesIOÚ_bufferÚ_chunk_size©r   r@   r   r   r   r!   ª   s    
zByteChunker.__init__©Ú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   ©rD   ©Ú.0Úi©r   Úvaluer   r   Ú
<listcomp>µ   s   ÿz&ByteChunker.decode.<locals>.<listcomp>r   éÿÿÿÿ©	rD   rC   ÚwriteÚtellÚgetvalueÚrangeÚlenÚseekÚtruncate©r   rG   Úchunksr   rL   r   r   ®   s"    

þ

zByteChunker.decoder   c                 C   s.   | j  ¡ }| j  d¡ | j  ¡  |r*|gS g S ©Nr   ©rC   rS   rV   rW   rL   r   r   r   r   Å   s    

zByteChunker.flush)N)r   r   r   r   r<   ÚOptionalÚintr!   r   ÚListr   r   r   r   r   r   r>   ¥   s   r>   c                   @   sR   e Zd ZdZdeje ddœdd„Zeej	e dœdd„Z
ej	e d	œd
d„ZdS )ÚTextChunkerz>
    Handles returning text content in fixed-size chunks.
    Nr?   c                 C   s   t  ¡ | _|| _d S r	   )rA   ÚStringIOrC   rD   rE   r   r   r   r!   Ñ   s    
zTextChunker.__init__rF   c                    sÀ   ˆ j d u r|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   rH   rI   rL   r   r   rN   Ü   s   ÿz&TextChunker.decode.<locals>.<listcomp>r   rO   rP   rX   r   rL   r   r   Õ   s"    

þ

zTextChunker.decoder   c                 C   s.   | j  ¡ }| j  d¡ | j  ¡  |r*|gS g S rZ   r[   rL   r   r   r   r   ì   s    

zTextChunker.flush)N)r   r   r   r   r<   r\   r]   r!   r&   r^   r   r   r   r   r   r   r_   Ì   s   r_   c                   @   s@   e Zd ZdZdeddœdd„Zeedœdd	„Zed
œdd„ZdS )ÚTextDecoderz8
    Handles incrementally decoding bytes into text
    úutf-8N)Úencodingr   c                 C   s   t  |¡dd| _d S )NÚreplace)Úerrors)ÚcodecsÚgetincrementaldecoderÚdecoder)r   rc   r   r   r   r!   ø   s    zTextDecoder.__init__r   c                 C   s   | j  |¡S r	   ©rh   r   r   r   r   r   r   û   s    zTextDecoder.decoder   c                 C   s   | j  dd¡S r4   ri   r   r   r   r   r   þ   s    zTextDecoder.flush)rb   )	r   r   r   r   r&   r!   r   r   r   r   r   r   r   ra   ó   s   ra   c                   @   sH   e Zd ZdZddœdd„Zeeje dœdd„Zeje 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.
    Nr   c                 C   s   g | _ d| _d S r"   )ÚbufferÚtrailing_crr   r   r   r   r!   	  s    zLineDecoder.__init__)Ú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   
Â…â€¨â€©úFTrO   r   r   Ú )rl   ÚendswithÚ
splitlinesrU   rk   ÚappendÚjoinÚpop)r   rm   ZNEWLINE_CHARSZtrailing_newlineÚlinesr   r   r   r     s(    
"zLineDecoder.decodec                 C   s.   | j s| jsg S d | j ¡g}g | _ d| _|S )Nro   F)rk   rl   rs   )r   ru   r   r   r   r   1  s    zLineDecoder.flush)
r   r   r   r   r!   r&   r<   r^   r   r   r   r   r   r   rj     s   $rj   )ÚidentityÚgzipÚdeflateÚbrry   )r   rf   rA   r<   r   Z_compatr   Ú_exceptionsr   r   r   r   r+   r.   r6   r>   r_   ra   rj   ZSUPPORTED_DECODERSrt   r   r   r   r   Ú<module>   s.   5'':ü