
    +DCf?                       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
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/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=  G d dej|                  e?e?f         Z@ G d d      ZA G d d      ZB G d dej|                  e?e?f         ZCy)    )annotationsN)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)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dZedd       Zej                  dd       Zedd       ZddZ	ddZ
dd	Zdd
Zd d!dZd"d#dZd d$dZd%dZd&dZd'dZd(dZd)dZd*dZd+dZd,dZddZy)-Headersz9
    HTTP headers, as a case-insensitive multi-dict.
    Nc           
        |g | _         || _        y t        |t              r"t        |j                         | _         || _        y t        |t              rU|j                         D cg c],  \  }}t        |d|      t        |d|      t        ||      f. c}}| _         || _        y |D cg c],  \  }}t        |d|      t        |d|      t        ||      f. c}}| _         || _        y c c}}w c c}}w )NF)lowerencodingT)	_list
isinstancer0   listr   itemsr*   r+   	_encoding)selfheadersr3   kvs        M/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/httpx/_models.py__init__zHeaders.__init__>   s    
 ?DJ, "+ )gmm,DJ( "' ) $MMO Aq	 )%(K($J*1h7DJ$ " $ Aq	 )%(K($J*1h7DJ "%s   '1C0.1C6c                   | j                   XdD ]L  }| j                  D ](  \  }}	 |j                  |       |j                  |       * || _          | j                   S  d| _         | j                   S # t        $ r Y  nw xY w)zn
        Header encoding is mandated as ascii, but we allow fallbacks to utf-8
        or iso-8859-1.
        )asciiutf-8z
iso-8859-1)r8   rawdecodeUnicodeDecodeError)r9   r3   keyvalues       r=   r3   zHeaders.encoding\   s     >>!. ."&(( 
JC

8,X.
 &.DN
 ~~!. ".~~ . s   "A11	A>=A>c                    || _         y N)r8   r9   rF   s     r=   r3   zHeaders.encodingu   s	        c                X    | j                   D cg c]
  \  }}}||f c}}}S c c}}}w )zH
        Returns a list of the raw header items, as byte pairs.
        )r4   )r9   raw_key_rF   s       r=   rB   zHeaders.rawy   s+    
 ;?**EE%6Wa% EEEs   %c                    | j                   D ci c]"  \  }}}|j                  | j                        d $ c}}}j                         S c c}}}w rH   )r4   rC   r3   keysr9   rM   rE   rF   s       r=   rO   zHeaders.keys   s>    EIZZPPMAsE

4==)4/PUUWWPs   'Ac                    i }| j                   D ]V  \  }}}|j                  | j                        }|j                  | j                        }||v r||xx   d| z  cc<   R|||<   X |j                         S )N, )r4   rC   r3   valuesr9   values_dictrM   rE   rF   str_key	str_values          r=   rS   zHeaders.values   s~    &(!ZZ 	1MAsEjj/GT]]3I+%G$"YK(88$'0G$	1 !!##rJ   c                    i }| j                   D ]V  \  }}}|j                  | j                        }|j                  | j                        }||v r||xx   d| z  cc<   R|||<   X |j                         S )z
        Return `(key, value)` items of headers. Concatenate headers
        into a single comma separated value when a key occurs multiple times.
        rR   )r4   rC   r3   r7   rT   s          r=   r7   zHeaders.items   s    
 ')!ZZ 	1MAsEjj/GT]]3I+%G$"YK(88$'0G$	1   ""rJ   c           	         | j                   D cg c]<  \  }}}|j                  | j                        |j                  | j                        f> c}}}S c c}}}w )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.
        )r4   rC   r3   rP   s       r=   multi_itemszHeaders.multi_items   sR     "&
 
3 ZZ&T]](CD
 	
 
s   AAc                0    	 | |   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)r9   rE   defaults      r=   getzHeaders.get   s%    
	9 	N	s    c                   |j                         j                  | j                        }| j                  D cg c]4  \  }}}|j                         |k(  r|j	                  | j                        6 }}}}|s|S g }|D ]>  }	|j                  |	j                  d      D 
cg c]  }
|
j                          c}
       @ |S c c}}}w c c}
w )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.
        ,)r2   encoder3   r4   rC   extendsplitstrip)r9   rE   split_commasget_header_keyrM   item_key
item_valuerS   split_valuesrF   items              r=   get_listzHeaders.get_list   s     ++DMM: ,0::
 
'8Z~~>1 dmm,
 
 M 	ME%++c:J K$ KL	M
 !Ls   9C C	
c                    t        |      }|j                         D ]  }|| v s| j                  |        | j                  j	                  |j                         y rH   )r0   rO   popr4   rb   )r9   r:   rE   s      r=   updatezHeaders.update   sK    '"<<> 	Cd{	 	

