
    Yj                    8   d dl mZ d dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ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 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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z;m<Z< g dZ=ddhZ> e
j~                  d      Z@d dZAd!d"dZBd!d#dZCd$dZDd%dZE	 	 	 	 d&dZF G d de
j                  eHeHf         ZI G d d      ZJ G d d      ZK G d de
j                  eHeHf         ZLy)'    )annotationsN)AsyncGeneratorMapping)Cookie	CookieJar   )
ByteStreamUnattachedStreamencode_requestencode_response)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)to_bytes_or_strto_str)CookiesHeadersRequestResponseauthorizationzproxy-authorization_Tc                N    	 t        j                  |        y# t        $ r Y yw xY w)z7
    Return `True` if `encoding` is a known codec.
    FT)codecslookupLookupErrorencodings    M/var/www/html/vmm-quimica/venv/lib/python3.12/site-packages/httpx2/_models.py_is_known_encodingr8   :   s,    h   s    	$$c                P    t        | t              r| S | j                  |xs d      S )zE
    Coerce str/bytes into a strictly byte-wise HTTP header key.
    ascii)
isinstancebytesencode)keyr6   s     r7   _normalize_header_keyr?   E   s&     S%(3Mcjj9LW.MM    c                    t        | t              r| S t        | t              st        dt	        |              | j                  |xs d      S )zG
    Coerce str/bytes into a strictly byte-wise HTTP header value.
    z'Header value must be str or bytes, not r:   )r;   r<   str	TypeErrortyper=   )valuer6   s     r7   _normalize_header_valuerF   L   sH     %eS!A$u+OPP<<+G,,r@   c                l    t         j                  j                         }| |d<   |j                  d       S )Ncontent-type)failobj)emailmessageMessageget_content_charset)content_typemsgs     r7   _parse_content_type_charsetrP   W   s4     --


!C&C""4"00r@   c                   g }d}| j                  |      } | s|S t        j                  d|       D ]  }	 |j                  dd      \  }}d|j                  d      i}|j                  d      D ]:  }	 |j                  d      \  }} | j                  |      ||j                  |      <   < |j	                  |        |S # t        $ r |d}}Y w xY w# t        $ r Y  4w xY w)	a7  
    Returns a list of parsed link headers, for more info see:
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
    The generic syntax of those is:
    Link: < uri-reference >; param1=value1; param2="value2"
    So for instance:
    Link; '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;'
    would return
        [
            {"url": "http:/.../front.jpeg", "type": "image/jpeg"},
            {"url": "http://.../back.jpeg"},
        ]
    :param value: HTTP Link entity-header field
    :return: list of parsed link headers
    z '"z, *<;r    urlz<> '"=)stripresplit
ValueErrorappend)	rE   linksreplace_charsvalrT   paramslinkparamr>   s	            r7   _parse_header_linksra   _   s      #%EMKK&Exx& 	"))C+KC syy*+\\#& 	HE"[[-
U .3[[-GD=)*	H 	T L  	"rC	"  s#   B?1C?CC	CCc              #     K   | D ]7  \  }}t        |j                               t        v rt        d|      }||f 9 y w)Nz[secure])match_type_of)r*   lowerSENSITIVE_HEADERSr)   )itemskvs      r7   _obfuscate_sensitive_headersri      sD       1!'') 11
!<Ad
s   >A c                  \   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ej                  d%d       Zej                  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d0dZd1dZd2dZd3dZd4dZd5dZddZy)6r,   z9
    HTTP headers, as a case-insensitive multi-dict.
    Nc                   g | _         t        |t              r"t        |j                         | _         || _
        y t        |t              rd|j                         D ]I  \  }}t        ||      }t        ||      }| j                   j                  ||j                         |f       K || _
        y |N|D ]I  \  }}t        ||      }t        ||      }| j                   j                  ||j                         |f       K || _
        y N)_listr;   r,   listr   rf   r?   rF   rZ   rd   	_encoding)selfheadersr6   rg   rh   	bytes_keybytes_values          r7   __init__zHeaders.__init__   s    
 8:
gw'gmm,DJ " ) O11!X>	5aB

!!9ioo.?"MNO "   O11!X>	5aB

!!9ioo.?"MNO
 "r@   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.
        )r:   utf-8z
