o
    ¨Ý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   úK/var/www/html/chatgpt/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   Z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?   r@   r   r   r   r   •   rA   zGZipDecoder.flushNrB   r(   r1   rC   r   r   r   r   rD   …   s
    

rD   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ó    )rI   r&   rK   rG   r:   r   r<   )r   r   rN   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   )rI   rJ   r!   rP   rG   r:   r   r<   r@   r   r   r   r   Æ   s   €
€€ÿzBrotliDecoder.flushNrB   r(   r1   rC   r   r   r   r   rF   œ   s
    
	
rF   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
   rH   r   r!   rI   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 )NTrO   )rI   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   )rI   r!   rR   r   r   r   r   r   r   ü   s   €zZStandardDecoder.flushNrB   r(   r1   rC   r   r   r   r   rQ   Ö   s
    

	rQ   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   rZ   )r\   Zcodingr   r   r   r^     s    N)ÚlenrW   r   ÚreversedÚchildren)r   rX   Z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   )Úiterra   Ú_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   )rb   ra   Ú	itertoolsÚchainrc   r/   r   )r   rd   re   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/   ri   Úchunkr   r   r   rc   "  s   €ÿzMultiDecoder._pipeN)rX   rY   r   r"   r(   r1   )r/   rh   ri   r%   r   r%   )r   r   r   r)   rW   Ú__annotations__r#   r/   r   Ústaticmethodrc   r   r   r   r   rU     s   
 


rU   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   ro   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   ©ru   ©r\   Úi©r   Úvaluer   r   r^   ;  ó    z&ByteChunker.decode.<locals>.<listcomp>r   éÿÿÿÿ©	ru   rt   ÚwriteÚtellÚgetvalueÚranger_   ÚseekÚtruncate©r   rx   Úchunksr   r   r   r/   4  ó   

"

zByteChunker.decodec                 C  ó.   | j  ¡ }| j  d¡ | j  ¡  |r|gS g S ©Nr   ©rt   r†   rˆ   r‰   r   r   r   r   r   H  ó   

zByteChunker.flushr   ©ro   rp   r   r"   )rx   r   r   ry   )r   ry   rC   r   r   r   r   rn   +  ó
    
rn   c                   @  rm   )ÚTextChunkerz>
    Handles returning text content in fixed-size chunks.
    Nro   rp   r   r"   c                 C  rq   r   )rr   ÚStringIOrt   ru   rv   r   r   r   r#   T  rw   zTextChunker.__init__rx   r<   ú	list[str]c                   rz   )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‘   )rx   r<   r   r•   ©r   r•   rC   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 )NrO   Trž   r   r   r   r   r   ~  s   zTextDecoder.flushN)r˜   )r]   r<   r   r"   )r   r   r   r<   )r   r<   rC   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Ú
splitlinesr_   r    ÚappendÚjoinÚpop)r   r¢   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 )Nr¤   F)r    r¡   r¨   )r   rª   r   r   r   r   ´  s   zLineDecoder.flushNrB   )r¢   r<   r   r•   r–   rC   r   r   r   r   rŸ   ‚  s
    

&rŸ   )ÚidentityÚgzipÚdeflateÚbrÚzstdzdict[str, type[ContentDecoder]]r[   r®   r¯   )'r)   Ú
__future__r   r›   rr   rf   ÚsysÚtypingr7   Ú_exceptionsr   rG   rH   Z
brotlicffiÚTYPE_CHECKINGÚversion_infoZcompression.zstdr   r   Zbackports.zstdrk   r
   r&   ÚProtocolr   r    r*   r2   r5   rD   rF   rQ   rU   rn   r“   r—   rŸ   r[   r©   r   r   r   r   Ú<module>   sr    ÿ€û


ÿ	:.'$$=û
	
ÿ