'--(rJ   c                0    t        | | j                        S )Nr3   )r0   r3   r9   s    r=   copyzHeaders.copy   s    tdmm44rJ   c                   |j                         j                  | j                        }| j                  D cg c]&  \  }}}||k(  r|j	                  | j                        ( }}}}|rdj                  |      S t        |      c c}}}w )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
        rR   )r2   ra   r3   r4   rC   joinr\   )r9   rE   normalized_keyrM   
header_keyheader_valuer7   s          r=   __getitem__zHeaders.__getitem__   s     ++DMM: 04zz
 
+:|^+ .
 
 99U##sm
s   +Bc                   |j                  | j                  xs d      }|j                  | j                  xs d      }|j                         }t        | j                        D cg c]  \  }\  }}}||k(  r| }	}}}t        |	dd       D ]  }| j                  |=  |	r|	d   }|||f| j                  |<   y| j                  j                  |||f       yc c}}}w )zs
        Set the header `key` to `value`, removing any duplicate entries.
        Retains insertion order.
        rA   r   Nr   )ra   r8   r2   	enumerater4   reversedappend)
r9   rE   rF   set_key	set_value
lookup_keyidxrM   rg   found_indexess
             r=   __setitem__zHeaders.__setitem__   s    
 **T^^6w7LL!:7;	]]_
 *34::)>
 
%%a1:% 
 
 M!"-. 	 C

3	  "C&
I>DJJsOJJw
I>?
s   (Cc                8   |j                         j                  | j                        }t        | j                        D cg c]  \  }\  }}}|j                         |k(  r|  }}}}|st        |      t        |      D ]  }| j                  |=  yc c}}}w )z*
        Remove the header `key`.
        N)r2   ra   r3   rz   r4   r\   r{   )r9   rE   del_keyr   rM   rg   pop_indexess          r=   __delitem__zHeaders.__delitem__   s     ))+$$T]]3 *34::)>
 
%%a1~~7* 
 
 3-K( 	 C

3	 
s   #Bc                    |j                         j                  | j                        }|| j                  D cg c]  \  }}}|
 c}}v S c c}}w rH   )r2   ra   r3   r4   )r9   rE   rv   rM   s       r=   __contains__zHeaders.__contains__  s?    YY[''6
4::>iaac>>>>s   Ac                4    t        | j                               S rH   )iterrO   rq   s    r=   __iter__zHeaders.__iter__  s    DIIK  rJ   c                ,    t        | j                        S rH   )lenr4   rq   s    r=   __len__zHeaders.__len__  s    4::rJ   c                   	 t        |      }| j                  D cg c]
  \  }}}||f }}}}|j                  D cg c]
  \  }}}||f }}}}t        |      t        |      k(  S # t        $ r Y yw xY wc c}}}w c c}}}w )NF)r0   
ValueErrorr4   sorted)r9   otherother_headersrM   rE   rF   	self_list
other_lists           r=   __eq__zHeaders.__eq__  s    	#ENM 8<zzBBmaec5\B	B8E8K8KLL}q#usElL
Li F:$666  		 CLs   A* A9 B *	A65A6c                "   | j                   j                  }d}| j                  dk7  rd| j                  }t        t	        | j                                     }t        |      }t        |      t        |      k(  }|r
| d|| dS | d|| dS )N r@   z, encoding=())	__class____name__r3   r6   r,   rZ   dictr   )r9   
class_nameencoding_stras_listas_dictno_duplicate_keyss         r=   __repr__zHeaders.__repr__$  s    ^^,,
==G#((9:L243C3C3EFGw-LCL8 \7+l^1==Qwk,q99rJ   NN)r:   HeaderTypes | Noner3   
str | NonereturnNoner   strrF   r   r   r   )r   zlist[tuple[bytes, bytes]])r   ztyping.KeysView[str])r   ztyping.ValuesView[str])r   ztyping.ItemsView[str, str])r   zlist[tuple[str, str]]rH   )rE   r   r]   
typing.Anyr   r   )F)rE   r   re   boolr   z	list[str])r:   r   r   r   )r   r0   )rE   r   r   r   rE   r   rF   r   r   r   )rE   r   r   r   )rE   r   r   r   )r   ztyping.Iterator[typing.Any]r   int)r   r   r   r   )r   
__module____qualname____doc__r>   propertyr3   setterrB   rO   rS   r7   rZ   r^   rk   rn   rr   rx   r   r   r   r   r   r   r    rJ   r=   r0   r0   9   s     '+#"#" " 
	"<  0 __  F FX	$#	
,)5(@0 $?!7:rJ   r0   c            
          e Zd Zdddddddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZedd       ZddZddZddZ	dd	Z
dd
Zy)RequestN)	paramsr:   cookiescontentdatafilesjsonstream
extensionsc       	           t        |t              r|j                  d      j                         n|j                         | _        t        |      | _        |!| j                  j                  |      | _        t        |      | _	        |i n|| _
        |rt        |      j                  |        |