iso-8859-1)ro   rawdecodeUnicodeDecodeError)rp   r6   r>   rE   s       r7   r6   zHeaders.encoding   s     >>!. ."&(( 
JC

8,X.
 &.DN
 ~~!. ".~~ . s   "A11	A>=A>c                    || _         y rl   )ro   rp   rE   s     r7   r6   zHeaders.encoding   s	    r@   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.
        )rm   )rp   raw_key_rE   s       r7   rw   zHeaders.raw   s+    
 ;?**EE%6Wa% EEEs   %c                    | j                   D ci c]"  \  }}}|j                  | j                        d $ c}}}j                         S c c}}}w rl   )rm   rx   r6   keys)rp   r~   r>   _values       r7   r   zHeaders.keys   s>    FJjjQQNAsF

4==)4/QVVXXQs   'Ac                    i }| j                   D ]V  \  }}}|j                  | j                        }|j                  | j                        }||v r||xx   d| z  cc<   R|||<   X |j                         S )N, )rm   rx   r6   valuesrp   values_dictr~   r>   rE   str_key	str_values          r7   r   zHeaders.values   s~    &(!ZZ 	1MAsEjj/GT]]3I+%G$"YK(88$'0G$	1 !!##r@   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.
        r   )rm   rx   r6   rf   r   s          r7   rf   zHeaders.items   s    
 ')!ZZ 	1MAsEjj/GT]]3I+%G$"YK(88$'0G$	1   ""r@   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.
        )rm   rx   r6   )rp   r~   r>   rE   s       r7   multi_itemszHeaders.multi_items   sJ     _c^h^hii]QPSUZDMM*ELL,GHiiis   AAc                    y rl    )rp   r>   s     r7   getzHeaders.get   s    .1r@   c                     y rl   r   rp   r>   defaults      r7   r   zHeaders.get   s    69r@   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.
        )KeyErrorr   s      r7   r   z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.
        ,)rd   r=   r6   rm   rx   extendrX   rV   )rp   r>   split_commasget_header_keyr~   item_key
item_valuer   split_valuesrE   items              r7   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 rl   )r,   r   poprm   r   )rp   rq   r>   s      r7   updatezHeaders.update  sK    '"<<> 	Cd{	 	

'--(r@   c                0    t        | | j                        S )Nr5   )r,   r6   rp   s    r7   copyzHeaders.copy  s    tdmm44r@   c                t    t        |t              st        S | j                         }|j	                  |       |S rl   )r;   r   NotImplementedr   r   rp   othermergeds      r7   __or__zHeaders.__or__!  s.    %)!!er@   c                j    t        |t              st        S t        |      }|j	                  |        |S rl   )r;   r   r   r,   r   r   s      r7   __ror__zHeaders.__ror__(  s,    %)!!dr@   c                (    | j                  |       | S rl   )r   )rp   r   s     r7   __ior__zHeaders.__ior__/  s    Er@   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
        r   )rd   r=   r6   rm   rx   joinr   )rp   r>   normalized_keyr~   
header_keyheader_valuerf   s          r7   __getitem__zHeaders.__getitem__3  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(  s| }	}}}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.
        rv   r   Nr   )r=   ro   rd   	enumeraterm   reversedrZ   )
rp   r>   rE   set_key	set_value
lookup_keyidxr~   r   found_indexess
             r7   __setitem__zHeaders.__setitem__G  s    
 **T^^6w7LL!:7;	]]_
