Format: application/x-python-code
⬇ Download File (10.6 KB)
   1  o
   2  
   3  C'h	/�@s�dZddlmZddlZddlZddlZddlZddlmZzddl	Z	Wne
   4  y?zddlZ	Wne
   5  y<dZ	YnwYnwzddlZWne
   6  yQdZYnwGdd�d�Z
   7  Gdd	�d	e
   8  �ZGd
   9  d�de
  10  �ZGdd
  11  �d
  12  e
  13  �ZGdd�de
  14  �ZGdd�de
  15  �ZGdd�de
  16  �ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�Zeeeeed�Ze	dur�e�d�edur�e�d�dSdS)zq
  17  Handlers for Content-Encoding.
  18  
  19  See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
  20  �)�annotationsN�)�
  21  DecodingErrorc@s eZdZd	dd�Zd
  22  dd�ZdS)�ContentDecoder�data�bytes�returncC�t���N��NotImplementedError��selfr�r�EC:\Users\shubh\Videos\agent\nova\Lib\site-packages\httpx/_decoders.py�decode%�zContentDecoder.decodecCr	r
  23  r�rrrr�flush(rzContentDecoder.flushN�rrrr�rr)�__name__�
  24  __module__�__qualname__rrrrrrr$s
  25  rc@s$eZdZdZd
  26  dd�Zddd�Zd	S)�IdentityDecoderz 
  27      Handle unencoded data.
  28      rrrcCs|Sr
  29  rr
  30  rrrr1�zIdentityDecoder.decodecCsdS�N�rrrrrr4rzIdentityDecoder.flushNrr)rrr�__doc__rrrrrrr,s
  31  rc@�.eZdZdZd
  32  dd�Zddd	�Zdd
  33  d�ZdS)�DeflateDecoderzZ
  34      Handle 'deflate' decoding.
  35  
  36      See: https://stackoverflow.com/questions/1838699
  37      r�NonecCsd|_t��|_dS�NT)�
  38  first_attempt�zlib�
  39  decompressobj�decompressorrrrr�__init__?szDeflateDecoder.__init__rrc
  40  Csn|j}d|_z|j�|�WStjy6}z|r+t�tj�|_|�|�WYd}~Stt	|��|�d}~ww�NF)
  41  r#r&�
  42  decompressr$�errorr%�	MAX_WBITSrr�str)rrZwas_first_attempt�excrrrrCs��zDeflateDecoder.decodec
  43  C�6z|j��WStjy}ztt|��|�d}~wwr
  44  �r&rr$r*rr,�rr-rrrrN���zDeflateDecoder.flushN�rr!rr�rrrrr'rrrrrrr 8s
  45  
  46  
  47  r c@r)�GZipDecoderzW
  48      Handle 'gzip' decoding.
  49  
  50      See: https://stackoverflow.com/questions/1838699
  51      rr!cCst�tjdB�|_dS)N�)r$r%r+r&rrrrr'\�zGZipDecoder.__init__rrc
  52  Cs8z|j�|�WStjy}ztt|��|�d}~wwr
  53  )r&r)r$r*rr,�rrr-rrrr_s��zGZipDecoder.decodec
  54  Cr.r
  55  r/r0rrrrer1zGZipDecoder.flushNr2rrr3rrrrr4Us
  56  
  57  
  58  r4c@r)�
  59  BrotliDecoderaT
  60      Handle 'brotli' decoding.
  61  
  62      Requires `pip install brotlipy`. See: https://brotlipy.readthedocs.io/
  63          or   `pip install brotli`. See https://github.com/google/brotli
  64      Supports both 'brotlipy' and 'Brotli' packages since they share an import
  65      name. The top branches are for 'brotlipy' and bottom branches for 'Brotli'
  66      rr!cCsNtdur	td�d�t��|_d|_|t|jd�r |jj|_dS|jj|_dS)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�ImportErrorZDecompressorr&�	seen_data�hasattrr)�_decompress�processrrrrr'vs��
  67  zBrotliDecoder.__init__rrc
  68  CsD|sdSd|_z|�|�WStjy!}ztt|��|�d}~ww�NrT)r;r=r9r*rr,r7rrrr�s��zBrotliDecoder.decodec
  69  CsP|jsdSzt|jd�r|j��WdStjy'}ztt|��|�d}~ww)Nr�finish)r;r<r&r@r9r*rr,r0rrrr�s
  70  ��zBrotliDecoder.flushNr2rrr3rrrrr8ls
  71  
  72  	
  73  	r8c@r)�ZStandardDecoderz�
  74      Handle 'zstd' RFC 8878 decoding.
  75  
  76      Requires `pip install zstandard`.
  77      Can be installed as a dependency of httpx using `pip install httpx[zstd]`.
  78      rr!cCs*tdur	td�d�t����|_d|_dS)NzXUsing 'ZStandardDecoder', ...Make sure to install httpx using `pip install httpx[zstd]`.F)�	zstandardr:�ZstdDecompressorr%r&r;rrrrr'�s��
  79  zZStandardDecoder.__init__rrc
  80  Cs�tdusJ�d|_t��}zA|�|j�|��|jjr@|jjrJ|jj}t�	��
  81  �|_|�|j�|��|jjrE|jjsW|��SW|��SW|��SW|��Stjyb}ztt
  82  |��|�d}~wwr")rBr;�io�BytesIO�writer&r)�eof�unused_datarCr%Z	ZstdErrorrr,�getvalue)rr�outputrHr-rrrr�s*�������zZStandardDecoder.decodecCs,|jsdS|j��}|jjstd��t|�S)NrzZstandard data is incomplete)r;r&rrGrr)r�retrrrr�s
  83  zZStandardDecoder.flushNr2rrr3rrrrrA�s
  84  
  85  
  86  
  87  rAc@s.eZdZdZddd�Zdd
  88  d�Zddd
  89  �ZdS)�MultiDecoderzE
  90      Handle the case where multiple encodings have been applied.
  91      �children�typing.Sequence[ContentDecoder]rr!cCstt|��|_dS)zm
  92          'children' should be a sequence of decoders in the order in which
  93          each was applied.
  94          N)�list�reversedrM)rrMrrrr'�szMultiDecoder.__init__rrcCs|jD]}|�|�}q|Sr
  95  )rMr�rr�childrrrr�s
  96  zMultiDecoder.decodecCs&d}|jD]}|�|�|��}q|Sr)rMrrrQrrrr�s
  97  zMultiDecoder.flushN)rMrNrr!rrr3rrrrrL�s
  98  
  99  
 100  rLc@�0eZdZdZdddd�Zddd
 101  �Zddd�ZdS)�ByteChunkerz>
 102      Handles returning byte content in fixed-size chunks.
 103      N�
 104  chunk_size�
 105  int | Nonerr!cC�t��|_||_dSr
 106  )rDrE�_buffer�_chunk_size�rrUrrrr'��
 107  
 108  zByteChunker.__init__�contentr�list[bytes]c���jdur|r
 109  |gSgS�j�|��j���jkr_�j�����fdd�tdt���j�D�}t|d��jkrF�j�d��j��|S�j�d��j�|d��j��|dd�SgS)Nc�g|]}�||�j��qSr�rY��.0�i�r�valuerr�
 110  <listcomp>����z&ByteChunker.decode.<locals>.<listcomp>r������	rYrXrF�tellrI�range�len�seek�truncate�rr\�chunksrrdrr��"
 111  
 112  �
 113  
 114  zByteChunker.decodecC�.|j��}|j�d�|j��|r|gSgS�Nr�rXrIrmrnrdrrrr�
 115  
 116  zByteChunker.flushr
 117  �rUrVrr!)r\rrr])rr]r3rrrrrT��
 118  
 119  rTc@rS)�TextChunkerz>
 120      Handles returning text content in fixed-size chunks.
 121      NrUrVrr!cCrWr
 122  )rD�StringIOrXrYrZrrrr'r[zTextChunker.__init__r\r,�	list[str]cr^)Ncr_rr`rardrrrfrgz&TextChunker.decode.<locals>.<listcomp>rrhrirorrdrrrqzTextChunker.decodecCrrrsrtrdrrrr+ruzTextChunker.flushr
 123  rv)r\r,rrz�rrzr3rrrrrxrwrxc@s0eZdZdZdddd�Zddd�Zdd
 124  d�ZdS)�TextDecoderz8
 125      Handles incrementally decoding bytes into text
 126      �utf-8�encodingr,rr!cCst�|�dd�|_dS)N�replace)�errors)�codecs�getincrementaldecoder�decoder)rr~rrrr'7r6zTextDecoder.__init__rrcCs|j�|�Sr
 127  �r�rr
 128  rrrr:szTextDecoder.decodecCs|j�dd�Sr?r�rrrrr=szTextDecoder.flushN)r})r~r,rr!)rrrr,)rr,r3rrrrr|2s
 129  
 130  r|c@s.eZdZdZddd�Zdd	d
 131  �Zddd�Zd
 132  S)�LineDecoderz�
 133      Handles incrementally reading lines from text.
 134  
 135      Has the same behaviour as the stdllib splitlines,
 136      but handling the input iteratively.
 137      rr!cCsg|_d|_dSr()�buffer�trailing_crrrrrr'Is
 138  zLineDecoder.__init__�textr,rzcCs�d}|jrd|}d|_|�d�rd|_|dd�}|sgS|d|v}|��}t|�dkr:|s:|j�|d�gS|jrQd�|j�|dg|dd�}g|_|sY|��g|_|S)	Nu
 139  
 140  …

�
 141  FTrhrr�)r��endswith�
 142  splitlinesrlr��append�join�pop)rr�Z
 143  NEWLINE_CHARSZtrailing_newline�linesrrrrMs(
 144  "zLineDecoder.decodecCs.|js|jsgSd�|j�g}g|_d|_|S)Nr�F)r�r�r�)rr�rrrrsszLineDecoder.flushNr2)r�r,rrzr{r3rrrrr�As
 145  
 146  
 147  &r�)�identity�gzip�deflate�br�zstdr�r�)r�
 148  __future__rr�rD�typingr$�_exceptionsrr9r:Z
 149  brotlicffirBrrr r4r8rArLrTrxr|r�ZSUPPORTED_DECODERSr�rrrr�<module>sX���
 150  �5*''=�	
 151  