| j                  j                  d      }t        ||||	t        |r%|j!                  | j                  j"                        nd             \  }}
| j%                  |       |
| _        t        |
t(              r| j+                          y y |
| _        y )Nr@   )r   zcontent-type)content_type)r   r   r   r   boundary)r5   bytesrC   uppermethodr(   urlcopy_merge_paramsr0   r:   r   Cookiesset_cookie_headerr^   r
   r   ra   r3   _preparer   r   read)r9   r   r   r   r:   r   r   r   r   r   r   r   r   s                r=   r>   zRequest.__init__5  s"   " &%( MM'"((* 	
 s8xx111@DHw' * 2"
G..t4>'+||'7'7'GL,A# ".!4!4T\\5J5J!K
OGV MM'" DK&*-		 ." !DKrJ   c                   |j                         D ]C  \  }}|j                         dk(  rd| j                  v r(| j                  j                  ||       E g }d| j                  v }d| j                  v xs d| j                  v }|s=| j                  j
                  r'|j                  d| j                  j                  f       |s| j                  dv r|j                  d       t        || j                  j                  z         | _        y )Ntransfer-encodingzContent-LengthHostzTransfer-Encodings   Host)POSTPUTPATCH)s   Content-Length   0)r7   r2   r:   
setdefaultr   hostr|   netlocr   r0   rB   )r9   default_headersrE   rF   auto_headershas_hosthas_content_lengths          r=   r   zRequest._prepareu  s    )//1 	0JCyy{116F$,,6VLL##C/		0 35T\\),S0Ct||0S 	 DHHMM$((// :;!dkk5M&M 9:|dll.>.>>?rJ   c                F    t        | d      s
t               | j                  S N_content)hasattrr   r   rq   s    r=   r   zRequest.content  s    tZ( ""}}rJ   c                &   t        | d      szt        | j                  t        j                        sJ dj                  | j                        | _        t        | j                  t              st        | j                        | _        | j                  S )6
        Read and return the request content.
        r   rJ   )r   r5   r   typingIterablert   r   r   rq   s    r=   r   zRequest.read  sd     tZ(dkk6??;;;HHT[[1DMdkk:6 )7}}rJ   c                j  K   t        | d      sMt        | j                  t        j                        sJ dj                  | j                  2 cg c3 d{   }|| j                  S 7 6 nc c}w c}      | _        t        | j                  t              r<t        | j                        | _        Ww)r   r   rJ   N)r   r5   r   r   AsyncIterablert   r   r   r9   parts     r=   areadzRequest.aread  s      tZ(dkk6+?+?@@@HHT[[%I%ITd }} &J%I%IJDMdkk:6 )7sB   AB3A,A*
A(A*
A,B3(A*
*A,+,B3B3c                    | j                   j                  }t        | j                        }d| d| j                  d|dS )N<r   rR   z)>)r   r   r   r   r   )r9   r   r   s      r=   r   zRequest.__repr__  s=    ^^,,
$((m:,abr::rJ   c                r    | j                   j                         D ci c]  \  }}|dvr|| c}}S c c}}w )N)r   r   __dict__r7   r9   namerF   s      r=   __getstate__zRequest.__getstate__  sB      $}}224
e33 %K
 	
 
   3c                z    |j                         D ]  \  }}t        | ||        i | _        t               | _        y rH   )r7   setattrr   r	   r   r9   stater   rF   s       r=   __setstate__zRequest.__setstate__  s8     ;;= 	'KD%D$&	'&(rJ   )r   zstr | bytesr   z	URL | strr   zQueryParamTypes | Noner:   r   r   CookieTypes | Noner   zRequestContent | Noner   zRequestData | Noner   zRequestFiles | Noner   ztyping.Any | Noner   'SyncByteStream | AsyncByteStream | Noner   zRequestExtensions | Noner   r   r   zdict[str, str]r   r   r   r   r   r   dict[str, typing.Any]r   r   r   r   )r   r   r   r>   r   r   r   r   r   r   r   r   r   rJ   r=   r   r   4  s     *.&*&*)-#'%)"&:>/3>!>! >!
 '>! $>! $>! '>! !>! #>!  >! 8>! ->! 
>!@@*  
;

)rJ   r   c                     e Zd Zddddddddddd
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d.dZd/dZed0d       Zej                  d1d       Zed2d       Zej                  d3d	       Zed4d
       Z	ed4d       Z
ed5d       Zed6d       Zed4d       Zed7d       Zej                  d8d       Zed7d       Zd9dZed:d       Zed:d       Zed:d       Zed:d       Zed:d       Zed:d       Zed:d       Zd;dZd<dZed=d       Zed>d       Zed?d       Zd4dZd@d ZdAd!Zd6d"Z dBdCd#Z!dBdDd$Z"dEd%Z#dBdCd&Z$dFd'Z%d6d(Z&	 dB	 	 	 dGd)Z'	 dB	 	 	 dHd*Z(dId+Z)	 dB	 	 	 dGd,Z*dFd-Z+y)JResponseNrA   )
r:   r   texthtmlr   r   requestr   historydefault_encodingc       
        x   || _         t        |      | _        || _        d | _        |	i n|	| _        |