:CDJJ:Ojj!6&6q(AS[_iSijjM!"-. 	 C

3	  "C&
I>DJJsOJJw
I>? ks   (C:Cc                :   |j                         j                  | j                        }t        | j                        D cg c]  \  }\  }}}|j                         |k(  s|! }}}}|st        |      t        |      D ]  }| j                  |=  yc c}}}w )z*
        Remove the header `key`.
        N)rd   r=   r6   r   rm   r   r   )rp   r>   del_keyr   r~   r   pop_indexess          r7   __delitem__zHeaders.__delitem__[  s     ))+$$T]]38A$**8Mmm4s$4Q!QYQ_Q_QaelQlsmm3-K( 	 C

3	  ns   B#Bc                    |j                         j                  | j                        }|| j                  D cg c]  \  }}}|
 c}}v S c c}}w rl   )rd   r=   r6   rm   )rp   r>   r   r~   s       r7   __contains__zHeaders.__contains__i  s?    YY[''6
4::>iaac>>>>s   Ac                4    t        | j                               S rl   )iterr   r   s    r7   __iter__zHeaders.__iter__m  s    DIIK  r@   c                ,    t        | j                        S rl   )lenrm   r   s    r7   __len__zHeaders.__len__p  s    4::r@   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)r,   rY   rm   sorted)rp   r   other_headersr~   r>   rE   	self_list
other_lists           r7   __eq__zHeaders.__eq__s  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 )NrS   r:   z, encoding=())	__class____name__r6   rn   ri   r   dictr   )rp   
class_nameencoding_stras_listas_dictno_duplicate_keyss         r7   __repr__zHeaders.__repr__}  s    ^^,,
==G#((9:L3D4D4D4FGHw-LCL8 \7+l^1==Qwk,q99r@   NN)rq   HeaderTypes | Noner6   
str | NonereturnNoner   rB   rE   rB   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]])r>   rB   r   r   )r>   rB   r   r0   r   zstr | _Trl   )r>   rB   r   z	_T | Noner   zstr | _T | None)F)r>   rB   r   boolr   z	list[str])rq   r   r   r   )r   r,   )r   zMapping[str, str]r   r,   )r   r   r   r,   )r>   rB   r   rB   )r>   rB   rE   rB   r   r   )r>   rB   r   r   )r>   
typing.Anyr   r   )r   ztyping.Iterator[typing.Any]r   int)r   r   r   r   )r   
__module____qualname____doc__rt   propertyr6   setterrw   r   r   rf   r   typingoverloadr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r@   r7   r,   r,      s     '+#"#" " 
	",  0 __  F FY	$#j __1 1__9 9,)5(@( ?!7:r@   r,   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)r-   N)	r^   rq   cookiescontentdatafilesjsonstream
extensionsc       	        0   |j                         | _        |t        |      nt        ||      | _        t	        |      | _        |i n
t        |      | _        |rt        |      j                  |        |
| j
                  j                  d      }t        ||||	t        |r%|j                  | j
                  j                        nd             \  }}
| j                  |       |
| _        t#        |
t$              r| j'                          y y |
| _        y )N)r^   rH   )rN   )r   r   r   r   boundary)uppermethodr(   rT   r,   rq   r   r   r+   set_cookie_headerr   r   r   r=   r6   _preparer   r;   r	   read)rp   r   rT   r^   rq   r   r   r   r   r   r   r   rN   s                r7   rt   zRequest.__init__  s     lln%~3s83s63Jw' * 2"Z8HG..t4>'+||'7'7'GL,AO[!4!4T\\5J5J!KaeOGV MM'" DK&*-		 ." !DKr@   c                ^   |j                         D ]e  \  }}|j                         dk(  rd| j                  v r(|j                         dk(  rd| j                  v rJ| j                  j                  ||       g 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content-lengthzTransfer-Encodingtransfer-encodingzContent-LengthHosts   Host)POSTPUTPATCHQUERY)s   Content-Length   0)rf   rd   rq   
setdefaultrT   hostrZ   netlocr   r,   rw   )rp   default_headersr>   rE   auto_headershas_hosthas_content_lengths          r7   r   zRequest._prepare  s   )//1 	0JCyy{..3F$,,3Vyy{116F$,,6VLL##C/	0 35T\\)-=dATX\XdXdAdDHHMM$((// :;!dkk5V&V 9:|dll.>.>>?r@   c                F    t        | d      s
t               | j                  S N_content)hasattrr   r  r   s    r7   r   zRequest.content  s    tZ( ""}}r@   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  r@   )r  r;   r   r   Iterabler   r  r	   r   s    r7   r   zRequest.read  sd     tZ(dkk6??;;;HHT[[1DMdkk:6 )7}}r@   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  r@   N)r  r;   r   r   AsyncIterabler   r  r	   )rp   parts     r7   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   r   z)>)r   r   rB   rT   r   )rp   r   rT   s      r7   r   zRequest.__repr__  s=    ^^,,
$((m:,abr::r@   c                t    | j                   j                         D ci c]  \  }}|dvs|| c}}S c c}}w )N)r   r   __dict__rf   rp   namerE   s      r7   __getstate__zRequest.__getstate__  s3    /3}}/B/B/DmeTlHlemmms   44c                z    |j                         D ]  \  }}t        | ||        i | _        t               | _        y rl   )rf   setattrr   r
   r   rp   stater  rE   s       r7   __setstate__zRequest.__setstate__  s8     ;;= 	'KD%D$&	'&(r@   )r   rB   rT   z	URL | strr^   zQueryParamTypes | Nonerq   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   rt   r   r   r   r   r  r   r  r#  r   r@   r7   r-   r-     s     *.&*&*)-#'%)"&:>/36!6! 6!
 '6! $6! $6! '6! !6! #6!  6! 86! -6! 
