
    tcȦ                        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	 d dl
mZmZ ddlmZmZmZmZ ddlmZmZmZmZmZmZmZmZ ddlmZmZmZmZm Z m!Z!m"Z" ddl#m$Z$ dd	l%m&Z& dd
l'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<  G d dej=        e>e>f                   Z? G d d          Z@ G d d          ZA G d dej=        e>e>f                   ZBdS )    N)Mapping)Cookie	CookieJar   )
ByteStreamUnattachedStreamencode_requestencode_response)SUPPORTED_DECODERSByteChunkerContentDecoderIdentityDecoderLineDecoderMultiDecoderTextChunkerTextDecoder)CookieConflictHTTPStatusErrorRequestNotReadResponseNotReadStreamClosedStreamConsumedrequest_context)(get_multipart_boundary_from_content_type)codes)AsyncByteStreamCookieTypesHeaderTypesQueryParamTypesRequestContentRequestDataRequestExtensionsRequestFilesResponseContentResponseExtensionsSyncByteStream)URL)guess_json_utfis_known_encodingnormalize_header_keynormalize_header_valueobfuscate_sensitive_headersparse_content_type_charsetparse_header_linksc                      e Zd ZdZ	 	 d dej        e         dej        e         ddfdZe	defd            Z
e
j        deddfd	            Z
e	dej        ej        eef                  fd
            Zdej        e         fdZdej        e         fdZdej        eef         fdZdej        ej        eef                  fdZd!dedej        dej        fdZd"dededej        e         fdZd!dej        e         ddfdZd#dZdedefdZdededdfdZdeddfdZdej        defdZ dej!        ej                 fdZ"de#fdZ$dej        defdZ%defdZ&dS )$Headersz9
    HTTP headers, as a case-insensitive multi-dict.
    Nheadersencodingreturnc                 $   |g | _         n}t          |t                    rt          |j                   | _         nNt          |t                    r&fd|                                D             | _         nfd|D             | _         | _        d S )Nc                 |    g | ]8\  }}t          |d           t          |d          t          |          f9S F)lowerr2   Tr*   r+   .0kvr2   s      //usr/lib/python3/dist-packages/httpx/_models.py
<listcomp>z$Headers.__init__.<locals>.<listcomp>G   b        Aq	 )%(KKK($JJJ*1h77      c                 |    g | ]8\  }}t          |d           t          |d          t          |          f9S r6   r8   r9   s      r=   r>   z$Headers.__init__.<locals>.<listcomp>P   r?   r@   )_list
isinstancer0   listr   items	_encoding)selfr1   r2   s     `r=   __init__zHeaders.__init__=   s    
 ?DJJ)) 	gm,,DJJ)) 	    $MMOO  DJJ    $  DJ "r@   c                     | j         ^dD ]T}| j        D ]A\  }}	 |                    |           |                    |           1# t          $ r Y  nw xY w|| _          nUd| _         | j         S )zn
        Header encoding is mandated as ascii, but we allow fallbacks to utf-8
        or iso-8859-1.
        N)asciiutf-8z
iso-8859-1)rF   rawdecodeUnicodeDecodeError)rG   r2   keyvalues       r=   r2   zHeaders.encoding[   s     >!. . ."&( 
 
JC

8,,,X....-   
 &.DNE  ".~s   *A
AArP   c                     || _         d S NrF   rG   rP   s     r=   r2   zHeaders.encodingt       r@   c                 $    d | j         D             S )zH
        Returns a list of the raw header items, as byte pairs.
        c                     g | ]
\  }}}||fS  rX   )r:   raw_key_rP   s       r=   r>   zHeaders.raw.<locals>.<listcomp>}   s$    EEE%6Wa% EEEr@   rB   rG   s    r=   rL   zHeaders.rawx   s    
 FE$*EEEEr@   c                 N      fd j         D                                             S )Nc                 N    i | ]!\  }}}|                     j                  d "S rR   rM   r2   r:   rZ   rO   rP   rG   s       r=   
<dictcomp>z Headers.keys.<locals>.<dictcomp>   s/    PPPMAsE

4=))4PPPr@   )rB   keysr\   s   `r=   rb   zHeaders.keys   s+    PPPPTZPPPUUWWWr@   c                     i }| j         D ]W\  }}}|                    | j                  }|                    | j                  }||v r||xx         d| z  cc<   R|||<   X|                                S )N, )rB   rM   r2   valuesrG   values_dictrZ   rO   rP   str_key	str_values          r=   re   zHeaders.values   s    -/!Z 	1 	1MAsEjj//GT]33I+%%G$$$(8Y(8(88$$$$'0G$$!!###r@   c                     i }| j         D ]W\  }}}|                    | j                  }|                    | j                  }||v r||xx         d| z  cc<   R|||<   X|                                S )z
        Return `(key, value)` items of headers. Concatenate headers
        into a single comma separated value when a key occurs multiple times.
        rd   )rB   rM   r2   rE   rf   s          r=   rE   zHeaders.items   s    
 .0!Z 	1 	1MAsEjj//GT]33I+%%G$$$(8Y(8(88$$$$'0G$$  """r@   c                 *      fd j         D             S )z
        Return a list of `(key, value)` pairs of headers. Allow multiple
        occurrences of the same key without concatenating into a single
        comma separated value.
        c                     g | ]:\  }}}|                     j                  |                     j                  f;S rX   r_   r`   s       r=   r>   z'Headers.multi_items.<locals>.<listcomp>   sP     
 
 
3 ZZ&&T](C(CD
 
 
r@   r[   r\   s   `r=   multi_itemszHeaders.multi_items   s0    
 
 
 
!%
 
 
 	
