o
    ùT·jÆ:  ã                   @  s(  U 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ZddlZddl	m
Z
 zddlZW n eyH   zddlZW n eyE   dZY nw Y nw ejrgejdkrZddlmZmZ nddlmZmZ ded	< n&zejdkrvddlmZmZ nddlmZmZ d
ZW n eyŒ   dZY nw dZG dd„ dejƒZG dd„ dƒ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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%d(ed)< edu �re% &d*¡ e�s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é   )ÚDecodingError)é   é   )ÚZstdDecompressorÚ	ZstdErrorÚboolÚ_zstandard_installedTFi   c                   @  s.   e Zd Zeddd„ƒZddd	„Zdd
d„ZdS )ÚDecompressorÚreturnÚbytesc                 C  ó   d S ©N© ©Úselfr   r   úS/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/httpx2/_decoders.pyÚunconsumed_tail8   s   zDecompressor.unconsumed_tailÚdataÚ
max_lengthÚintc                 C  r   r   r   )r   r   r   r   r   r   Ú
decompress;   ó    zDecompressor.decompressc                 C  r   r   r   r   r   r   r   Úflush=   r   zDecompressor.flushN©r   r   )r   r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Úpropertyr   r   r   r   r   r   r   r   7   s
    
r   c                   @  s.   e Zd ZdZddd„Zddd„Zddd„ZdS )ÚZlibDecompressorz–
    Drain a `zlib`/`gzip` decompressor in bounded pieces so a small compressed
    input cannot inflate to an unbounded buffer in a single call.
    Údecompressorr   r   ÚNonec                 C  s
   || _ d S r   )r!   )r   r!   r   r   r   Ú__init__F   ó   
zZlibDecompressor.__init__r   r   útyping.Iterator[bytes]c                 c  s8   � | j  |t¡}|r|V  | j  | j jt¡}|s
d S d S r   )r!   r   ÚMAX_DECODE_CHUNK_SIZEr   )r   r   Údecompressedr   r   r   r   I   s   €þzZlibDecompressor.decompressc                 C  s
   | j  ¡ S r   )r!   r   r   r   r   r   r   O   r$   zZlibDecompressor.flushN)r!   r   r   r"   ©r   r   r   r%   r   )r   r   r   Ú__doc__r#   r   r   r   r   r   r   r    @   s
    