6!p@,  
;
n)r@   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&dBdGd)Z'dBdHd*Z(dId+Z)dBdGd,Z*dFd-Z+y)Jr.   Nrv   )
rq   r   texthtmlr   r   requestr   historydefault_encodingc       
           || _         t        |      | _        || _        d | _        |	i n
t        |	      | _        |
g n
t        |
      | _        d| _	        d| _
        || _        |Qt        ||||      \  }}| j                  |       || _        t        |t               r| j#                          d| _        y || _        d| _        y )NFr   )status_coder,   rq   _requestnext_requestr   r   rn   r/  	is_closedis_stream_consumedr0  r   r   r   r;   r	   r   _num_bytes_downloaded)rp   r2  rq   r   r,  r-  r   r   r.  r   r/  r0  s               r7   rt   zResponse.__init__  s     'w'(/ -1 * 2"Z8H$_r$w-"' 0>-gtT4HOGVMM'" DK&*-		 &'" !DK%&"r@   c                    |j                         D ]C  \  }}|j                         dk(  rd| j                  v r(| j                  j                  ||       E y )Nr   r   )rf   rd   rq   r  )rp   r  r>   rE   s       r7   r   zResponse._prepareE  sP    )//1 	0JCyy{116F$,,6VLL##C/		0r@   c                ~    t        | d      s&t        | j                  dd      }||S t        d      | j                  S )ze
        Returns the time taken for the complete request/response
        cycle to complete.
        _elapsedelapsedNzK'.elapsed' may only be accessed after the response has been read or closed.)r  getattrr   RuntimeErrorr:  )rp   stream_elapseds     r7   r;  zResponse.elapsedL  sC     tZ(8?YX\8]N)%%lmm}}r@   c                    || _         y rl   )r:  )rp   r;  s     r7   r;  zResponse.elapsedY  s	    r@   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.)r3  r=  r   s    r7   r.  zResponse.request]  s$    
 == XYY}}r@   c                    || _         y rl   )r3  r{   s     r7   r.  zResponse.requestf  s	    r@   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   rx   r   )rp   rC  s     r7   rC  zResponse.http_versionj  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:   rD  rE  )r   rx   r   r   get_reason_phraser2  )rp   rH  s     r7   rH  zResponse.reason_phrases  sV    	B#'???#CM !'''AA  	=**4+;+;<<	=s   $ (AAc                .    | j                   j                  S )zA
        Returns the URL for which the request was made.
        )r.  rT   r   s    r7   rT   zResponse.url|  s    
 ||r@   c                F    t        | d      s
t               | j                  S r  )r  r   r  r   s    r7   r   zResponse.content  s    tZ(!##}}r@   c                &   t        | d      sz| j                  }|sd| _        | j                  S t        | j                  xs d      }dj                  |j                  | j                        |j                         g      | _        | j                  S )N_textrS   rv   r5   )r  r   rM  r   r6   r   rx   flush)rp   r   decoders      r7   r,  zResponse.text  sr    tW%llG
 zz &t}}/GHWWgnnT\\&BGMMO%TU
zzr@   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.
        ro   r  rv   )r  charset_encodingr8   r;   r0  rB   r  ro   )rp   r6   s     r7   r6   zResponse.encoding  sv     t[),,H'9('Cd33S9#44HT:.#44T]]CH%0DN~~r@   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.
        rM  z?Setting encoding after `text` has been accessed is not allowed.N)r  rY   ro   r{   s     r7   r6   zResponse.encoding  s!     4!^__r@   c                T    | j                   j                  d      }|yt        |      S )zO
        Return the encoding, as specified by the Content-Type header.
        zContent-TypeN)rq   r   rP   )rp   rN   s     r7   rQ  zResponse.charset_encoding  s,    
 ||''7*<88r@   c                   t        | d      s| j                  j                  dd      }|D cg c]   }|j                         j	                         " }}t        |D cg c]
  }|dk7  s	| c}      }t        |j                        dk(  r |j                  d   | _        | j                  S |j                  r|| _        | j                  S t               | _        | j                  S c c}w c c}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)r   identityr   r   )