r@   rO   defaultc                 8    	 | |         S # t           $ r |cY S w xY w)z
        Return a header value. If multiple occurrences of the header occur
        then concatenate them together with commas.
        )KeyError)rG   rO   rn   s      r=   getzHeaders.get   s5    
	9 	 	 	NNN	s   
 Fsplit_commasc                     |                                                      j                   fd j        D             }|s|S g }|D ]4}|                    d |                    d          D                        5|S )z
        Return a list of all header values for a given key.
        If `split_commas=True` is passed, then any comma separated header
        values are split into multiple return strings.
        c                 |    g | ]8\  }}}|                                 k    |                    j                  9S rX   )r7   rM   r2   )r:   rZ   item_key
item_valueget_header_keyrG   s       r=   r>   z$Headers.get_list.<locals>.<listcomp>   sN     
 
 
'8Z~~>11 dm,,111r@   c                 6    g | ]}|                                 S rX   )strip)r:   items     r=   r>   z$Headers.get_list.<locals>.<listcomp>   s      K K K$ K K Kr@   ,)r7   encoder2   rB   extendsplit)rG   rO   rr   re   split_valuesrP   rw   s   `     @r=   get_listzHeaders.get_list   s     ++DM::
 
 
 
 
+/:
 
 
  	M 	M 	ME K K%++c:J:J K K KLLLLr@   c                     t          |          }|                                D ]}|| v r|                     |           | j                            |j                   d S rR   )r0   rb   poprB   r}   )rG   r1   rO   s      r=   updatezHeaders.update   s]    '""<<>> 	 	Cd{{
'-(((((r@   c                 .    t          | | j                  S )Nr2   )r0   r2   r\   s    r=   copyzHeaders.copy   s    tdm4444r@   c                      |                                                      j                   fd j        D             }|rd                    |          S t          |          )z
        Return a single header value.

        If there are multiple headers with the same key, then we concatenate
        them with commas. See: https://tools.ietf.org/html/rfc7230#section-3.2.2
        c                 X    g | ]&\  }}}|k    |                     j                  'S rX   r_   )r:   rZ   