r    c                   @  s    e Zd Zd
dd„Zddd„Zd	S )ÚContentDecoderr   r   r   r%   c                 C  ó   t ƒ ‚r   ©ÚNotImplementedError©r   r   r   r   r   ÚdecodeT   ó   zContentDecoder.decodec                 C  r+   r   r,   r   r   r   r   r   W   r0   zContentDecoder.flushNr(   ©r   r%   )r   r   r   r/   r   r   r   r   r   r*   S   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   r%   c                 c  s   � |V  d S r   r   r.   r   r   r   r/   `   s   €
zIdentityDecoder.decodec                 c  s   � dE d H  d S ©Nr   r   r   r   r   r   r   c   s   €zIdentityDecoder.flushNr(   r1   )r   r   r   r)   r/   r   r   r   r   r   r2   [   s    
r2   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   r"   c                 C  s   d| _ tt ¡ ƒ| _d S )NT)Úfirst_attemptr    ÚzlibÚdecompressobjr!   r   r   r   r   r#   n   s   zDeflateDecoder.__init__r   r   r%   c              
   c  sˆ   � | j }d| _ z| j |¡E d H  W d S  tjyC } z#|r1tt tj ¡ƒ| _|  |¡E d H  nt	t
|ƒƒ|‚W Y d }~d S d }~ww ©NF)r6   r!   r   r7   Úerrorr    r8   Ú	MAX_WBITSr/   r   Ústr)r   r   Úwas_first_attemptÚexcr   r   r   r/   r   s   €þ€ýzDeflateDecoder.decodec              
   c  ó>   � z	| j  ¡ V  W d S  tjy } ztt|ƒƒ|‚d }~ww r   ©r!   r   r7   r:   r   r<   ©r   r>   r   r   r   r   ~   ó   €€ÿzDeflateDecoder.flushN©r   r"   r(   r1   ©r   r   r   r)   r#   r/   r   r   r   r   r   r5   g   s
    

r5   c                   @  r4   )ÚGZipDecoderzW
    Handle 'gzip' decoding.

    See: https://stackoverflow.com/questions/1838699
    r   r"   c                 C  s   t t tjdB ¡ƒ| _d S )Né   )r    r7   r8   r;   r!   r   r   r   r   r#   Œ   s   zGZipDecoder.__init__r   r   r%   c              
   c  sD   � z| j  |¡E d H  W d S  tjy! } ztt|ƒƒ|‚d }~ww r   )r!   r   r7   r:   r   r<   )r   r   r>   r   r   r   r/   �   s   €€ÿzGZipDecoder.decodec              
   c  r?   r   r@   rA   r   r   r   r   •   rB   zGZipDecoder.flushNrC   r(   r1   rD   r   r   r   r   rE   …   s
    

rE   c                   @  r4   )Ú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ÚImportErrorr   r!   Ú	seen_dataÚhasattrr   Ú_decompressÚprocessr   r   r   r   r#   ¦   s   ÿü
zBrotliDecoder.__init__r   r   r%   c              
   c  sx   � |sd S d| _ ztd }| j||d�}|r%|V  | jd|d�}|sW d S W d S  tjy; } ztt|ƒƒ|‚d }~ww )NTé   )Úoutput_buffer_limitó    )rJ   r&   rL   rH   r:   r   r<   )r   r   rO   r'   r>   r   r   r   r/   ¸   s   €þ€ÿzBrotliDecoder.decodec              
   c  s^   � | j sd S zt| jdƒr| j ¡  W n tjy' } ztt|ƒƒ|‚d }~ww dE d H  d S )NÚfinishr   )rJ   rK   r!   rQ   rH   r:   r   r<   rA   r   r   r   r   Æ   s   €
€€ÿzBrotliDecoder.flushNrC   r(   r1   rD   r   r   r   r   rG   œ   s
    
	
rG   c                   @  r4   )ÚZStandardDecoderznHandle 'zstd' RFC 8878 decoding.

    On Python 3.13 and below, this requires `pip install httpx2[zstd]`.
    r   r"   c                 C  s    t stdƒd ‚tƒ | _d| _d S )NzXUsing 'ZStandardDecoder', ...Make sure to install httpx using `pip install httpx[zstd]`.F)r
   rI   r   r!   rJ   r   r   r   r   r#   Ý   s   ÿþ
zZStandardDecoder.__init__r   r   r%   c              
   c  sº   � |sd S d| _ zA| jjr| jj| }tƒ | _	 | j |t¡}|r6|V  | jjs,| jjr-n	| j dt¡}|s!| jjr>| jjsAW d S | jj}tƒ | _q ty\ } zt	t
|ƒƒ|‚d }~ww )NTrP   )rJ   r!   ÚeofÚunused_datar   r   r&   Úneeds_inputr   r   r<   )r   r   r'   r>   r   r   r   r/   æ   s2   €üö€ÿzZStandardDecoder.decodec                 c  s*   � | j sd S | jjstdƒ‚dE d H  d S )NzZstandard data is incompleter   )rJ   r!   rS   r   r   r   r   r   r   ü   s   €zZStandardDecoder.flushNrC   r(   r1   rD   r   r   r   r   rR   Ö   s
    

	rR   c                   @  sJ   e Zd ZU dZdZded< dd	d
„Zddd„Zddd„Ze	ddd„ƒZ
dS )ÚMultiDecoderzE
    Handle the case where multiple encodings have been applied.
    é   ztyping.ClassVar[int]Úmax_decode_linksÚ	encodingsútyping.Sequence[str]r   r"   c                 C  sF   dd„ |D ƒ}t |ƒ| jkrtd| j› d�ƒ‚dd„ t|ƒD ƒ| _dS )zk
        'encodings' should be the content codings in the order in which
        each was applied.
        c                 S  s   g | ]}|t v r|‘qS r   ©ÚSUPPORTED_DECODERS)Ú.0Úencodingr   r   r   Ú
<listcomp>  s    z)MultiDecoder.__init__.<locals>.<listcomp>zCannot apply more than z content encodings.c                 S  s   g | ]}t | ƒ ‘qS r   r[   )r]   Úcodingr   r   r   r_     s    N)ÚlenrX   r   ÚreversedÚchildren)r   rY   Úcodingsr   r   r   r#     s   zMultiDecoder.__init__r   r   r%   c                 c  s4   � t |fƒ}| jD ]	}|  |j|¡}q	|E d H  d S r   )Úiterrc   Ú_piper/   )r   r   ÚstreamsÚchildr   r   r   r/     s
   €

zMultiDecoder.decodec                 c  s>   � t dƒ}| jD ]}t |  |j|¡| ¡ ¡}q|E d H  d S r3   )re   rc   Ú	itertoolsÚchainrf   r/   r   )r   rg   rh   r   r   r   r     s
   €
zMultiDecoder.flushr/   ú0typing.Callable[[bytes], typing.Iterator[bytes]]Úupstreamc                 c  s   � |D ]	}| |ƒE d H  qd S r   r   )r/   rl   Úchunkr   r   r   rf   "  s   €ÿzMultiDecoder._pipeN)rY   rZ   r   r"   r(   r1   )r/   rk   rl   r%   r   r%   )r   r   r   r)   rX   Ú__annotations__r#   r/   r   Ústaticmethodrf   r   r   r   r   rV     s   
 


rV   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   )ÚioÚBytesIOÚ_bufferÚ_chunk_size©r   rr   r   r   r   r#   0  ó   

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   ©rx   ©r]   Úi©r   Úvaluer   r   r_   ;  ó    z&ByteChunker.decode.<locals>.<listcomp>r   éÿÿÿÿ©	rx   rw   ÚwriteÚtellÚgetvalueÚrangera   ÚseekÚtruncate©r   r{   Úchunksr   r‚   r   r/   4  ó   

"

zByteChunker.decodec                 C  ó.   | j  ¡ }| j  d¡ | j  ¡  |r|gS g S ©Nr   ©rw   r‰   r‹   rŒ   r‚   r   r   r   r   H  ó   

zByteChunker.flushr   ©rr   rs   r   r"   )r{   r   r   r|   )r   r|   rD   r   r   r   r   rq   +  ó
    
rq   c                   @  rp   )ÚTextChunkerz>
    Handles returning text content in fixed-size chunks.
    Nrr   rs   r   r"   c                 C  rt   r   )ru   ÚStringIOrw   rx   ry   r   r   r   r#   T  rz   zTextChunker.__init__r{   r<   ú	list[str]c                   r}   )Nc                   r~   r   r   r€   r‚   r   r   r_   _  r„   z&TextChunker.decode.<locals>.<listcomp>r   r…   r†   r�   r   r‚   r   r/   X  r�   zTextChunker.decodec                 C  r�   r‘   r’   r‚   r   r   r   r   l  r“   zTextChunker.flushr   r”   )r{   r<   r   r˜   ©r   r˜   rD   r   r   r   r   r–   O  r•   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-8r^   r<   r   r"   c                 C  s   t  |¡dd�| _d S )NÚreplace)Úerrors)ÚcodecsÚgetincrementaldecoderÚdecoder)r   r^   r   r   r   r#   x  s   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 )NrP   Tr¡   r   r   r   r   r   ~  s   zTextDecoder.flushN)r›   )r^   r<   r   r"   )r   r   r   r<   )r   r<   rD   r   r   r   r   rš   s  s
    
rš   c                   @  r4   )Ú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 r9   )ÚbufferÚtrailing_crr   r   r   r   r#   Š  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   
Â…â€¨â€©úFTr…   r   r   Ú )r¤   ÚendswithÚ
splitlinesra   r£   ÚappendÚjoinÚpop)r   r¥   ÚNEWLINE_CHARSÚtrailing_newlineÚlinesr   r   r   r/   Ž  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   zLineDecoder.flushNrC   )r¥   r<   r   r˜   r™   rD   r   r   r   r   r¢   ‚  s
    

&r¢   )ÚidentityÚgzipÚdeflateÚbrÚzstdzdict[str, type[ContentDecoder]]r\   r³   r´   )'r)   Ú
__future__r   rž   ru   ri   ÚsysÚtypingr7   Ú_exceptionsr   rH   rI   Ú
brotlicffiÚTYPE_CHECKINGÚversion_infoÚcompression.zstdr   r   Úbackports.zstdrn   r
   r&   ÚProtocolr   r    r*   r2   r5   rE   rG   rR   rV   rq   r–   rš   r¢   r\   r¬   r   r   r   r   Ú<module>   sr    ÿ€û


ÿ	:.'$$=û
	
ÿ