g n
t        |
      | _        d| _        d| _	        || _
        |Qt        ||||      \  }}| j                  |       || _        t        |t              r| j!                          d| _        y || _        d| _        y )NFr   )status_coder0   r:   _requestnext_requestr   r6   r  	is_closedis_stream_consumedr  r   r   r   r5   r   r   _num_bytes_downloaded)r9   r  r:   r   r   r   r   r   r  r   r  r  s               r=   r>   zResponse.__init__  s     'w'(/ -14>4FbJ$_r$w-"' 0>-gtT4HOGVMM'" DK&*-		 &'" !DK%&"rJ   c                    |j                         D ]C  \  }}|j                         dk(  rd| j                  v r(| j                  j                  ||       E y )Nr   zcontent-length)r7   r2   r:   r   )r9   r   rE   rF   s       r=   r   zResponse._prepare  sP    )//1 	0JCyy{116F$,,6VLL##C/		0rJ   c                H    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  rq   s    r=   elapsedzResponse.elapsed  s,     tZ(+  }}rJ   c                    || _         y rH   )r  )r9   r  s     r=   r  zResponse.elapsed  s	    rJ   c                H    | j                   t        d      | j                   S )zR
        Returns the request instance associated to the current response.
        z7The request instance has not been set on this response.)r  r  rq   s    r=   r  zResponse.request  s*    
 == I  }}rJ   c                    || _         y rH   )r  rI   s     r=   r  zResponse.request  s	    rJ   c                f    	 | j                   d   }|j                  dd      S # t        $ r Y yw xY w)Nhttp_versionr@   ignoreerrorszHTTP/1.1)r   rC   r\   )r9   r  s     r=   r  zResponse.http_version  sB    	A"&//."AL  &&wx&@@  		s   $ 	00c                    	 | j                   d   }|j                  dd      S # t        $ r" t        j                  | j
                        cY S w xY w)Nreason_phraser@   r  r  )r   rC   r\   r   get_reason_phraser  )r9   r  s     r=   r  zResponse.reason_phrase'  sV    	B#'???#CM !'''AA  	=**4+;+;<<	=s   $ (AAc                .    | j                   j                  S )zA
        Returns the URL for which the request was made.
        )r  r   rq   s    r=   r   zResponse.url0  s    
 ||rJ   c                F    t        | d      s
t               | j                  S r   )r   r   r   rq   s    r=   r   zResponse.content7  s    tZ(!##}}rJ   c                &   t        | d      sz| j                  }|sd| _        | j                  S t        | j                  xs d      }dj                  |j                  | j                        |j                         g      | _        | j                  S )N_textr   rA   rp   )r   r   r  r   r3   rt   rC   flush)r9   r   decoders      r=   r   zResponse.text=  sr    tW%llG
 zz &t}}/GHWWgnnT\\&BGMMO%TU
zzrJ   c                   t        | d      sr| j                  }|t        |      sNt        | j                  t
              r| j                  }n't        | d      r| j	                  | j                        }|xs 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.
        r8   r   rA   )r   charset_encodingr)   r5   r  r   r   r8   )r9   r3   s     r=   r3   zResponse.encodingH  sv     t[),,H'8'Bd33S9#44HT:.#44T]]CH%0DN~~rJ   c                @    t        | d      rt        d      || _        y)z
        Set the encoding to use for decoding the byte content into text.

        If the `text` attribute has been accessed, attempting to set the
        encoding will throw a ValueError.
        r  z?Setting encoding after `text` has been accessed is not allowed.N)r   r   r8   rI   s     r=   r3   zResponse.encoding^  s'     4!Q  rJ   c                T    | j                   j                  d      }|yt        |      S )zO
        Return the encoding, as specified by the Content-Type header.
        zContent-TypeN)r:   r^   r-   )r9   r   s     r=   r"  zResponse.charset_encodingl  s,    
 ||''7),77rJ   c                   t        | d      sg }| j                  j                  dd      }|D ]@  }|j                         j	                         }	 t
        |   }|j                   |              B t        |      dk(  r|d   | _	        | j                  S t        |      dkD  rt        |      | _	        | j                  S t               | _	        | j                  S # t        $ r Y w xY w)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)re   r   r   )children)r   r:   rk   rd   r2   r   r|   r\   r   r&  r   r   )r9   decodersrS   rF   decoder_clss        r=   _get_content_decoderzResponse._get_content_decoderw  s    
 tZ(-/H\\**+=D*QF ++-"4U";KOOKM2	 8}! ( }} X" ,h ? }} !0 1}}   s   C	C'&C'c                @    t        j                  | j                        S )zU
        A property which is `True` for 1xx status codes, `False` otherwise.
        )r   is_informationalr  rq   s    r=   r,  zResponse.is_informational  s    
 %%d&6&677rJ   c                @    t        j                  | j                        S )zU
        A property which is `True` for 2xx status codes, `False` otherwise.
        )r   
