U
    9Š]  ã                   @   sþ   d 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
rT   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ƒZe
eeedœZedkrâe d¡ d dd„ e ¡ D ƒ¡ZdS )zq
Handlers for Content-Encoding.

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
é    Né   )ÚDecodingErrorc                   @   s*   e Zd Zeedœdd„Zedœdd„ZdS )ÚDecoder©ÚdataÚreturnc                 C   s
   t ƒ ‚d S ©N©ÚNotImplementedError©Úselfr   © r   ún/var/www/html/staging.mfahmagazine.net/magazine_api/magazine_env/lib/python3.8/site-packages/httpx/decoders.pyÚdecode   s    zDecoder.decode©r   c                 C   s
   t ƒ ‚d S r   r	   ©r   r   r   r   Úflush   s    zDecoder.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   t  t j ¡| _d S r   ©ÚzlibÚdecompressobjÚ	MAX_WBITSÚdecompressorr   r   r   r   Ú__init__/   s    zDeflateDecoder.__init__r   c              
   C   s>   z| j  |¡W S  tjk
r8 } z
t|‚W 5 d }~X Y nX d S r   ©r    Ú
decompressr   Úerrorr   ©r   r   Úexcr   r   r   r   2   s    zDeflateDecoder.decodec              
   C   s<   z| j  ¡ W S  tjk
r6 } z
t|‚W 5 d }~X Y nX d S r   ©r    r   r   r$   r   ©r   r&   r   r   r   r   8   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!   F   s    zGZipDecoder.__init__r   c              
   C   s>   z| j  |¡W S  tjk
r8 } z
t|‚W 5 d }~X Y nX d S r   r"   r%   r   r   r   r   I   s    zGZipDecoder.decodec              
   C   s<   z| j  ¡ W S  tjk
r6 } z
t|‚W 5 d }~X Y nX d S r   r'   r(   r   r   r   r   O   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   s$   t d k	stdƒ‚t  ¡ | _d| _d S )NzKThe 'brotlipy' or 'brotli' library must be installed to use 'BrotliDecoder'F)ÚbrotliÚAssertionErrorZDecompressorr    Ú	seen_datar   r   r   r   r!   `   s    ÿþ
zBrotliDecoder.__init__r   c              
   C   sf   |sdS d| _ z(t| jdƒr*| j |¡W S | j |¡W S  tjk
r` } z
t|‚W 5 d }~X Y nX d S )Nr   Tr#   )r/   Úhasattrr    r#   Úprocessr-   r$   r   r%   r   r   r   r   g   s    zBrotliDecoder.decodec              
   C   sV   | j s
dS zt| jdƒr"| j ¡  W dS  tjk
rP } z
t|‚W 5 d }~X Y nX d S )Nr   Úfinish)r/   r0   r    r2   r-   r$   r   r(   r   r   r   r   r   s    
zBrotliDecoder.flushr)   r   r   r   r   r,   V   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Úreversedr4   )r   r4   r   r   r   r!   ‚   s    zMultiDecoder.__init__r   c                 C   s   | j D ]}| |¡}q|S r   )r4   r   ©r   r   Úchildr   r   r   r   Š   s    
zMultiDecoder.decoder   c                 C   s&   d}| j D ]}| |¡| ¡  }q
|S r   )r4   r   r   r7   r   r   r   r      s    
zMultiDecoder.flush)r   r   r   r   ÚtypingÚSequencer   r!   r   r   r   r   r   r   r   r3   }   s   r3   c                   @   sR   e Zd ZdZdeje dœdd„Zeedœdd„Z	ed	œd
d„Z
ed	œdd„ZdS )ÚTextDecoderz8
    Handles incrementally decoding bytes into text
    N)Úencodingc                 C   s<   |d krd n
t  |¡ƒ | _tj ¡ | _| jr0d ntƒ | _d S r   )	ÚcodecsÚgetincrementaldecoderÚdecoderÚchardetZuniversaldetectorZUniversalDetectorÚdetectorÚ	bytearrayÚbuffer)r   r<   r   r   r   r!   ›   s    ÿzTextDecoder.__init__r   c                 C   s¦   z„| j d k	r| j  |¡}nf| jd k	s(t‚d}| j |¡ |  j|7  _t| jƒdkr€t |  	¡ ¡ƒ | _ | j  t
| jƒd¡}d | _|W S  tk
r    tƒ d ‚Y nX d S )NÚ i   F)r?   r   rC   r.   rA   ÚfeedÚlenr=   r>   Ú_detector_resultr   ÚUnicodeDecodeErrorr   )r   r   Útextr   r   r   r   §   s     
ÿzTextDecoder.decoder   c                 C   st   zR| j d krD| jd k	st‚t| jƒdkr.W dS t| jƒ |  ¡ ¡W S | j  dd¡W S  tk
rn   tƒ d ‚Y nX d S )Nr   rD   r   T)	r?   rC   r.   rF   r   r   rG   rH   r   r   r   r   r   r   À   s    
zTextDecoder.flushc                 C   s&   | j  ¡  | j jd }|s"tdƒ‚|S )Nr<   z'Unable to determine encoding of content)rA   ÚcloseÚresultr   )r   rK   r   r   r   rG   Í   s
    
zTextDecoder._detector_result)N)r   r   r   r   r9   ÚOptionalÚstrr!   r   r   r   rG   r   r   r   r   r;   –   s
   r;   )ÚidentityÚgzipÚdeflateÚbrrQ   z, c                 C   s   g | ]}|d kr|‘qS )rN   r   )Ú.0Úkeyr   r   r   Ú
<listcomp>ã   s      rT   )r   r=   r9   r   r@   Ú
exceptionsr   r-   ÚImportErrorr   r   r   r*   r,   r3   r;   ZSUPPORTED_DECODERSÚpopÚjoinÚkeysZACCEPT_ENCODINGr   r   r   r   Ú<module>   s4   
'Aü
ÿ