header_keyheader_valuenormalized_keyrG   s       r=   r>   z'Headers.__getitem__.<locals>.<listcomp>   sD     
 
 
+:|^++ ..+++r@   rd   )r7   r|   r2   rB   joinrp   )rG   rO   rE   r   s   `  @r=   __getitem__zHeaders.__getitem__   sz     ++DM::
 
 
 
 
/3z
 
 
  	$99U###smmr@   c                    |                     | j        pd          }|                     | j        pd          }|                                fdt          | j                  D             }t          |dd                   D ]
}| j        |= |r|d         }||f| j        |<   dS | j                            ||f           dS )zs
        Set the header `key` to `value`, removing any duplicate entries.
        Retains insertion order.
        rK   c                 .    g | ]\  }\  }}}|k    |S rX   rX   )r:   idxrZ   ru   
lookup_keys       r=   r>   z'Headers.__setitem__.<locals>.<listcomp>   s9     
 
 
%%a1:%% %%%r@   r   Nr   )r|   rF   r7   	enumeraterB   reversedappend)rG   rO   rP   set_key	set_valuefound_indexesr   r   s          @r=   __setitem__zHeaders.__setitem__   s    
 **T^6w77LL!:7;;	]]__

 
 
 
)24:)>)>
 
 
 M!""-.. 	  	 C
3 	@"C&
I>DJsOOOJw
I>?????r@   c                     |                                                     | j                  fdt          | j                  D             }|st          |          t          |          D ]
}| j        |= dS )z*
        Remove the header `key`.
        c                 R    g | ]#\  }\  }}}|                                 k    !|$S rX   )r7   )r:   r   rZ   ru   del_keys       r=   r>   z'Headers.__delitem__.<locals>.<listcomp>  sC     
 
 
%%a1~~7** ***r@   N)r7   r|   r2   r   rB   rp   r   )rG   rO   pop_indexesr   r   s       @r=   __delitem__zHeaders.__delitem__   s     ))++$$T]33
 
 
 
)24:)>)>
 
 
  	 3--K(( 	  	 C
3	  	 r@   c                     |                                                     | j                  }|d | j        D             v S )Nc                     g | ]\  }}}|	S rX   rX   )r:   rZ   rO   s      r=   r>   z(Headers.__contains__.<locals>.<listcomp>  s    >>>iaac>>>r@   )r7   r|   r2   rB   )rG   rO   r   s      r=   __contains__zHeaders.__contains__  s;    YY[[''66
>>4:>>>>>r@   c                 D    t          |                                           S rR   )iterrb   r\   s    r=   __iter__zHeaders.__iter__  s    DIIKK   r@   c                 *    t          | j                  S rR   )lenrB   r\   s    r=   __len__zHeaders.__len__  s    4:r@   otherc                     	 t          |          }n# t          $ r Y dS w xY wd | j        D             }d |j        D             }t          |          t          |          k    S )NFc                     g | ]
\  }}}||fS rX   rX   r:   rZ   rO   rP   s       r=   r>   z"Headers.__eq__.<locals>.<listcomp>  s"    BBBmaec5\BBBr@   c                     g | ]
\  }}}||fS rX   rX   r   s       r=   r>   z"Headers.__eq__.<locals>.<listcomp>   s"    LLL}q#usElLLLr@   )r0   
ValueErrorrB   sorted)rG   r   other_headers	self_list
other_lists        r=   __eq__zHeaders.__eq__  s    	#ENNMM 	 	 	55	 CBtzBBB	LL8KLLL
i  F:$6$666s    
  c                 .   | j         j        }d}| j        dk    r
d| j        }t          t	          |                                                     }t          |          }t          |          t          |          k    }|r
| d|| dS | d|| dS )N rJ   z, encoding=())	__class____name__r2   rD   r,   rm   dictr   )rG   
class_nameencoding_stras_listas_dictno_duplicate_keyss         r=   __repr__zHeaders.__repr__#  s    ^,
=G##:::L243C3C3E3EFFGGw--LLCLL8 	> ==7=l====99w9,9999r@   NNrR   )F)r3   r0   )'r   
__module____qualname____doc__typingOptionalr   strrH   propertyr2   setterListTuplebytesrL   KeysViewrb   
ValuesViewre   	ItemsViewrE   rm   Anyrq   boolr   r   r   r   r   r   r   Iteratorr   intr   r   r   rX   r@   r=   r0   r0   8   s[         15)-" "-" /#&" 
	" " " "< #    X0 _c d    _ FV[eUl!;< F F F XFXfoc* X X X X	$)#. 	$ 	$ 	$ 	$#v'S1 # # # #	
V[c3h)?@ 	
 	
 	
 	
 s VZ 6:     C t C@P    ,) )fok: )d ) ) ) )5 5 5 5s s    (@s @3 @4 @ @ @ @0 s  t        $?
 ?t ? ? ? ?!&/&*5 ! ! ! !    7FJ 74 7 7 7 7:# : : : : : :r@   r0   c                   0   e Zd Zdddddddddd	dej        eef         dej        def         dej        e         dej        e	         dej        e
         d	ej        e         d
ej        e         dej        e         dej        ej                 dej        eedf         dej        e         fdZdej        eef         ddfdZedefd            ZdefdZdefdZdefdZdej        eej        f         fdZdej        eej        f         ddfdZdS )RequestN)	paramsr1   cookiescontentdatafilesjsonstream
extensionsmethodurlr'   r   r1   r   r   r   r   r   r   r   c       	            t          |t                    r'|                    d                                          n|                                | _        t          |          | _        | | j                            |          | _        t          |          | _	        |i n|| _
        |r"t          |                              |            |
| j	                            d          }t          ||||	t          |r|                    | j	        j                  nd                     \  }}
|                     |           |
| _        t          |
t(                    r|                                  d S d S |
| _        d S )NrJ   )r   zcontent-type)content_type)r   r   r   r   boundary)rC   r   rM   upperr   r'   r   copy_merge_paramsr0   r1   r   Cookiesset_cookie_headerrq   r	   r   r|   r2   _preparer   r   read)rG   r   r   r   r1   r   r   r   r   r   r   r   r   s                r=   rH   zRequest.__init__4  s   " &%(( FMM'""((*** 	
 s88x111@@DHw'' * 2""
 	5G..t444>151A1A.1Q1QL,A#"!4!4T\5J!K!K!K  
 
 
OGV MM'""" DK&*-- 		   !DKKKr@   default_headersr3   c                    |                                 D ]B\  }}|                                dk    r
d| j        v r'| j                            ||           Cg }d| j        v }d| j        v pd| j        v }|s-| j        j        r!|                    d| j        j        f           |s| j        dv r|                    d           t          || j        j
        z             | _        d S )Ntransfer-encodingzContent-LengthHostzTransfer-Encodings   Host)POSTPUTPATCH)s   Content-Length   0)rE   r7   r1   
setdefaultr   hostr   netlocr   r0   rL   )rG   r   rO   rP   auto_headershas_hosthas_content_lengths          r=   r   zRequest._prepares  s   )//11 	0 	0JCyy{{1116F$,6V6VL##C////@BT\),S0Ct|0S 	  	<DHM 	<$(/ :;;;! 	;dk5M&M&M 9:::|dl.>>??r@   c                 L    t          | d          st                      | j        S N_content)hasattrr   r   r\   s    r=   r   zRequest.content  s(    tZ(( 	# """}r@   c                    t          | d          sst          | j        t          j                  sJ d                    | j                  | _        t          | j        t                    st          | j                  | _        | j        S )6
        Read and return the request content.
        r   r@   )r   rC   r   r   Iterabler   r   r   r\   s    r=   r   zRequest.read  st     tZ(( 	8dk6?;;;;;HHT[11DMdk:66 8 )77}r@   c                 :  K   t          | d          st          | j        t          j                  sJ d                    d | j        2              d{V           | _        t          | j        t                    st          | j                  | _        | j        S )r   r   r@   c                 "   K   g | 3 d {V }|
6 S rR   rX   r:   parts     r=   r>   z!Request.aread.<locals>.<listcomp>  s.      %I%I%I%I%I%I%I%ITd%I%I%I%I   N)r   rC   r   r   AsyncIterabler   r   r   r\   s    r=   areadzRequest.aread  s       tZ(( 	8dk6+?@@@@@HH%I%IT[%I%I%I%I%I%I%I%I%IJJDMdk:66 8 )77}r@   c                 d    | j         j        }t          | j                  }d| d| j        d|dS )N<r   rd   z)>)r   r   r   r   r   )rG   r   r   s      r=   r   zRequest.__repr__  s<    ^,
$(mm::::::::::r@   c                 H    d | j                                         D             S )Nc                 "    i | ]\  }}|d v	||S ))r   r   rX   r:   namerP   s      r=   ra   z(Request.__getstate__.<locals>.<dictcomp>  s4     
 
 
e333 %333r@   __dict__rE   r\   s    r=   __getstate__zRequest.__getstate__  1    
 
#}2244
 
 
 	
r@   statec                     |                                 D ]\  }}t          | ||           i | _        t                      | _        d S rR   )rE   setattrr   r   r   rG   r  r  rP   s       r=   __setstate__zRequest.__setstate__  sJ     ;;== 	' 	'KD%D$&&&&&((r@   )r   r   r   r   Unionr   r   r   r   r   r   r    r!   r#   r   r&   r   r"   rH   Dictr   r   r   r   r  r   r  r  rX   r@   r=   r   r   3  s        48040437-1/3,0FJ9==! =! =!S%Z(=! \%*%=!
 0=! -=! -=! 0=! ok*=! |,=! ofj)=! ^_dBC=! O$56=! =! =! =!~@CH(= @$ @ @ @ @*     X
e    U    ;# ; ; ; ;

fk#vz/: 
 
 
 
)&+c6:o"> )4 ) ) ) ) ) )r@   r   c                   <   e Zd Zddddddddddd
dedej        e         dej        e         dej        e         dej        e         d	ej	        d
ej
        eedf         dej        e         dej        e         dej        ej        d                   dej
        eej        egef         f         fdZdej        eef         ddfdZedej        fd            Zej        dej        ddfd            Zedefd            Zej        deddfd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Z edej        e         fd            Z!e!j        deddfd            Z!edej        e         fd             Z"de#fd!Z$ede%fd"            Z&ede%fd#            Z'ede%fd$            Z(ede%fd%            Z)ede%fd&            Z*ede%fd'            Z+ede%fd(            Z,dAd)Z-d*ej	        dej	        fd+Z.edBd-            Z/edej        ej        e         ej        eef         f         fd.            Z0edefd/            Z1defd0Z2dej        eej	        f         fd1Z3d2ej        eej	        f         ddfd3Z4defd4Z5	 dCd5ej        e         dej6        e         fd6Z7	 dCd5ej        e         dej6        e         fd7Z8dej6        e         fd8Z9	 dCd5ej        e         dej6        e         fd9Z:dAd:Z;defd;Z<	 dCd5ej        e         dej=        e         fd<Z>	 dCd5ej        e         dej=        e         fd=Z?dej=        e         fd>Z@	 dCd5ej        e         dej=        e         fd?ZAdAd@ZBdS )DResponseNrK   )
r1   r   texthtmlr   r   requestr   historydefault_encodingstatus_coder1   r   r  r  r   r   r  r   r  r  c       
            || _         t          |          | _        || _        d | _        |	i n|	| _        |
g nt          |
          | _        d| _        d| _	        || _
        |[t          ||||          \  }}|                     |           || _        t          |t                    r|                                  n|| _        d| _        d S )NFr   )r  r0   r1   _requestnext_requestr   rD   r  	is_closedis_stream_consumedr  r
   r   r   rC   r   r   _num_bytes_downloaded)rG   r  r1   r   r  r  r   r   r  r   r  r  s               r=   rH   zResponse.__init__  s     'w''29 7; * 2""
$_rr$w--"' 0>-gtT4HHOGVMM'""" DK&*-- 		 !DK%&"""r@   r   r3   c                     |                                 D ]B\  }}|                                dk    r
d| j        v r'| j                            ||           Cd S )Nr   zcontent-length)rE   r7   r1   r   )rG   r   rO   rP   s       r=   r   zResponse._prepare  sj    )//11 	0 	0JCyy{{1116F$,6V6VL##C////		0 	0r@   c                 N    t          | d          st          d          | j        S )ze
        Returns the time taken for the complete request/response
        cycle to complete.
        _elapsedzK'.elapsed' may only be accessed after the response has been read or closed.)r   RuntimeErrorr$  r\   s    r=   elapsedzResponse.elapsed  s7     tZ(( 	+   }r@   r&  c                     || _         d S rR   )r$  )rG   r&  s     r=   r&  zResponse.elapsed	  s    r@   c                 <    | j         t          d          | j         S )zR
        Returns the request instance associated to the current response.
        Nz7The request instance has not been set on this response.)r  r%  r\   s    r=   r  zResponse.request  s+    
 = I   }r@   rP   c                     || _         d S rR   )r  rT   s     r=   r  zResponse.request  s    r@   c                 n    	 | j         d         }|                    dd          S # t          $ r Y dS w xY w)Nhttp_versionrJ   ignoreerrorszHTTP/1.1)r   rM   rp   )rG   r+  s     r=   r+  zResponse.http_version  sS    	A"&/."AL  &&wx&@@@  	 	 	::	s   & 
44c                     	 | j         d         }|                    dd          S # t          $ r t          j        | j                  cY S w xY w)Nreason_phraserJ   r,  r-  )r   rM   rp   r   get_reason_phraser  )rG   r0  s     r=   r0  zResponse.reason_phrase%  sf    	B#'??#CM !'''AAA  	= 	= 	=*4+;<<<<<	=s   & #AAc                     | j         j        S )zA
        Returns the URL for which the request was made.
        )r  r   r\   s    r=   r   zResponse.url.  s    
 |r@   c                 L    t          | d          st                      | j        S r   )r   r   r   r\   s    r=   r   zResponse.content5  s(    tZ(( 	$!###}r@   c                    t          | d          sn| j        }|sd| _        n]t          | j        pd          }d                    |                    | j                  |                                g          | _        | j        S )N_textr   rK   r   )r   r   r5  r   r2   r   rM   flush)rG   r   decoders      r=   r  zResponse.text;  s{    tW%% 	VlG V

%t}/GHHHWWgnnT\&B&BGMMOO%TUU
zr@   c                 
   t          | d          sm| j        }|t          |          sLt          | j        t
                    r| j        }n*t          | d          r|                     | j                  }|pd| _        | j        S )a  
        Return an encoding to use for decoding the byte content into text.
        The priority for determining this is given by...

        * `.encoding = <>` has been set explicitly.
        * The encoding as specified by the charset parameter in the Content-Type header.
        * The encoding as determined by `default_encoding`, which may either be
          a string like "utf-8" indicating the encoding to use, or may be a callable
          which enables charset autodetection.
        rF   Nr   rK   )r   charset_encodingr)   rC   r  r   r   rF   )rG   r2   s     r=   r2   zResponse.encodingF  s     t[)) 	1,H'8'B'Bd3S99 D#4HHT:.. D#44T]CCH%0DN~r@   c                     || _         d S rR   rS   rT   s     r=   r2   zResponse.encoding\  rU   r@   c                 \    | j                             d          }|dS t          |          S )zO
        Return the encoding, as specified by the Content-Type header.
        zContent-TypeN)r1   rq   r-   )rG   r   s     r=   r9  zResponse.charset_encoding`  s2    
 |''774),777r@   c                    t          | d          sg }| j                            dd          }|D ]c}|                                                                }	 t
          |         }|                     |                       T# t          $ r Y `w xY wt          |          dk    r|d         | _	        n<t          |          dk    rt          |          | _	        nt                      | _	        | j	        S )z
        Returns a decoder instance which can be used to decode the raw byte
        content, depending on the Content-Encoding used in the response.
        _decoderzcontent-encodingT)rr   r   r   )children)r   r1   r   ry   r7   r   r   rp   r   r=  r   r   )rG   decodersre   rP   decoder_clss        r=   _get_content_decoderzResponse._get_content_decoderk  s   
 tZ(( 	246H\**+=D*QQF  ++--"4U";KOOKKMM2222   H 8}}!! (X"" ,h ? ? ? / 1 1}s   *B