is_successr  rq   s    r=   r.  zResponse.is_success  s    
  0 011rJ   c                @    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  rq   s    r=   r0  zResponse.is_redirect  s       !1!122rJ   c                @    t        j                  | j                        S )zU
        A property which is `True` for 4xx status codes, `False` otherwise.
        )r   is_client_errorr  rq   s    r=   r2  zResponse.is_client_error      
 $$T%5%566rJ   c                @    t        j                  | j                        S )zU
        A property which is `True` for 5xx status codes, `False` otherwise.
        )r   is_server_errorr  rq   s    r=   r5  zResponse.is_server_error  r3  rJ   c                @    t        j                  | j                        S )z]
        A property which is `True` for 4xx and 5xx status codes, `False` otherwise.
        )r   is_errorr  rq   s    r=   r7  zResponse.is_error  s    
 ~~d..//rJ   c                    | j                   t        j                  t        j                  t        j                  t        j
                  t        j                  fv xr 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_REDIRECTr:   rq   s    r=   has_redirect_locationzResponse.has_redirect_location  sZ      ''(((( + dll*	
rJ   c                   | j                   }|t        d      | j                  r| S | j                  rd}nd}| j                  dz  }ddddd	}|j                  |d
      }|j                  | |      }t        |||       )z>
        Raise the `HTTPStatusError` if one occurred.
        zYCannot 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://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{0.status_code}z{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{0.status_code}d   zInformational responsezRedirect responsezClient errorzServer error)r            zInvalid status code)
error_type)r  response)r  r  r.  r?  r  r^   formatr   )r9   r  messagestatus_classerror_typesrE  s         r=   raise_for_statuszResponse.raise_for_status  s     --?> 
 ??K%%w w 
 ''3.'"	
 !__\3HI
..*.=gwFFrJ   c                B    t        j                  | j                  fi |S rH   )jsonlibloadsr   )r9   kwargss     r=   r   zResponse.json  s    }}T\\4V44rJ   c                    t        | d      s*t               | _        | j                  j                  |        | j                  S )N_cookies)r   r   rQ  extract_cookiesrq   s    r=   r   zResponse.cookies  s1    tZ(#IDMMM))$/}}rJ   c                    | j                   j                  d      }|i S t        |      D ci c]'  }|j                  d      xs |j                  d      |) c}S c c}w )zI
        Returns the parsed header links of the response, if any
        linkrelr   )r:   r^   r.   )r9   headerrT  s      r=   linkszResponse.links  sc    
 !!&)>I +62
 XXe_/$6
 	
 
s   ,Ac                    | j                   S rH   )r
  rq   s    r=   num_bytes_downloadedzResponse.num_bytes_downloaded  s    )))rJ   c                <    d| j                    d| j                   dS )Nz<Response [ ]>)r  r  rq   s    r=   r   zResponse.__repr__  s%    T--.a0B0B/C2FFrJ   c                r    | j                   j                         D ci c]  \  }}|dvr|| c}}S c c}}w )N)r   r   r  r&  r   r   s      r=   r   zResponse.__getstate__  sB      $}}224
eLL %K
 	
 
r   c                    |j                         D ]  \  }}t        | ||        d| _        i | _        t	               | _        y )NT)r7   r   r  r   r	   r   r   s       r=   r   zResponse.__setstate__!  s?     ;;= 	'KD%D$&	'&(rJ   c                z    t        | d      s$dj                  | j                               | _        | j                  S )7
        Read and return the response content.
        r   rJ   )r   rt   
iter_bytesr   rq   s    r=   r   zResponse.read(  s/     tZ(HHT__%67DM}}rJ   c              #  t  K   t        | d      r]|t        | j                        n|}t        dt        | j                        t	        |d            D ]  }| j                  |||z      y| j                         }t        |      }t        | j                        5  | j                         D ]-  }|j                  |      }|j                  |      D ]  }|  / |j                         }|j                  |      D ]  }|  |j                         D ]  }|  	 ddd       y# 1 sw Y   yxY wwz
        A byte-iterator over the decoded response content.
        This allows us to handle gzip, deflate, and brotli encoded responses.
        r   Nr   r   