r  rq   r   rV   rd   r   r   childrenrU  r   )rp   r   rE   	encodingsr6   rO  s         r7   _get_content_decoderzResponse._get_content_decoder  s    
 tZ(\\**+=D*QF<BC5,,.CIC"Y#a(V`J`H#abG7##$) ' 0 0 3 }} !! ' }} !0 1}} D#as   %C&
C+)C+c                @    t        j                  | j                        S )zU
        A property which is `True` for 1xx status codes, `False` otherwise.
        )r   is_informationalr2  r   s    r7   r[  zResponse.is_informational  s    
 %%d&6&677r@   c                @    t        j                  | j                        S )zU
        A property which is `True` for 2xx status codes, `False` otherwise.
        )r   
is_successr2  r   s    r7   r]  zResponse.is_success  s    
  0 011r@   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_redirectr2  r   s    r7   r_  zResponse.is_redirect  s       !1!122r@   c                @    t        j                  | j                        S )zU
        A property which is `True` for 4xx status codes, `False` otherwise.
        )r   is_client_errorr2  r   s    r7   ra  zResponse.is_client_error      
 $$T%5%566r@   c                @    t        j                  | j                        S )zU
        A property which is `True` for 5xx status codes, `False` otherwise.
        )r   is_server_errorr2  r   s    r7   rd  zResponse.is_server_error  rb  r@   c                @    t        j                  | j                        S )z]
        A property which is `True` for 4xx and 5xx status codes, `False` otherwise.
        )r   is_errorr2  r   s    r7   rf  zResponse.is_error  s    
 ~~d..//r@   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)r2  r   MOVED_PERMANENTLYFOUND	SEE_OTHERTEMPORARY_REDIRECTPERMANENT_REDIRECTrq   r   s    r7   has_redirect_locationzResponse.has_redirect_location  sZ      ''(((( + dll*	
r@   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)r3  r=  r]  rn  r2  r   formatr   )rp   r.  rK   status_classerror_typesrt  s         r7   raise_for_statuszResponse.raise_for_status  s     --?k  ??K%%w w 
 ''3.'"	
 !__\3HI
..*.=gwFFr@   c                B    t        j                  | j                  fi |S rl   )jsonlibloadsr   )rp   kwargss     r7   r   zResponse.json=  s    }}T\\4V44r@   c                    t        | d      s*t               | _        | j                  j                  |        | j                  S )N_cookies)r  r+   r  extract_cookiesr   s    r7   r   zResponse.cookies@  s1    tZ(#IDMMM))$/}}r@   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
        r_   relrT   )rq   r   ra   )rp   headerr_   s      r7   r[   zResponse.linksG  sV    
 !!&)>IGZ[aGbct%3DHHUOd:cccs   ,Ac                    | j                   S rl   )r7  r   s    r7   num_bytes_downloadedzResponse.num_bytes_downloadedR  s    )))r@   c                <    d| j                    d| j                   dS )Nz<Response [ ]>)r2  rH  r   s    r7   r   zResponse.__repr__V  s%    T--.a0B0B/C2FFr@   c                r    | j                   j                         D ci c]  \  }}|dvr|| c}}S c c}}w )N)r   r   r5  rU  r  r  s      r7   r  zResponse.__getstate__Y  sB      $}}224
eLL %K
 	
 
s   3c                    |j                         D ]  \  }}t        | ||        d| _        i | _        t	               | _        y )NT)rf   r   r5  r   r
   r   r!  s       r7   r#  zResponse.__setstate__`  s?     ;;= 	'KD%D$&	'&(r@   c                z    t        | d      s$dj                  | j                               | _        | j                  S )7
        Read and return the response content.
        r  r@   )r  r   