BBc                 4    t          j        | j                  S )zU
        A property which is `True` for 1xx status codes, `False` otherwise.
        )r   is_informationalr  r\   s    r=   rC  zResponse.is_informational  s    
 %d&6777r@   c                 4    t          j        | j                  S )zU
        A property which is `True` for 2xx status codes, `False` otherwise.
        )r   
is_successr  r\   s    r=   rE  zResponse.is_success  s    
  0111r@   c                 4    t          j        | j                  S )a  
        A property which is `True` for 3xx status codes, `False` otherwise.

        Note that not all responses with a 3xx status code indicate a URL redirect.

        Use `response.has_redirect_location` to determine responses with a properly
        formed URL redirection.
        )r   is_redirectr  r\   s    r=   rG  zResponse.is_redirect  s      !1222r@   c                 4    t          j        | j                  S )zU
        A property which is `True` for 4xx status codes, `False` otherwise.
        )r   is_client_errorr  r\   s    r=   rI  zResponse.is_client_error      
 $T%5666r@   c                 4    t          j        | j                  S )zU
        A property which is `True` for 5xx status codes, `False` otherwise.
        )r   is_server_errorr  r\   s    r=   rL  zResponse.is_server_error  rJ  r@   c                 4    t          j        | j                  S )z]
        A property which is `True` for 4xx and 5xx status codes, `False` otherwise.
        )r   is_errorr  r\   s    r=   rN  zResponse.is_error  s    
 ~d.///r@   c                     | j         t          j        t          j        t          j        t          j        t          j        fv od| j        v S )zs
        Returns True for 3xx responses with a properly formed URL redirection,
        `False` otherwise.
        Location)r  r   MOVED_PERMANENTLYFOUND	SEE_OTHERTEMPORARY_REDIRECTPERMANENT_REDIRECTr1   r\   s    r=   has_redirect_locationzResponse.has_redirect_location  sH      '(( + dl*	
