U
    Vh	/                     @  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
k
r   zddlZ	W n e
k
r|   dZ	Y nX Y nX zddlZW n e
k
r   dZY nX 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krted edkre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   Q/var/www/html/arya_register/venvv2/lib/python3.8/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  sx   | j }d| _ z| j|W S  tjk
rr } z8|rTttj | _| | W Y S tt	||W 5 d }~X Y nX 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  sD   z| j  W S  tjk
r> } ztt||W 5 d }~X Y nX 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  sF   z| j |W S  tjk
r@ } ztt||W 5 d }~X Y nX d S r
   )r"   r%   r    r&   r   r(   r   r   r)   r   r   r   r   _   s    zGZipDecoder.decodec              
   C  sD   z| j  W S  tjk
r> } ztt||W 5 d }~X Y nX 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 krtdd t  | _d| _|  t| jdr>| jj| _n
| 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]`.Fr%   )	brotliImportErrorDecompressorr"   	seen_datahasattrr%   _decompressprocessr   r   r   r   r#   v   s    
zBrotliDecoder.__init__r   r   c              
   C  sR   |sdS d| _ z| |W S  tjk
rL } ztt||W 5 d }~X Y nX d S Nr   T)r4   r6   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k
rX } ztt||W 5 d }~X Y nX d S )Nr   finish)r4   r5   r"   r9   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 krtdd t   | _d| _d S )NzXUsing 'ZStandardDecoder', ...Make sure to install httpx using `pip install httpx[zstd]`.F)	zstandardr2   ZstdDecompressorr!   r"   r4   r   r   r   r   r#      s    zZStandardDecoder.__init__r   r   c              
   C  s   t d k	std| _t }zP|| j| | jjrh| jj	rh| jj	}t 
  | _|| j| q.W n2 t jk
r } ztt||W 5 d }~X Y nX | S r   )r;   AssertionErrorr4   ioBytesIOwriter"   r%   eofunused_datar<   r!   Z	ZstdErrorr   r(   getvalue)r   r   outputrB   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)r4   r"   r   rA   r   r   )r   retr   r   r   r      s    
zZStandardDecoder.flushNr,   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	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reversedrG   )r   rG   r   r   r   r#      s    zMultiDecoder.__init__r   r   c                 C  s   | j D ]}||}q|S r
   )rG   r   r   r   childr   r   r   r      s    
zMultiDecoder.decoder   c                 C  s&   d}| j D ]}|||  }q
|S r   )rG   r   r   rJ   r   r   r   r      s    
zMultiDecoder.flushNr,   r   r   r   r   rF      s   rF   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   rO   r   r   r   r#      s    
zByteChunker.__init__r   zlist[bytes]contentr	   c                   s    j d k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   rQ   .0ir   valuer   r   
<listcomp>   s   z&ByteChunker.decode.<locals>.<listcomp>r   	rQ   rP   r@   tellrC   rangelenseektruncater   rT   chunksr   rY   r   r      s"    



zByteChunker.decoder   c                 C  s.   | j  }| j d | j   |r*|gS g S Nr   rP   rC   ra   rb   rY   r   r   r   r     s    

zByteChunker.flush)Nr,   r   r   r   r   rL      s   rL   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.
    NrM   r   rN   c                 C  s   t  | _|| _d S r
   )r>   StringIOrP   rQ   rR   r   r   r   r#     s    
zTextChunker.__init__r(   	list[str]rS   c                   s    j d k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   rU   rV   rY   r   r   r[     s   z&TextChunker.decode.<locals>.<listcomp>r   r\   r]   rc   r   rY   r   r     s"    



zTextChunker.decoder   c                 C  s.   | j  }| j d | j   |r*|gS g S re   rf   rY   r   r   r   r   +  s    

zTextChunker.flush)Nr,   r   r   r   r   rg     s   rg   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   rl   r   r   r   r#   7  s    zTextDecoder.__init__r   r   c                 C  s   | j |S r
   rq   r   r   r   r   r   r   :  s    zTextDecoder.decoder   c                 C  s   | j ddS r8   rr   r   r   r   r   r   =  s    zTextDecoder.flushN)rk   r,   r   r   r   r   rj   2  s   rj   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(   ri   )textr	   c                 C  s   d}| j rd| }d| _ |dr4d| _ |d d }|s<g S |d |k}| }t|dkrt|st| j|d  g S | jrd| j|d  g|dd   }g | _|s| g| _|S )	Nu   
  FTr\   r   r    )ru   endswith
splitlinesr`   rt   appendjoinpop)r   rv   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 )Nrx   F)rt   ru   r|   )r   r~   r   r   r   r   s  s    zLineDecoder.flushNr,   r   r   r   r   rs   A  s   &rs   )identitygzipdeflatebrzstdr   r   )r   
__future__r   ro   r>   typingr    _exceptionsr   r1   r2   Z
brotlicffir;   r   r   r   r-   r0   r:   rF   rL   rg   rj   rs   SUPPORTED_DECODERSr}   r   r   r   r   <module>   sL   
5*''=	