chunk_sizer  )r   r   r   rangemaxr*  r   r   r  iter_rawrC   r  r9   re  ir   chunker	raw_bytesdecodedchunks           r=   ra  zResponse.iter_bytes0  s"    
 4$/9/AT]]+zJ1c$--0#j!2DE 8mmAJ778 //1G!Z8G 7 	 !% $I%nnY7G!(!8 $#$$ "--/$^^G4  EK $]]_  EK 	  	  	 s   BD8BD,#	D8,D51D8c              #    K   t        | j                  xs d      }t        |      }t        | j                        5  | j                         D ]-  }|j                  |      }|j                  |      D ]  }|  / |j                         }|j                  |      D ]  }|  |j                         D ]  }|  	 ddd       y# 1 sw Y   yxY wwz
        A str-iterator over the decoded response content
        that handles both gzip, deflate, etc but also detects the content's
        string encoding.
        rA   rp   rd  rf  N)r   r3   r   r   r  ra  rC   r  r9   re  r   rl  byte_contenttext_contentro  s          r=   	iter_textzResponse.iter_textG  s      t}}'?@4T]]3 		 $ 1  &~~l;$^^L9  EK   #==?L 5   		 		 		s   =CBC	CCCc              #    K   t               }t        | j                        5  | j                         D ]  }|j	                  |      D ]  }|   |j                         D ]  }|  	 d d d        y # 1 sw Y   y xY wwNrf  )r   r   r  ru  rC   r  r9   r   r   lines       r=   
iter_lineszResponse.iter_linesZ  s|     -T]]3 	( #NN40 DJ   
		 	 	s   !BA	A6-	B6A?;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_        |j                  |      D ]  }|  < 	 ddd       |j                         D ]  }|  | j                          y# 1 sw Y   3xY ww)@
        A byte-iterator over the raw response content.
        z5Attempted to call a sync iterator on an async stream.Tr   rd  rf  N)r	  r   r  r   r5   r   r'   r  r
  r   r   r  r   rC   r  closer9   re  rl  raw_stream_bytesro  s        r=   ri  zResponse.iter_rawc  s      "" "">>. $++~6VWW"&%&"4T]]3 	 $(KK   **c2B.CC*$^^,<=  EK  	  ]]_ 	EK	 	

	  	 s   BDA
D2DD
Dc                    t        | j                  t              st        d      | j                  sAd| _        t        | j                        5  | j                  j                          ddd       yy# 1 sw Y   yxY w)
        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.Trf  N)r5   r   r'   r  r  r   r  r}  rq   s    r=   r}  zResponse.close}  sg    
 $++~6TUU~~!DN 7 $!!#$ $ $ $s   A44A=c                   K   t        | d      s+dj                  | j                         2 cg c3 d{   }|| j                  S 7 6 nc c}w c}      | _        "w)r`  r   rJ   N)r   rt   aiter_bytesr   r   s     r=   r   zResponse.aread  sM      tZ(HHT=M=M=O%P%PTd}} &Q%P%PQDMs5   *AA
A
AA
A
AA
A
	Ac                 K   t        | d      r^|t        | j                        n|}t        dt        | j                        t	        |d            D ]  }| j                  |||z      y| j                         }t        |      }t        | j                        5  | j                         2 3 d{   }|j                  |      }|j                  |      D ]  }| 	 67 16 |j                         }|j                  |      D ]  }| 	 |j                         D ]  }| 	 	 ddd       y# 1 sw Y   yxY wwrc  )r   r   r   rg  rh  r*  r   r   r  	aiter_rawrC   r  rj  s           r=   r  zResponse.aiter_bytes  s,     4$/9/AT]]+zJ1c$--0#j!2DE 8mmAJ778 //1G!Z8G 7 	 '+~~'7 $ $)%nnY7G!(!8 $#$$'7 "--/$^^G4  EK $]]_  EK 	  	  	 sC   BED80C(4C&5C(8.D8&C((AD8/	E8E=Ec                 K   t        | j                  xs d      }t        |      }t        | j                        5  | j                         2 3 d{   }|j                  |      }|j                  |      D ]  }| 	 67 16 |j                         }|j                  |      D ]  }| 	 |j                         D ]  }| 	 	 ddd       y# 1 sw Y   yxY wwrq  )r   r3   r   r   r  r  rC   r  rr  s          r=   
aiter_textzResponse.aiter_text  s      t}}'?@4T]]3 		&*&6&6&8    l&~~l;$^^L9  EK  &8 #==?L 5   		 		 		sA   =C$CBBB.CBAC	C$C!C$c                 K   t               }t        | j                        5  | j                         2 3 d {   }|j	                  |      D ]  }| 	 %7  6 |j                         D ]  }| 	 	 d d d        y # 1 sw Y   y xY wwrw  )r   r   r  r  rC   r  rx  s       r=   aiter_lineszResponse.aiter_lines  s     -T]]3 	"oo/  d#NN40 DJ/   
		 	 	s<   !BB AAAB AB 7	B B	Bc               F  K   | j                   r