r@   c                     | j         }|t          d          | j        rdS | j        rd}nd}| j        dz  }dddd	d
}|                    |d          }|                    | |          }t          |||           )z>
        Raise the `HTTPStatusError` if one occurred.
        NzYCannot call `raise_for_status` as the request instance has not been set on this response.z{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'
Redirect location: '{0.headers[location]}'
For more information check: https://httpstatuses.com/{0.status_code}z{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'
For more information check: https://httpstatuses.com/{0.status_code}d   zInformational responsezRedirect responsezClient errorzServer error)r            zInvalid status code)
error_type)r  response)r  r%  rE  rV  r  rq   formatr   )rG   r  messagestatus_classerror_typesr\  s         r=   raise_for_statuszResponse.raise_for_status  s     -?>  
 ? 	F% 
	W GW 
 '3.'"	
 
 !__\3HII
..*.==gwFFFFr@   kwargsc                     | j         _| j        rXt          | j                  dk    r@t          | j                  }|*t	          j        | j                            |          fi |S t	          j        | j        fi |S )NrY  )r9  r   r   r(   jsonlibloadsrM   r  )rG   rc  r2   s      r=   r   zResponse.json  s~     (T\(c$,>O>ORS>S>S%dl33H#}T\%8%8%B%BMMfMMM}TY11&111r@   r   c                     t          | d          s-t                      | _        | j                            |            | j        S )N_cookies)r   r   rh  extract_cookiesr\   s    r=   r   zResponse.cookies  s=    tZ(( 	0#IIDMM))$///}r@   c                     | j                             d          }i }|rCt          |          }|D ]1}|                    d          p|                    d          }|||<   2|S )zI
        Returns the parsed header links of the response, if any
        linkrelr   )r1   rq   r.   )rG   headerldictlinksrk  rO   s         r=   ro  zResponse.links  sp    
 !!&)) 	"&v..E " "hhuoo8%!c

r@   c                     | j         S rR   )r!  r\   s    r=   num_bytes_downloadedzResponse.num_bytes_downloaded  s    ))r@   c                 (    d| j          d| j         dS )Nz<Response [ ]>)r  r0  r\   s    r=   r   zResponse.__repr__  s!    FT-FF0BFFFFr@   c                 H    d | j                                         D             S )Nc                 "    i | ]\  }}|d v	||S ))r   r   r  r=  rX   r  s      r=   ra   z)Response.__getstate__.<locals>.<dictcomp>  s4     
 
 
eLLL %LLLr@   r	  r\   s    r=   r  zResponse.__getstate__  r  r@   r  c                     |                                 D ]\  }}t          | ||           d| _        i | _        t	                      | _        d S )NT)rE   r  r  r   r   r   r  s       r=   r  zResponse.__setstate__  sQ     ;;== 	' 	'KD%D$&&&&&((r@   c                     t          | d          s,d                    |                                           | _        | j        S )7
        Read and return the response content.
        r   r@   )r   r   