iter_bytesr  r   s    r7   r   zResponse.readg  s/     tZ(HHT__%67DM}}r@   c              #    K   t        | d      r]|t        | j                        n|}t        dt        | j                        t	        |d            D ]  }| j                  |||z      y| j                         }t        |      }t        | j                        5  | j                         D ]2  }|j                  |      D ]  }|j                  |      D ]  }|   4 |j                         D ]  }|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, brotli, and zstd encoded responses.
        r  Nr   r   
chunk_sizer.  )r  r   r  rangemaxrY  r   r   r3  iter_rawrx   rN  )rp   r  irO  chunker	raw_bytesdecodedchunks           r7   r  zResponse.iter_byteso  s8    
 4$/9/AT]]+zJ1c$--0#j!2DE 8mmAJ778 //1G!Z8G 7 	 !% (I#*>>)#< (%,^^G%< (E"'K(((  '}} $G!(!8 $#$$ %]]_  EK 	  	  	 s   BEBD6-	E6D?;E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.
        rv   r5   r  r  N)r   r6   r   r   r3  r  rx   rN  rp   r  rO  r  byte_contenttext_contentr  s          r7   	iter_textzResponse.iter_text  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Nr  )r   r   r3  r  rx   rN  rp   rO  r,  lines       r7   
iter_lineszResponse.iter_lines  s|     -T]]3 	( #NN40 DJ   
		 	 	s   !BA	A6-	B6A?;Bc              #  L  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   4xY w# | j                          w xY ww)@
        A byte-iterator over the raw response content.
        z5Attempted to call a sync iterator on an async stream.Tr   r  r  N)r6  r   r5  r   r;   r   r'   r=  r7  r   r   r3  r   rx   rN  close)rp   r  r  raw_stream_bytesr  s        r7   r  zResponse.iter_raw  s      "" "">>. $++~6VWW"&%&"4
	 7 $(, $$..#6F2GG.!(0@!A $#$$$ !  JJL$ $ JJLs7   A,D$/D A
D!D 2D$DD 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.
        z2Attempted to call a sync close on an async stream.Tr  N)r;   r   r'   r=  r5  r   r3  r  r   s    r7   r  zResponse.close  sg    
 $++~6STT~~!DN 7 $!!#$ $ $ $s   A44A=c           	     t  K   t        | d      sIt        j                  | j                               4 d{   }dj	                  |2 cg c3 d{   }|| j
                  S 7 -7 6 nc c}w c}      | _        ddd      d{  7   | j
                  S # 1 d{  7  sw Y   | j
                  S xY ww)r  r  Nr@   )r  