t               | j                  r
t               t	        | j
                  t              st        d      d| _         d| _        t        |      }t        | j                        5  | j
                  2 3 d{   }| xj                  t        |      z  c_        |j                  |      D ]  }| 	 C7 >6 	 ddd       n# 1 sw Y   nxY w|j                         D ]  }| 	 | j                          d{  7   yw)r|  z6Attempted to call an async iterator on an sync stream.Tr   rd  rf  N)r	  r   r  r   r5   r   r   r  r
  r   r   r  r   rC   r  acloser~  s        r=   r  zResponse.aiter_raw  s      "" "">>. $++7WXX"&%&"4T]]3 	 *.++    &**c2B.CC*$^^,<=  EK  +	  	  	  ]]_ 	EK	 kkmsN   BD!C!CCC;C!CC!	D!!C*&4D!DD!c                  K   t        | j                  t              st        d      | j                  sId| _        t        | j                        5  | j                  j                          d{    ddd       yy7 # 1 sw Y   yxY ww)r  z3Attempted to call an async close on an sync stream.Trf  N)r5   r   r   r  r  r   r  r  rq   s    r=   r  zResponse.aclose  sv     
 $++7TUU~~!DN 7 +kk((***+ +  ++ +s0   ABB /A>0B 4
B>B  B	B)r  r   r:   r   r   zResponseContent | Noner   r   r   r   r   r   r   r   r  zRequest | Noner   zResponseExtensions | Noner  zlist[Response] | Noner  z#str | typing.Callable[[bytes], str]r   r   r   )r   datetime.timedelta)r  r  r   r   )r   r   )rF   r   r   r   r   )r   r(   r   )r   r   r   )r   r   r   r   )r   r   )rO  r   r   r   )r   r   )r   z dict[str | None, dict[str, str]]r   r   r   rH   )re  
int | Noner   ztyping.Iterator[bytes])re  r  r   typing.Iterator[str]r   r  )r   r   )re  r  r   ztyping.AsyncIterator[bytes])re  r  r   typing.AsyncIterator[str])r   r  ),r   r   r   r>   r   r   r  r   r  r  r  r   r   r   r3   r"  r*  r,  r.  r0  r2  r5  r7  r?  rK  r   r   rW  rY  r   r   r   r   ra  ru  rz  ri  r}  r   r  r  r  r  r  r   rJ   r=   r   r     s   
 '+*.:>"&04)-@G5'5' $	5'
 (5' 5' 5' 5' 85'  5' .5' '5' >5' 
5'n0 
 
 ^^      ^^  A A B B      
    * __  8 82 8 8 2 2 	3 	3 7 7 7 7 0 0 
 
,#GJ5   
 
 * *G
) .&4$ (, $ 	$ 4 (,$	"* (,$	$8+rJ   r   c                     e Zd ZdZdddZddZddZdddZ	 	 	 d	 	 	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 ddZ	dd d	Z
ddd
Zd!dZd"dZd#dZd$dZd%dZd&dZd'dZ G d dej(                  j*                        Z G d d      Zy)(r   z-
    HTTP Cookies, as a mutable mapping.
    Nc                   |t        |t              rKt               | _        t        |t              r+|j	                         D ]  \  }}| j                  ||        y y t        |t              r,t               | _        |D ]  \  }}| j                  ||        y t        |t              r<t               | _        |j                  D ]  }| j                  j                  |        y || _        y rH   )	r5   r   r   jarr7   setr6   r   
set_cookie)r9   r   rE   rF   cookies        r=   r>   zCookies.__init__  s    ?j$7 {DH'4(")--/ )JCHHS%() ) & {DH% %
Ue$%) {DH!++ ,##F+, DHrJ   c                    | j                  |      }| j                  |j                        }| j                  j	                  ||       y)zO
        Loads any cookies based on the response `Set-Cookie` headers.
        N)_CookieCompatResponse_CookieCompatRequestr  r  rR  )r9   rF  urllib_responseurllib_requests       r=   rR  zCookies.extract_cookies	  s>     44X>2283C3CD  .ArJ   c                \    | j                  |      }| j                  j                  |       y)zM
        Sets an appropriate 'Cookie:' HTTP header on the `Request`.
        N)r  r  add_cookie_header)r9   r  r  s      r=   r   zCookies.set_cookie_header  s&     227;"">2rJ   c                    i ddd|d|ddddd	|d
t        |      d|j                  d      d|dt        |      dddddddddddddidd}t        di |}| j                  j	                  |       y)zU
        Set a cookie value by name. May optionally include domain and path.
        versionr   r   rF   portNport_specifiedFdomaindomain_specifieddomain_initial_dot.pathpath_specifiedsecureexpiresdiscardTcommentcomment_urlrestHttpOnlyrfc2109r   )r   
startswithr   r  r  )r9   r   rF   r  r  rO  r  s          r=   r  zCookies.set  s
   
q
D
 U
 D	

 e
 f
 V
 !&"3"3C"8
 D
 d4j
 e
 t
 t
 t
 4
  Z&!