iter_bytesr   r\   s    r=   r   zResponse.read   s;     tZ(( 	8HHT__%6%677DM}r@   
chunk_sizec              #     K   t          | d          rb|t          | j                  n|}t          dt          | j                  t	          |d                    D ]}| j        |||z            V  dS |                                 }t          |          }t          | j                  5  | 	                                D ]3}|
                    |          }|
                    |          D ]}|V  4|                                }|
                    |          D ]}|V  |                                D ]}|V  	 ddd           dS # 1 swxY w Y   dS z
        A byte-iterator over the decoded response content.
        This allows us to handle gzip, deflate, and brotli encoded responses.
        r   Nr   r   r{  r  )r   r   r   rangemaxrA  r   r   r  iter_rawrM   r6  rG   r{  ir7  chunker	raw_bytesdecodedchunks           r=   rz  zResponse.iter_bytes(  s      4$$ 	 /9/AT]+++zJ1c$-00#j!2D2DEE 8 8mAJ$6777778 8 //11G!Z888G 777 	  	 !% $ $I%nnY77G!(!8!8 $ $#$!--//$^^G44    EKKKK$]]__    EKKKK 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   .BEEEc              #     K   t          | j        pd          }t          |          }t          | j                  5  |                                 D ]3}|                    |          }|                    |          D ]}|V  4|                                }|                    |          D ]}|V  |                                D ]}|V  	 ddd           dS # 1 swxY w Y   dS z
        A str-iterator over the decoded response content
        that handles both gzip, deflate, etc but also detects the content's
        string encoding.
        rK   r   r~  r  N)r   r2   r   r   r  rz  rM   r6  rG   r{  r7  r  byte_contenttext_contentr  s          r=   	iter_textzResponse.iter_textA  sU      t}'?@@@444T]333 		 		 $ 1 1    &~~l;;$^^L99    EKKKK "==??L 55     		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s   BC!!C%(C%c              #      K   t                      }t          | j                  5  |                                 D ]}|                    |          D ]}|V  |                                D ]}|V  	 d d d            d S # 1 swxY w Y   d S Nr  )r   r   r  r  rM   r6  rG   r7  r  lines       r=   
iter_lineszResponse.iter_linesV  s      --T]333 	 	((  #NN400  DJJJJ  



		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   ABB
Bc              #   ,  K   | j         rt                      | j        rt                      t	          | j        t                    st          d          d| _         d| _        t          |          }t          | j                  5  | j        D ];}| xj        t          |          z  c_        |                    |          D ]}|V  <	 ddd           n# 1 swxY w Y   |                                D ]}|V  |                                  dS )@
        A byte-iterator over the raw response content.
        z5Attempted to call a sync iterator on an async stream.Tr   r~  r  N)r   r   r  r   rC   r   r&   r%  r!  r   r   r  r   rM   r6  closerG   r{  r  raw_stream_bytesr  s        r=   r  zResponse.iter_raw_  st      " 	# """> 	!.. $+~66 	XVWWW"&%&"444T]333 	  	 $(K     **c2B.C.CC**$^^,<==    EKKKK  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  ]]__ 	 	EKKKK

s   	ACC!Cc                    t          | j        t                    st          d          | j        sPd| _        t          | j                  5  | j                                         ddd           dS # 1 swxY w Y   dS dS )
        Close the response and release the connection.
        Automatically called if the response body is read to completion.
        z3Attempted to call an sync close on an async stream.Tr  N)rC   r   r&   r%  r  r   r  r  r\   s    r=   r  zResponse.close{  s    
 $+~66 	VTUUU~ 	$!DN 777 $ $!!###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $	$ 	$s   A44A8;A8c                    K   t          | d          s<d                    d |                                 2              d{V           | _        | j        S )ry  r   r@   c                 "   K   g | 3 d {V }|
6 S rR   rX   r   s     r=   r>   z"Response.aread.<locals>.<listcomp>  s.      %P%P%P%P%P%P%P%PTd%P%P%P%Pr   N)r   r   aiter_bytesr   r\   s    r=   r  zResponse.aread  sc       tZ(( 	RHH%P%PT=M=M=O=O%P%P%P%P%P%P%P%P%PQQDM}r@   c                  K   t          | d          rc|t          | j                  n|}t          dt          | j                  t	          |d                    D ]}| j        |||z            W V  dS |                                 }t          |          }t          | j                  5  | 	                                2 3 d{V }|
                    |          }|
                    |          D ]}|W V  :6 |                                }|
                    |          D ]}|W V  |                                D ]}|W V  	 ddd           dS # 1 swxY w Y   dS r}  )r   r   r   r  r  rA  r   r   r  	aiter_rawrM   r6  r  s           r=   r  zResponse.aiter_bytes  s      4$$ 	 /9/AT]+++zJ1c$-00#j!2D2DEE 8 8mAJ$67777778 8 //11G!Z888G 777 	  	 '+~~'7'7 $ $ $ $ $ $ $)%nnY77G!(!8!8 $ $#$ (8 "--//$^^G44    EKKKKK$]]__    EKKKKK 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   /EC>