contextlibaclosingaiter_bytesr   r  )rp   partsr  s      r7   r  zResponse.aread  s      tZ(!**4+;+;+=> I I% #)G)G$}}I)G)G)G HI I I}}I I I}}st   4B8A$B8B
A*
A(A&A(A*
B8&A((A*
)B;B8B	B8B5B!B5&B8c               .  K   t        | d      r^|t        | j                        n|}t        dt        | j                        t	        |d            D ]  }| j                  |||z      y| j                         }t        |      }t        | j                        5  t        j                  | j                               4 d{   }|2 3 d{   }|j                  |      D ]  }|j                  |      D ]  }| 	  ;7 A7 86 ddd      d{  7   n# 1 d{  7  sw Y   nxY w|j                         D ]  }|j                  |      D ]  }| 	  |j                         D ]  }| 	 	 ddd       y# 1 sw Y   yxY wwr  )r  r   r  r  r  rY  r   r   r3  r  r  	aiter_rawrx   rN  )	rp   r  r  rO  r  
raw_streamr  r  r  s	            r7   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 
 %..t~~/?@ , ,J+5 , ,i'.~~i'@ ,G)0)@ ,&+,,,,:, , , , ,
  '}} $G!(!8 $#$$ %]]_  EK 
  
  
 s   BF(F	D	F	D DD
D3D 	F	DD F	DF	 D2	&D)'D2	.AF	 	F	FF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r  )r   r6   r   r   r3  r  rx   rN  r  s          r7   
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r  )r   r   r3  r  rx   rN  r  s       r7   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               J  K   | j                   r
t               | j                  r
t               t	        | j
                  t              st        d      d| _         d| _        t        |      }| j
                  j                         }	 t        | j                        5  |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 ]  }| 	 	 t	        |t               r|j#                          d{  7   | j#                          d{  7   y# t	        |t               r|j#                          d{  7   | j#                          d{  7   w xY ww)r  z5Attempted to call an async iterator on a sync stream.Tr   r  r  N)r6  r   r5  r   r;   r   r   r=  r7  r   	__aiter__r   r3  r   rx   rN  r   aclose)rp   r  r  r   r  r  s         r7   r  zResponse.aiter_raw  sS     "" "">>. $++7VWW"&%&"4&&(	  7 $.4 $ $*..#6F2GG.!(0@!A $#$$f$ $ $ !  &.1mmo%%++- &.1mmo%%++-s   BF#	E C2"C'&C%'C'*;C2%C''C2)	E 2C;7!E #F#<D?=F#EF#$F  FF FF  F#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  z2Attempted to call an async close on a sync stream.Tr  N)r;   r   r   r=  r5  r   r3  r  r   s    r7   r  zResponse.aclose%  sv     
 $++7STT~~!DN 7 +kk((***+ +  ++ +s0   ABB /A>0B 4
B>B  B	B)r2  r   rq   r   r   zResponseContent | Noner,  r   r-  r   r   r   r   r%  r.  zRequest | Noner   zResponseExtensions | Noner/  zlist[Response] | Noner0  z*str | typing.Callable[[bytes], str | None]r   r   r&  )r   datetime.timedelta)r;  r  r   r   )r   r-   )rE   r-   r   r   r   )r   r(   r'  )r   r   r   )r   r   r   r   )r   r.   )r}  r   r   r   )r   r+   )r   z dict[str | None, dict[str, str]]r   r(  r*  rl   )r  
int | Noner   ztyping.Iterator[bytes])r  r  r   typing.Iterator[str]r   r  )r   r   )r  r  r   z"typing.AsyncGenerator[bytes, None])r  r  r   typing.AsyncIterator[str])r   r  ),r   r   r   rt   r   r   r;  r   r.  rC  rH  rT   r   r,  r6   rQ  rY  r[  r]  r_  ra  rd  rf  rn  ry  r   r   r[   r  r   r  r#  r   r  r  r  r  r  r  r  r  r  r  r  r   r@   r7   r.   r.     s   
 '+*.:>"&04)-GN5'5' $	5'
 (5' 5' 5' 5' 85'  5' .5' '5' E5' 
5'n0 
 
 ^^      ^^  A A B B      
    * __	 	 9 9$ 8 8 2 2 	3 	3 7 7 7 7 0 0 
 
,"GH5   d d * *G
) .&6$ 0& <+r@   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 rl   )	r;   r   r   jarrf   setrn   r+   
set_cookie)rp   r   r>   rE   cookies        r7   rt   zCookies.__init__8  s    ?j$7 {DH'4(")--/ )JCHHS%() ) & {DH% %
Ue$%) {DH!++ ,##F+, DHr@   c                    d|j                   vrd|j                   vry| j                  |      }| j                  |j                        }| j                  j                  ||       y)zO
        Loads any cookies based on the response `Set-Cookie` headers.
        z
set-cookiezset-cookie2N)rq   _CookieCompatResponse_CookieCompatRequestr.  r  r  )rp   ru  urllib_responseurllib_requests       r7   r  zCookies.extract_cookiesI  s\     x///MIYIY4Y44X>2283C3CD  .Ar@   c                \    | j                  |      }| j                  j                  |       y)zM
        Sets an appropriate 'Cookie:' HTTP header on the `Request`.
        N)r  r  add_cookie_header)rp   r.  r  s      r7   r   zCookies.set_cookie_headerU  s&     227;"">2r@   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  rE   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  )rp   r  rE   r  r  r}  r  s          r7   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#r@   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   rE   )rp   r  r   r  r  rE   r  rK   s           r7   r   zCookies.getv  s     hh 	-F{{d">V]]f%<|v{{d': ,(I$&PG"0"99 &	- =Nr@   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  )rp   r  r  r  r  removes         r7   deletezCookies.delete  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)rZ   r  r  )rp   r  r  argss       r7   r  zCookies.clear  sK    
 KK%%%KKr@   c                r    t        |      }|j                  D ]  }| j                  j                  |        y rl   )r+   r  r  )rp   r   r  s      r7   r   zCookies.update  s1    '"kk 	(FHH'	(r@   c                &    | j                  ||      S rl   )r  r  s      r7   r   zCookies.__setitem__  s    xxe$$r@   c                B    | j                  |      }|t        |      |S rl   )r   r   r  s      r7   r   zCookies.__getitem__  s#    =4. r@   c                $    | j                  |      S rl   )r  )rp   r  s     r7   r   zCookies.__delitem__  s    {{4  r@   c                ,    t        | j                        S rl   )r   r  r   s    r7   r   zCookies.__len__  s    488}r@   c                (    d | j                   D        S )Nc              3  4   K   | ]  }|j                     y wrl   )r  ).0r  s     r7   	<genexpr>z#Cookies.__iter__.<locals>.<genexpr>  s     33s   r  r   s    r7   r   zCookies.__iter__  s    3$((33r@   c                (    | j                   D ]  } y y)NTFr  )rp   r~   s     r7   __bool__zCookies.__bool__  s     	A	r@   c                    dj                  | j                  D cg c],  }d|j                   d|j                   d|j                   d. c}      }d| dS c c}w )Nr   z<Cookie rU   z for z />z	<Cookies[r  )r   r  r  rE   r  )rp   r  cookies_reprs      r7   r   zCookies.__repr__  s]    yyZ^ZbZbcPVx}Afll^5sKc
 <.++ d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)rT   rq   r   )superrt   rB   rT   r   rq   r   r.  )rp   r.  r   s     r7   rt   z%Cookies._CookieCompatRequest.__init__  s=    G$W__-~~  
 #DLr@   c                X    t         |   ||       || j                  j                  |<   y rl   )r  add_unredirected_headerr.  rq   )rp   r>   r]   r   s      r7   r  z4Cookies._CookieCompatRequest.add_unredirected_header  s&    G+C5(+DLL  %r@   r.  r-   r   r   )r>   rB   r]   rB   r   r   )r   r   r   r   rt   r  __classcell__)r   s   @r7   r  r    s    	
	#	, 	,r@   r  c                       e Zd ZdZddZddZy)Cookies._CookieCompatResponser  c                    || _         y rl   )ru  )rp   ru  s     r7   rt   z&Cookies._CookieCompatResponse.__init__  s	    $DMr@   c                    t         j                  j                         }| j                  j                  j                         D ]
  \  }}|||<    |S rl   )rJ   rK   rL   ru  rq   r   )rp   infor>   rE   s       r7   r  z"Cookies._CookieCompatResponse.info  sL    ==((*D"mm33??A "