" u#
& !&!F#rJ   c                    d}| j                   D ]T  }|j                  |k(  s||j                  |k(  s%||j                  |k(  s7|d| }t	        |      |j
                  }V ||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   rF   )r9   r   r]   r  r  rF   r  rH  s           r=   r^   zCookies.get3  s     hh 	-F{{d">V]]f%<|v{{d': ,(I$&PG"0"99 &	- =NrJ   c                h   ||| j                   j                  |||      S | j                   D cg c]5  }|j                  |k(  r$||j                  |k(  r||j                  |k(  r|7 }}|D ]=  }| j                   j                  |j                  |j                  |j                         ? yc c}w )z
        Delete a cookie by name. May optionally include domain and path
        in order to specify exactly which cookie to delete.
        N)r  clearr   r  r  )r9   r   r  r  r  removes         r=   deletezCookies.deleteL  s     $"288>>&$55 ((
{{d"6==F#:!4	 
 
  	DFHHNN6==&++v{{C	D
s   :B/c                    g }||j                  |       ||J |j                  |        | j                  j                  |  y)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  )r9   r  r  argss       r=   r  zCookies.cleard  sK    
 KK%%%KKrJ   c                r    t        |      }|j                  D ]  }| j                  j                  |        y rH   )r   r  r  )r9   r   r  s      r=   rn   zCookies.updateq  s1    '"kk 	(FHH'	(rJ   c                &    | j                  ||      S rH   )r  r   s      r=   r   zCookies.__setitem__v  s    xxe$$rJ   c                B    | j                  |      }|t        |      |S rH   )r^   r\   r   s      r=   rx   zCookies.__getitem__y  s#    =4. rJ   c                $    | j                  |      S rH   )r  )r9   r   s     r=   r   zCookies.__delitem__  s    {{4  rJ   c                ,    t        | j                        S rH   )r   r  rq   s    r=   r   zCookies.__len__  s    488}rJ   c                (    d | j                   D        S )Nc              3  4   K   | ]  }|j                     y wrH   )r   ).0r  s     r=   	<genexpr>z#Cookies.__iter__.<locals>.<genexpr>  s     33s   r  rq   s    r=   r   zCookies.__iter__  s    3$((33rJ   c                (    | j                   D ]  } y y)NTFr  )r9   rM   s     r=   __bool__zCookies.__bool__  s     	A	rJ   c                    dj                  | j                  D cg c],  }d|j                   d|j                   d|j                   d. c}      }d| dS c c}w )NrR   z<Cookie =z for z />z	<Cookies[r\  )rt   r  r   rF   r  )r9   r  cookies_reprs      r=   r   zCookies.__repr__  sc    yy #hh 6;;-qeFMM?#N
 <.++s   1Ac                  0     e Zd ZdZd fdZd fdZ xZS )Cookies._CookieCompatRequest
        Wraps a `Request` instance up in a compatibility interface suitable
        for use with `CookieJar` operations.
        c                    t         |   t        |j                        t	        |j
                        |j                         || _        y )N)r   r:   r   )superr>   r   r   r   r:   r   r  )r9   r  r   s     r=   r>   z%Cookies._CookieCompatRequest.__init__  s=    G$W__-~~  
 #DLrJ   c                X    t         |   ||       || j                  j                  |<   y rH   )r  add_unredirected_headerr  r:   )r9   rE   rF   r   s      r=   r  z4Cookies._CookieCompatRequest.add_unredirected_header  s&    G+C7(-DLL  %rJ   r  r   r   r   r   )r   r   r   r   r>   r  __classcell__)r   s   @r=   r  r    s    	
	#	. 	.rJ   r  c                       e Zd ZdZddZddZy)Cookies._CookieCompatResponser  c                    || _         y rH   )rF  )r9   rF  s     r=   r>   z&Cookies._CookieCompatResponse.__init__  s	    $DMrJ   c                    t         j                  j                         }| j                  j                  j                         D ]
  \  }}|||<    |S rH   )emailrH  MessagerF  r:   rZ   )r9   inforE   rF   s       r=   r  z"Cookies._CookieCompatResponse.info  sL    ==((*D"mm33??A "
U "S		"
 KrJ   NrF  r   r   r   )r   zemail.message.Message)r   r   r   r   r>   r  r   rJ   r=   r  r    s    	
	%	rJ   r  rH   )r   r   r   r   r  r  )r   /)
r   r   rF   r   r  r   r  r   r   r   )NNN)
r   r   r]   r   r  r   r  r   r   r   r   )r   r   r  r   r  r   r   r   )r  r   r  r   r   r   )r   r   rF   r   r   r   )r   r   r   r   )r   r   r   r   r   r  r  r   )r   r   r   r   r>   rR  r   r  r^   r  r  rn   r   rx   r   r   r   r  r   urllibr  r   r  r  r   rJ   r=   r   r     s    "B3$: #!  	
  
8 "	DD D 	D
 
D0(
%!4
,.v~~55 .$ rJ   r   )D
__future__r   datetimeemail.messager  r   rM  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.   MutableMappingr   r0   r   r   r   r   rJ   r=   <module>r     s    "      # , S S	 	 	   A       x:f##CH- x:vH) H)Vq+ q+hFf##CH- FrJ   