BEE!Ec                  K   t          | j        pd          }t          |          }t          | j                  5  |                                 2 3 d{V }|                    |          }|                    |          D ]}|W V  :6 |                                }|                    |          D ]}|W V  |                                D ]}|W V  	 ddd           dS # 1 swxY w Y   dS r  )r   r2   r   r   r  r  rM   r6  r  s          r=   
aiter_textzResponse.aiter_text  s}      t}'?@@@444T]333 		 		&*&6&6&8&8              l&~~l;;$^^L99    EKKKKK  '9 #==??L 55     		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s   C*BBC**C.1C.c                0  K   t                      }t          | j                  5  |                                 2 3 d {V }|                    |          D ]}|W V  %6 |                                D ]}|W V  	 d d d            d S # 1 swxY w Y   d S r  )r   r   r  r  rM   r6  r  s       r=   aiter_lineszResponse.aiter_lines  s     --T]333 	 	"oo//       d#NN400  DJJJJJ 0    




		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BA <BBBc                H  K   | j         rt                      | j        rt                      t	          | j        t                    st          d          d| _         d| _        t          |          }t          | j                  5  | j        2 3 d{V }| xj        t          |          z  c_        |                    |          D ]}|W V  B6 	 ddd           n# 1 swxY w Y   |                                D ]}|W V  |                                  d{V  dS )r  z6Attempted to call an async iterator on an sync stream.Tr   r~  r  N)r   r   r  r   rC   r   r   r%  r!  r   r   r  r   rM   r6  acloser  s        r=   r  zResponse.aiter_raw  s      " 	# """> 	!.. $+77 	YWXXX"&%&"444T]333 	  	 *.+              &**c2B.C.CC**$^^,<==    EKKKKK  +6+	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  ]]__ 	 	EKKKKKkkmms   	C!C=C!!C%(C%c                   K   t          | j        t                    st          d          | j        sVd| _        t          | j                  5  | j                                         d{V  ddd           dS # 1 swxY w Y   dS dS )r  z3Attempted to call an async close on an sync stream.Tr  N)rC   r   r   r%  r  r   r  r  r\   s    r=   r  zResponse.aclose  s      
 $+77 	VTUUU~ 	+!DN 777 + +k((*********+ + + + + + + + + + + + + + + + + +	+ 	+s    A<<B B )r3   N)r3   r   rR   )Cr   r   r   r   r   r   r   r$   r   r   r  r&   r   r   r%   r   Callabler   rH   r  r   r   datetime	timedeltar&  r   r  r+  r0  r'   r   r   r  r2   r9  r   rA  r   rC  rE  rG  rI  rL  rN  rV  rb  r   r   ro  rq  r   r  r  r   r   rz  r  r  r  r  r  AsyncIteratorr  r  r  r  r  rX   r@   r=   r  r    s       
 1548%)%)FJ,0:><@MT5' 5' 5'5' -	5'
 15' oc"5' oc"5' j5' ^_dBC5' )5' O$675' Z!895' !,sFOUGSL,I'IJ5' 5' 5' 5'n0CH(= 0$ 0 0 0 0 
+ 
 
 
 X
 ^ x1  d       ^      X ^W     ^ Ac A A A XA Bs B B B XB  S       X      X
 c    X &/#.    X* _c d    _ 8&/#"6 8 8 8 X8n    2 8$ 8 8 8 X8 2D 2 2 2 X2 	3T 	3 	3 	3 X	3 7 7 7 7 X7 7 7 7 7 X7 0$ 0 0 0 X0 
t 
 
 
 X
,#G #G #G #GJ2VZ 2FJ 2 2 2 2    X v{6?3#7S#X9N#NO    X *c * * * X*G# G G G G
fk#vz/: 
 
 
 
)&+c6:o"> )4 ) ) ) )e     26    /#. 		       4 26  /#.		   *FOC0     26  /#.		   8$ $ $ $U     26    /#. 		e	$       4 26  /#.		c	"   *6#7#<     26  /#.		e	$   8+ + + + + +r@   r  c                   n   e Zd ZdZd!dej        e         ddfdZdeddfdZ	de
ddfd	Zd"dededededdf
dZ	 	 	 d#dedej        e         dej        e         dej        e         dej        e         f
dZ	 	 d$dedej        e         dej        e         ddfdZ	 d$dej        e         dej        e         ddfdZd!dej        e         ddfdZdededdfdZdedefdZdeddfdZdefdZdej        e         fdZdefdZdefdZ G d dej        j
                  Z G d d           ZdS )%r   z-
    HTTP Cookies, as a mutable mapping.
    Nr   r3   c                 &   |t          |t                    r\t                      | _        t          |t                    r0|                                D ]\  }}|                     ||           d S d S t          |t                    r3t                      | _        |D ]\  }}|                     ||           d S t          |t                    r9t                      | _        |j        D ]}| j                            |           d S || _        d S rR   )	rC   r   r   jarrE   setrD   r   
set_cookie)rG   r   rO   rP   cookies        r=   rH   zCookies.__init__  s'   ?j$77? {{DH'4(( )")--// ) )JCHHS%(((() )) )&& 		 {{DH% % %
Ue$$$$% %)) 	 {{DH!+ , ,##F++++, , DHHHr@   r]  c                     |                      |          }|                     |j                  }| j                            ||           dS )zO
        Loads any cookies based on the response `Set-Cookie` headers.
        N)_CookieCompatResponse_CookieCompatRequestr  r  ri  )rG   r]  urllib_responseurllib_requests       r=   ri  zCookies.extract_cookies  sK     44X>>2283CDD  .AAAAAr@   r  c                 d    |                      |          }| j                            |           dS )zM
        Sets an appropriate 'Cookie:' HTTP header on the `Request`.
        N)r  r  add_cookie_header)rG   r  r  s      r=   r   zCookies.set_cookie_header  s3     227;;"">22222r@   r   /r  rP   domainpathc                    i ddd|d|ddddd	|d
t          |          d|                    d          d|dt          |          dddddddddddddidd}t          di |}| j                            |           dS )zU
        Set a cookie value by name. May optionally include domain and path.
        versionr   r  rP   portNport_specifiedFr  domain_specifieddomain_initial_dot.r  path_specifiedsecureexpiresdiscardTcommentcomment_urlrestHttpOnlyrfc2109rX   )r   
startswithr   r  r  )rG   r  rP   r  r  rc  r  s          r=   r  zCookies.set  s!   
q
D
 U
 D	

 e
 f
 V
 !&"3"3C"8"8
 D
 d4jj
 e
 t
 t
 t
 4
  Z&!