U "S		"
 Kr@   Nru  r.   r   r   )r   zemail.message.Message)r   r   r   r   rt   r  r   r@   r7   r  r    s    	
	%	r@   r  rl   )r   r$  r   r   r  r  )rS   /)
r  rB   rE   rB   r  rB   r  rB   r   r   )NNN)
r  rB   r   r   r  r   r  r   r   r   r   )r  rB   r  r   r  r   r   r   )r  r   r  r   r   r   )r  rB   rE   rB   r   r   )r  rB   r   rB   )r  rB   r   r   r   r  r  r   )r   r   r   r   rt   r  r   r  r   r  r  r   r   r   r   r   r   r  r   urllibr.  r-   r  r  r   r@   r7   r+   r+   3  s    "
B3$: #!  	
  
8 "	DD D 	D
 
D0(
%!4
,,v~~55 ,$ r@   r+   )r6   rB   r   r   rl   )r>   str | bytesr6   r   r   r<   )rE   r  r6   r   r   r<   )rN   rB   r   r   )rE   rB   r   zlist[dict[str, str]])rf   z4typing.Iterable[tuple[typing.AnyStr, typing.AnyStr]]r   z4typing.Iterator[tuple[typing.AnyStr, typing.AnyStr]])M
__future__r   r2   r  datetimeemail.messagerJ   r   r{  rW   r   urllib.requestr  collections.abcr   r   http.cookiejarr   r   r  r	   r
   r   r   	_decodersr   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*   __all__re   TypeVarr0   r8   r?   rF   rP   ra   ri   MutableMappingrB   r,   r-   r.   r+   r   r@   r7   <module>r     s   "      	   3 , S S     A       +
7$&;< V^^DN-1"J?9}:f##CH- }:@}) })@c+ c+LFf##CH- Fr@   