" u#
& !!&!!F#####r@   rn   c                     d}| j         D ]D}|j        |k    r7||j        |k    r*||j        |k    r|d| }t	          |          |j        }E||S |S )z
        Get a cookie by name. May optionally include domain and path
        in order to specify exactly which cookie to retrieve.
        Nz!Multiple cookies exist with name=)r  r  r  r  r   rP   )rG   r  rn   r  r  rP   r  r_  s           r=   rq   zCookies.get1  s     h 	- 	-F{d"">V]f%<%<|v{d':': ,&P$&P&PG"0"9"99 &=Nr@   c                     | j                                       S fd| j         D             }|D ]-}| j                             |j        |j        |j                   .dS )z
        Delete a cookie by name. May optionally include domain and path
        in order to specify exactly which cookie to delete.
        Nc                 ^    g | ])}|j         k    r|j        k    r|j        k    '|*S rR   )r  r  r  )r:   r  r  r  r  s     r=   r>   z"Cookies.delete.<locals>.<listcomp>W  sT     
 
 
{d""6=F#:#:!4!4	  "5!4!4r@   )r  clearr  r  r  )rG   r  r  r  remover  s    ```  r=   deletezCookies.deleteJ  s     $"28>>&$555
 
 
 
 
 
(
 
 
  	D 	DFHNN6=&+v{CCCC	D 	Dr@   c                     g }||                     |           ||J |                     |            | j        j        |  dS )z
        Delete all cookies. Optionally include a domain and path in
        order to only delete a subset of all the cookies.
        N)r   r  r  )rG   r  r  argss       r=   r  zCookies.clearb  s\     KK%%%KKr@   c                 l    t          |          }|j        D ]}| j                            |           d S rR   )r   r  r  )rG   r   r  s      r=   r   zCookies.updateq  sC    '""k 	( 	(FH''''	( 	(r@   c                 .    |                      ||          S rR   )r  rG   r  rP   s      r=   r   zCookies.__setitem__v  s    xxe$$$r@   c                 R    |                      |          }|t          |          |S rR   )rq   rp   r  s      r=   r   zCookies.__getitem__y  s'    =4.. r@   c                 ,    |                      |          S rR   )r  )rG   r  s     r=   r   zCookies.__delitem__  s    {{4   r@   c                 *    t          | j                  S rR   )r   r  r\   s    r=   r   zCookies.__len__  s    48}}r@   c                 $    d | j         D             S )Nc              3   $   K   | ]}|j         V  d S rR   )r  r:   r  s     r=   	<genexpr>z#Cookies.__iter__.<locals>.<genexpr>  s$      33333333r@   r  r\   s    r=   r   zCookies.__iter__  s    33$(3333r@   c                     | j         D ]} dS dS )NTFr  )rG   rZ   s     r=   __bool__zCookies.__bool__  s     	 	A44ur@   c                 V    d                     d | j        D                       }d| dS )Nrd   c           	      D    g | ]}d |j          d|j         d|j         dS )z<Cookie =z for z />)r  rP   r  r  s     r=   r>   z$Cookies.__repr__.<locals>.<listcomp>  sJ        O6;NNNNFMNNN  r@   z	<Cookies[rt  )r   r  )rG   cookies_reprs     r=   r   zCookies.__repr__  sF    yy "h  
 
 ,<++++r@   c                   D     e Zd ZdZdeddf fdZdededdf fdZ xZS )	Cookies._CookieCompatRequest
        Wraps a `Request` instance up in a compatibility interface suitable
        for use with `CookieJar` operations.
        r  r3   Nc                     t                                          t          |j                  t	          |j                  |j                   || _        d S )N)r   r1   r   )superrH   r   r   r   r1   r   r  )rG   r  r   s     r=   rH   z%Cookies._CookieCompatRequest.__init__  sP    GG$$W_--~    
 #DLLLr@   rO   rP   c                 j    t                                          ||           || j        j        |<   d S rR   )r  add_unredirected_headerr  r1   )rG   rO   rP   r   s      r=   r  z4Cookies._CookieCompatRequest.add_unredirected_header  s2    GG++C777(-DL %%%r@   )	r   r   r   r   r   rH   r   r  __classcell__)r   s   @r=   r  r    s        	 	
	#G 	# 	# 	# 	# 	# 	# 	#	.s 	.3 	.4 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.r@   r  c                   >    e Zd ZdZdefdZdej        j        fdZ	dS )Cookies._CookieCompatResponser  r]  c                     || _         d S rR   )r]  )rG   r]  s     r=   rH   z&Cookies._CookieCompatResponse.__init__  s    $DMMMr@   r3   c                     t           j                                        }| j        j                                        D ]
\  }}|||<   |S rR   )emailr_  Messager]  r1   rm   )rG   inforO   rP   s       r=   r  z"Cookies._CookieCompatResponse.info  sK    =((**D"m3??AA " "
U "S		Kr@   N)
r   r   r   r   r  rH   r  r_  r  r  rX   r@   r=   r  r    sY        	 	
	%X 	% 	% 	% 	%	%-/ 	 	 	 	 	 	r@   r  rR   )r   r  )NNNr   ) r   r   r   r   r   r   r   rH   r  ri  r   r   r   r  rq   r  r  r   r   r   r   r   r   r   r   r   r  r   urllibr  r  r  rX   r@   r=   r   r     sK          <     "B BT B B B B3 3T 3 3 3 3$ $ $C $ $ $t $ $ $ $: )-'+%)  % $	
 oc" 
	   8 (,%)	D DD $D oc"	D
 
D D D D2 QU oc*9?9M	   ( (fok: (d ( ( ( (
% %C %D % % % %     ! ! ! ! ! !    4&/#. 4 4 4 4$    
,# , , , ,. . . . .v~5 . . .$         r@   r   )Cr  email.messager  r   re  r   urllib.requestr  collections.abcr   http.cookiejarr   r   r   r   r   r	   r
   	_decodersr   r   r   r   r   r   r   r   _exceptionsr   r   r   r   r   r   r   
_multipartr   _status_codesr   _typesr   r   r   r   r    r!   r"   r#   r$   r%   r&   _urlsr'   _utilsr(   r)   r*   r+   r,   r-   r.   MutableMappingr   r0   r   r  r   rX   r@   r=   <module>r     sI                 # # # # # # , , , , , , , , S S S S S S S S S S S S	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                  A @ @ @ @ @                                                            x: x: x: x: x:f#CH- x: x: x:vG) G) G) G) G) G) G) G)Tq+ q+ q+ q+ q+ q+ q+ q+hH H H H Hf#CH- H H H H Hr@   