
    =hȦ                        d dl Z d dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZmZ ddlmZmZmZmZ ddlmZmZmZmZmZmZmZmZ ddlmZmZmZmZm Z m!Z!m"Z" ddl#m$Z$ dd	l%m&Z& dd
l'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<  G d dejz                  e>e>f         Z? G d d      Z@ G d d      ZA G d dejz                  e>e>f         ZBy)    N)Mapping)Cookie	CookieJar   )
ByteStreamUnattachedStreamencode_requestencode_response)SUPPORTED_DECODERSByteChunkerContentDecoderIdentityDecoderLineDecoderMultiDecoderTextChunkerTextDecoder)CookieConflictHTTPStatusErrorRequestNotReadResponseNotReadStreamClosedStreamConsumedrequest_context)(get_multipart_boundary_from_content_type)codes)AsyncByteStreamCookieTypesHeaderTypesQueryParamTypesRequestContentRequestDataRequestExtensionsRequestFilesResponseContentResponseExtensionsSyncByteStream)URL)guess_json_utfis_known_encodingnormalize_header_keynormalize_header_valueobfuscate_sensitive_headersparse_content_type_charsetparse_header_linksc                      e Zd ZdZ	 	 ddej
                  e   dej
                  e   ddfdZe	defd       Z
e
j                  deddfd	       Z
e	dej                  ej                  eef      fd
       Zdej                   e   fdZdej$                  e   fdZdej(                  eef   fdZdej                  ej                  eef      fdZd dedej.                  dej.                  fdZd!dededej                  e   fdZd dej
                  e   ddfdZd"dZdedefdZdededdfdZdeddfdZdej.                  defdZ dejB                  ej.                     fdZ"de#fdZ$dej.                  defdZ%defdZ&y)#Headersz9
    HTTP headers, as a case-insensitive multi-dict.
    Nheadersencodingreturnc           
         |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)lowerr2   T)	_list
isinstancer0   listr   itemsr*   r+   	_encoding)selfr1   r2   kvs        ]/var/www/html/phonemate/phone_mate_backend/venv/lib/python3.12/site-packages/httpx/_models.py__init__zHeaders.__init__=   s   
 ?DJ, "+ )gmm,DJ( "' ) $MMO ,DAq	 )%(K($J*1h7
 ,DJ$ " $ $DAq	 )%(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)r:   rawdecodeUnicodeDecodeError)r;   r2   keyvalues       r>   r2   zHeaders.encoding[   s     >>!."&((JC

8,X. #+ &.DN
 ~~! / ".~~ . s   "A11	A>=A>rG   c                     || _         y Nr:   r;   rG   s     r>   r2   zHeaders.encodingt   	        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.
        )r6   )r;   raw_key_rG   s       r>   rC   zHeaders.rawx   s,    
 ;?**E*%6Wa% *EEEs   %c                     | j                   D ci c]"  \  }}}|j                  | j                        d $ c}}}j                         S c c}}}w rI   )r6   rD   r2   keysr;   rP   rF   rG   s       r>   rR   zHeaders.keys   s?    EIZZPZMAsE

4==)4/Z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, )r6   rD   r2   valuesr;   values_dictrP   rF   rG   str_key	str_values          r>   rV   zHeaders.values   sy    -/!ZZMAsEjj/GT]]3I+%G$"YK(88$'0G$ ( !!##rM   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.
        rU   )r6   rD   r2   r9   rW   s          r>   r9   zHeaders.items   s{    
 .0!ZZMAsEjj/GT]]3I+%G$"YK(88$'0G$ (   ""rM   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.
        )r6   rD   r2   rS   s       r>   multi_itemszHeaders.multi_items   sR     "&
!+3 ZZ&T]](CD!+
 	
 
s   AArF   defaultc                 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)r;   rF   r^   s      r>   getzHeaders.get   s%    
	9 	N	s    split_commasc                    |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.
        ,)r5   encoder2   r6   rD   extendsplitstrip)r;   rF   rb   get_header_keyrP   item_key
item_valuerV   split_valuesrG   items              r>   get_listzHeaders.get_list   s     ++DMM: ,0::
+5'8Z~~>1 dmm,+5 	 
 ME%++c:J K:J$:J KL 
 !Ls   9C C	
c                     t        |      }|j                         D ]  }|| v s| j                  |        | j                  j	                  |j                         y rI   )r0   rR   popr6   rf   )r;   r1   rF   s      r>   updatezHeaders.update   sF    '"<<>Cd{ " 	

'--(rM   c                 0    t        | | j                        S )Nr2   )r0   r2   r;   s    r>   copyzHeaders.copy   s    tdmm44rM   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
        rU   )r5   re   r2   r6   rD   joinr`   )r;   rF   normalized_keyrP   
header_keyheader_valuer9   s          r>   __getitem__zHeaders.__getitem__   s     ++DMM: 04zz
/9+:|^+ ./9 	 
 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.
        rB   r   Nr   )re   r:   r5   	enumerater6   reversedappend)
r;   rF   rG   set_key	set_value
lookup_keyidxrP   rj   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)r5   re   r2   r}   r6   r`   r~   )r;   rF   del_keyr   rP   rj   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 rI   )r5   re   r2   r6   )r;   rF   ry   rP   s       r>   __contains__zHeaders.__contains__  sC    YY[''6
4::>:iaac:>>>>s   Ac                 4    t        | j                               S rI   )iterrR   rt   s    r>   __iter__zHeaders.__iter__  s    DIIK  rM   c                 ,    t        | j                        S rI   )lenr6   rt   s    r>   __len__zHeaders.__len__  s    4::rM   otherc                    	 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   
ValueErrorr6   sorted)r;   r   other_headersrP   rF   rG   	self_list
other_lists           r>   __eq__zHeaders.__eq__  s    	#ENM 8<zzBzmaec5\z	B8E8K8KL8K}q#usEl8K
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 rA   z, encoding=())	__class____name__r2   r8   r,   r]   dictr   )r;   
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9rM   NNrI   )F)r3   r0   )'r   
__module____qualname____doc__typingOptionalr   strr?   propertyr2   setterListTuplebytesrC   KeysViewrR   
ValuesViewrV   	ItemsViewr9   r]   Anyra   boolrn   rq   ru   r{   r   r   r   Iteratorr   intr   r   r    rM   r>   r0   r0   8   s+    15)-"-" //#&" 
	"< #  0 __c d   FV[[eUl!;< F FXfooc* X	$))#. 	$#v''S1 #	
V[[c3h)?@ 	
s VZZ 6:: C t C@P ,)fook: )d )5s s (@s @3 @4 @0 s  t  $?

 ?t ?!&//&**5 ! 7FJJ 74 7:# :rM   r0   c                   ~   e Zd Zdddddddddd	dej                  eef   dej                  def   dej                  e   dej                  e	   dej                  e
   d	ej                  e   d
ej                  e   dej                  e   dej                  ej                     dej                  eedf   dej                  e   fdZdej&                  eef   ddfdZedefd       ZdefdZdefdZdefdZdej&                  eej                  f   fdZdej&                  eej                  f   ddfdZy)RequestN)	paramsr1   cookiescontentdatafilesjsonstream
extensionsmethodurlr'   r   r1   r   r   r   r   r   r   r   c       	            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 )NrA   )r   zcontent-type)content_type)r   r   r   r   boundary)r7   r   rD   upperr   r'   r   copy_merge_paramsr0   r1   r   Cookiesset_cookie_headerra   r	   r   re   r2   _preparer   r   read)r;   r   r   r   r1   r   r   r   r   r   r   r   r   s                r>   r?   zRequest.__init__4  s"   " &%( MM'"((* 	
 s8xx111@DHw' * 2"
G..t4>151A1A.1QL,A# ".!4!4T\\5J5J!K
OGV MM'" DK&*-		 .  !DKrM   default_headersr3   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)r9   r5   r1   
setdefaultr   hostr   netlocr   r0   rC   )r;   r   rF   rG   auto_headershas_hosthas_content_lengths          r>   r   zRequest._prepares  s    )//1JCyy{116F$,,6VLL##C/	 2 ACT\\),S0Ct||0S 	 DHHMM$((// :;!dkk5M&M 9:|dll.>.>>?rM   c                 F    t        | d      s
t               | j                  S N_content)hasattrr   r   rt   s    r>   r   zRequest.content  s    tZ( ""}}rM   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   rM   )r   r7   r   r   Iterablerw   r   r   rt   s    r>   r   zRequest.read  sd     tZ(dkk6??;;;HHT[[1DMdkk:6 )7}}rM   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   rM   N)r   r7   r   r   AsyncIterablerw   r   r   r;   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   rU   z)>)r   r   r   r   r   )r;   r   r   s      r>   r   zRequest.__repr__  s=    ^^,,
$((m:,abr::rM   c                 r    | j                   j                         D ci c]  \  }}|dvr|| c}}S c c}}w )N)r   r   __dict__r9   r;   namerG   s      r>   __getstate__zRequest.__getstate__  sG      $}}224
4e33 %K4
 	
 
   3statec                 z    |j                         D ]  \  }}t        | ||        i | _        t               | _        y rI   )r9   setattrr   r   r   r;   r   r   rG   s       r>   __setstate__zRequest.__setstate__  s3     ;;=KD%D$& )&(rM   )r   r   r   r   Unionr   r   r   r   r   r   r    r!   r#   r   r&   r   r"   r?   Dictr   r   r   r   r   r   r   r   r   rM   r>   r   r   3  s    48040437-1/3,0FJ9==!S%Z(=! \\%*%=!
 0=! -=! -=! 0=! ook*=! |,=! oofjj)=! ^_dBC=! OO$56=!~@CH(= @$ @*   
e U ;# ;

fkk#vzz/: 
)&++c6::o"> )4 )rM   r   c                      e Zd Zddddddddddd
dedej
                  e   dej
                  e   dej
                  e   dej
                  e   d	ej                  d
ej                  eedf   dej
                  e   dej
                  e   dej
                  ej                  d       dej                  eej                   egef   f   fdZdej&                  eef   ddfdZedej.                  fd       Zej2                  dej.                  ddfd       Zedefd       Zej2                  deddfd       Zedefd       Zedefd       Zedefd       Zedefd       Zedefd       Z edej
                  e   fd       Z!e!j2                  deddfd       Z!edej
                  e   fd        Z"de#fd!Z$ede%fd"       Z&ede%fd#       Z'ede%fd$       Z(ede%fd%       Z)ede%fd&       Z*ede%fd'       Z+ede%fd(       Z,d@d)Z-d*ej                  dej                  fd+Z.edAd,       Z/edej&                  ej
                  e   ej&                  eef   f   fd-       Z0edefd.       Z1defd/Z2dej&                  eej                  f   fd0Z3d1ej&                  eej                  f   ddfd2Z4defd3Z5	 dBd4ej
                  e   dejl                  e   fd5Z7	 dBd4ej
                  e   dejl                  e   fd6Z8dejl                  e   fd7Z9	 dBd4ej
                  e   dejl                  e   fd8Z:d@d9Z;defd:Z<	 dBd4ej
                  e   dejz                  e   fd;Z>	 dBd4ej
                  e   dejz                  e   fd<Z?dejz                  e   fd=Z@	 dBd4ej
                  e   dejz                  e   fd>ZAd@d?ZBy)CResponseNrB   )
r1   r   texthtmlr   r   requestr   historydefault_encodingstatus_coder1   r   r   r   r   r   r   r   r   r   c       
         x   || _         t        |      | _        || _        d | _        |	i n|	| _        |
g n
t        |
      | _        d| _        d| _	        || _
        |Qt        ||||      \  }}| j                  |       || _        t        |t              r| j!                          d| _        y || _        d| _        y )NFr   )r  r0   r1   _requestnext_requestr   r8   r   	is_closedis_stream_consumedr   r
   r   r   r7   r   r   _num_bytes_downloaded)r;   r  r1   r   r   r   r   r   r   r   r   r   s               r>   r?   zResponse.__init__  s     'w'29 7; * 2"
$_r$w-"' 0>-gtT4HOGVMM'" DK&*-		 &'" !DK%&"rM   r   r3   c                     |j                         D ]C  \  }}|j                         dk(  rd| j                  v r(| j                  j                  ||       E y )Nr   zcontent-length)r9   r5   r1   r   )r;   r   rF   rG   s       r>   r   zResponse._prepare  sK    )//1JCyy{116F$,,6VLL##C/	 2rM   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
  rt   s    r>   elapsedzResponse.elapsed  s,     tZ(+  }}rM   r  c                     || _         y rI   )r
  )r;   r  s     r>   r  zResponse.elapsed	  s	    rM   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  rt   s    r>   r   zResponse.request  s*    
 == I  }}rM   rG   c                     || _         y rI   )r  rK   s     r>   r   zResponse.request  s	    rM   c                 f    	 | j                   d   }|j                  dd      S # t        $ r Y yw xY w)Nhttp_versionrA   ignoreerrorszHTTP/1.1)r   rD   r`   )r;   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_phraserA   r  r  )r   rD   r`   r   get_reason_phraser  )r;   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   rt   s    r>   r   zResponse.url.  s    
 ||rM   c                 F    t        | d      s
t               | j                  S r   )r   r   r   rt   s    r>   r   zResponse.content5  s    tZ(!##}}rM   c                 &   t        | d      sz| j                  }|sd| _        | j                  S t        | j                  xs d      }dj                  |j                  | j                        |j                         g      | _        | j                  S )N_textr   rB   rs   )r   r   r  r   r2   rw   rD   flush)r;   r   decoders      r>   r   zResponse.text;  sr    tW%llG
 zz &t}}/GHWWgnnT\\&BGMMO%TU
zzrM   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.
        r:   r   rB   )r   charset_encodingr)   r7   r   r   r   r:   )r;   r2   s     r>   r2   zResponse.encodingF  sv     t[),,H'8'Bd33S9#44HT:.#44T]]CH%0DN~~rM   c                     || _         y rI   rJ   rK   s     r>   r2   zResponse.encoding\  rL   rM   c                 T    | j                   j                  d      }|yt        |      S )zO
        Return the encoding, as specified by the Content-Type header.
        zContent-TypeN)r1   ra   r-   )r;   r   s     r>   r  zResponse.charset_encoding`  s,    
 ||''7),77rM   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)rb   r   r   )children)r   r1   rn   rh   r5   r   r   r`   r   r#  r   r   )r;   decodersrV   rG   decoder_clss        r>   _get_content_decoderzResponse._get_content_decoderk  s    
 tZ(46H\\**+=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  rt   s    r>   r)  zResponse.is_informational  s    
 %%d&6&677rM   c                 @    t        j                  | j                        S )zU
        A property which is `True` for 2xx status codes, `False` otherwise.
        )r   
is_successr  rt   s    r>   r+  zResponse.is_success  s    
  0 011rM   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  rt   s    r>   r-  zResponse.is_redirect  s       !1!122rM   c                 @    t        j                  | j                        S )zU
        A property which is `True` for 4xx status codes, `False` otherwise.
        )r   is_client_errorr  rt   s    r>   r/  zResponse.is_client_error      
 $$T%5%566rM   c                 @    t        j                  | j                        S )zU
        A property which is `True` for 5xx status codes, `False` otherwise.
        )r   is_server_errorr  rt   s    r>   r2  zResponse.is_server_error  r0  rM   c                 @    t        j                  | j                        S )z]
        A property which is `True` for 4xx and 5xx status codes, `False` otherwise.
        )r   is_errorr  rt   s    r>   r4  zResponse.is_error  s    
 ~~d..//rM   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_REDIRECTr1   rt   s    r>   has_redirect_locationzResponse.has_redirect_location  sZ      ''(((( + dll*	
rM   c                    | j                   }|t        d      | j                  ry| j                  rd}nd}| j                  dz  }dddd	d
}|j                  |d      }|j                  | |      }t        |||       )z>
        Raise the `HTTPStatusError` if one occurred.
        NzYCannot call `raise_for_status` as the request instance has not been set on this response.z{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'
Redirect location: '{0.headers[location]}'
For more information check: https://httpstatuses.com/{0.status_code}z{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'
For more information check: https://httpstatuses.com/{0.status_code}d   zInformational responsezRedirect responsezClient errorzServer error)r            zInvalid status code)
error_type)r   response)r  r  r+  r<  r  ra   formatr   )r;   r   messagestatus_classerror_typesrB  s         r>   raise_for_statuszResponse.raise_for_status  s     --?> 
 ??%%W W 
 ''3.'"	
 !__\3HI
..*.=gwFFrM   kwargsc                 .   | j                   j| j                  r^t        | j                        dkD  rFt        | j                        }|/t	        j
                  | j                  j                  |      fi |S t	        j
                  | j                  fi |S )Nr?  )r  r   r   r(   jsonlibloadsrD   r   )r;   rI  r2   s      r>   r   zResponse.json  st      (T\\c$,,>ORS>S%dll3H#}}T\\%8%8%BMfMM}}TYY1&11rM   c                     t        | d      s*t               | _        | j                  j                  |        | j                  S )N_cookies)r   r   rN  extract_cookiesrt   s    r>   r   zResponse.cookies  s1    tZ(#IDMMM))$/}}rM   c                     | j                   j                  d      }i }|r;t        |      }|D ]+  }|j                  d      xs |j                  d      }|||<   - |S )zI
        Returns the parsed header links of the response, if any
        linkrelr   )r1   ra   r.   )r;   headerldictlinksrQ  rF   s         r>   rU  zResponse.links  s^    
 !!&)&v.Ehhuo8%!c
  rM   c                     | j                   S rI   )r  rt   s    r>   num_bytes_downloadedzResponse.num_bytes_downloaded  s    )))rM   c                 <    d| j                    d| j                   dS )Nz<Response [ ]>)r  r  rt   s    r>   r   zResponse.__repr__  s%    T--.a0B0B/C2FFrM   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__  sG      $}}224
4eLL %K4
 	
 
r   r   c                     |j                         D ]  \  }}t        | ||        d| _        i | _        t	               | _        y )NT)r9   r   r  r   r   r   r   s       r>   r   zResponse.__setstate__  s:     ;;=KD%D$& )&(rM   c                 z    t        | d      s$dj                  | j                               | _        | j                  S )7
        Read and return the response content.
        r   rM   )r   rw   
iter_bytesr   rt   s    r>   r   zResponse.read   s/     tZ(HHT__%67DM}}rM   
chunk_sizec              #   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   r`  r   )r   r   r   rangemaxr'  r   r   r  iter_rawrD   r  r;   r`  ir  chunker	raw_bytesdecodedchunks           r>   r_  zResponse.iter_bytes(  s     4$/9/AT]]+zJ1c$--0#j!2DEmmAJ77 F //1G!Z8G 7!%I%nnY7G!(!8# "9 "1 "--/$^^G4EK 5$]]_EK - 877s   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.
        rB   rs   rc  rd  N)r   r2   r   r   r  r_  rD   r  r;   r`  r  rj  byte_contenttext_contentrm  s          r>   	iter_textzResponse.iter_textA  s      t}}'?@4T]]3 $ 1&~~l;$^^L9EK : !2 #==?L 5 6  ) 433s   =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Nrd  )r   r   r  rs  rD   r  r;   r  r   lines       r>   
iter_lineszResponse.iter_linesV  sd     -T]]3(#NN40DJ 1 )  
 (	 433s   !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   rc  rd  N)r  r   r  r   r7   r   r&   r  r  r   r   r  r   rD   r  closer;   r`  rj  raw_stream_bytesrm  s        r>   rg  zResponse.iter_raw_  s      "" "">>. $++~6VWW"&%&"4T]]3$(KK **c2B.CC*$^^,<=EK > %0 4 ]]_EK % 	

 43s   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.Trd  N)r7   r   r&   r  r  r   r  r{  rt   s    r>   r{  zResponse.close{  s\    
 $++~6TUU~~!DN 7!!# 87 77s   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   rM   N)r   rw   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rb  )r   r   r   re  rf  r'  r   r   r  	aiter_rawrD   r  rh  s           r>   r  zResponse.aiter_bytes  s     4$/9/AT]]+zJ1c$--0#j!2DEmmAJ77 F //1G!Z8G 7'+~~'7 $)%nnY7G!(!8# "9$'7 "--/$^^G4EK 5$]]_EK - 877sC   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ro  )r   r2   r   r   r  r  rD   r  rp  s          r>   
aiter_textzResponse.aiter_text  s      t}}'?@4T]]3&*&6&6&8  l&~~l;$^^L9EK : &8 #==?L 5 6  ) 433sA   =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ru  )r   r   r  r  rD   r  rv  s       r>   aiter_lineszResponse.aiter_lines  sm     -T]]3"oo/ d#NN40DJ 1/  
 (	 433s<   !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)rz  z6Attempted to call an async iterator on an sync stream.Tr   rc  rd  N)r  r   r  r   r7   r   r   r  r  r   r   r  r   rD   r  acloser|  s        r>   r  zResponse.aiter_raw  s      "" "">>. $++7WXX"&%&"4T]]3*.++  &**c2B.CC*$^^,<=EK > + 433 ]]_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.Trd  N)r7   r   r   r  r  r   r  r  rt   s    r>   r  zResponse.aclose  sm     
 $++7TUU~~!DN 7kk((*** 87  + 87s0   ABB /A>0B 4
B>B  B	B)r3   N)r3   r   rI   )Cr   r   r   r   r   r   r   r$   r   r   r   r&   r   r   r%   r   Callabler   r?   r   r   r   datetime	timedeltar  r   r   r  r  r'   r   r   r   r2   r  r   r'  r   r)  r+  r-  r/  r2  r4  r<  rH  r   r   rU  rW  r   r   r   r   r   r_  rs  rx  rg  r{  r   AsyncIteratorr  r  r  r  r  r   rM   r>   r   r     s   
 1548%)%)FJ,0:><@MT5'5' -	5'
 15' ooc"5' ooc"5' jj5' ^_dBC5' )5' OO$675' Z!895' !,,sFOOUGSL,I'IJ5'n0CH(= 0$ 0 
++ 
 
 ^^ x11  d        ^^W    Ac A A Bs B B  S       
 c   &//#.  * __c d   8&//#"6 8 8n 2 8$ 8 8 2D 2 2 	3T 	3 	3 7 7 7 7 7 7 0$ 0 0 
t 
 
,#GJ2VZZ 2FJJ 2   v{{6??3#7S#X9N#NO   *c * *G# G
fkk#vzz/: 
)&++c6::o"> )4 )e  26  //#. 		 4 26 //#.		*FOOC0  26 //#.		8$U  26  //#. 			e	$ 4 26 //#.			c	"*6#7#7#<  26 //#.			e	$8+rM   r   c                      e Zd ZdZddej
                  e   ddfdZdeddfdZ	de
ddfd	Zd d
ededededdf
dZ	 	 	 d!d
edej
                  e   dej
                  e   dej
                  e   dej
                  e   f
dZ	 	 d"d
edej
                  e   dej
                  e   ddfdZ	 d"dej
                  e   dej
                  e   ddfdZddej
                  e   ddfdZd
ededdfdZd
edefdZd
eddfdZdefdZdej.                  e   fdZdefdZdefdZ G d dej:                  j                        Z G d d      Zy)#r   z-
    HTTP Cookies, as a mutable mapping.
    Nr   r3   c                    |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 rI   )	r7   r   r   jarr9   setr8   r   
set_cookie)r;   r   rF   rG   cookies        r>   r?   zCookies.__init__  s    ?j$7 {DH'4(")--/JCHHS%( #2 ) & {DH%
Ue$ &) {DH!++##F+ & DHrM   rC  c                     | j                  |      }| j                  |j                        }| j                  j	                  ||       y)zO
        Loads any cookies based on the response `Set-Cookie` headers.
        N)_CookieCompatResponse_CookieCompatRequestr   r  rO  )r;   rC  urllib_responseurllib_requests       r>   rO  zCookies.extract_cookies  s>     44X>2283C3CD  .ArM   r   c                 \    | j                  |      }| j                  j                  |       y)zM
        Sets an appropriate 'Cookie:' HTTP header on the `Request`.
        N)r  r  add_cookie_header)r;   r   r  s      r>   r   zCookies.set_cookie_header  s&     227;"">2rM   r   rG   domainpathc                     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   rG   portNport_specifiedFr  domain_specifieddomain_initial_dot.r  path_specifiedsecureexpiresdiscardTcommentcomment_urlrestHttpOnlyrfc2109r   )r   
startswithr   r  r  )r;   r   rG   r  r  rI  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#rM   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   rG   )r;   r   r^   r  r  rG   r  rE  s           r>   ra   zCookies.get1  sz     hhF{{d">V]]f%<|v{{d': ,(I$&PG"0"99 &  =NrM   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  )r;   r   r  r  r  removes         r>   deletezCookies.deleteJ  s     $"288>>&$55 ((
"{{d"6==F#:!4	 " 	 
 FHHNN6==&++v{{C 
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  )r;   r  r  argss       r>   r  zCookies.clearb  sK     KK%%%KKrM   c                 r    t        |      }|j                  D ]  }| j                  j                  |        y rI   )r   r  r  )r;   r   r  s      r>   rq   zCookies.updateq  s,    '"kkFHH' "rM   c                 &    | j                  ||      S rI   )r  r   s      r>   r   zCookies.__setitem__v  s    xxe$$rM   c                 B    | j                  |      }|t        |      |S rI   )ra   r`   r   s      r>   r{   zCookies.__getitem__y  s#    =4. rM   c                 $    | j                  |      S rI   )r  )r;   r   s     r>   r   zCookies.__delitem__  s    {{4  rM   c                 ,    t        | j                        S rI   )r   r  rt   s    r>   r   zCookies.__len__  s    488}rM   c                 (    d | j                   D        S )Nc              3   4   K   | ]  }|j                     y wrI   )r   ).0r  s     r>   	<genexpr>z#Cookies.__iter__.<locals>.<genexpr>  s     3((s   r  rt   s    r>   r   zCookies.__iter__  s    3$((33rM   c                 (    | j                   D ]  } y y)NTFr  )r;   rP   s     r>   __bool__zCookies.__bool__  s    A rM   c                     dj                  | j                  D cg c],  }d|j                   d|j                   d|j                   d. c}      }d| dS c c}w )NrU   z<Cookie =z for z />z	<Cookies[rZ  )rw   r  r   rG   r  )r;   r  cookies_reprs      r>   r   zCookies.__repr__  sh    yy #hh&F 6;;-qeFMM?#N&
 <.++s   1Ac                   D     e Zd ZdZdeddf fdZdededdf fdZ xZS )	Cookies._CookieCompatRequest
        Wraps a `Request` instance up in a compatibility interface suitable
        for use with `CookieJar` operations.
        r   r3   Nc                     t         |   t        |j                        t	        |j
                        |j                         || _        y )N)r   r1   r   )superr?   r   r   r   r1   r   r   )r;   r   r   s     r>   r?   z%Cookies._CookieCompatRequest.__init__  s=    G$W__-~~  
 #DLrM   rF   rG   c                 X    t         |   ||       || j                  j                  |<   y rI   )r  add_unredirected_headerr   r1   )r;   rF   rG   r   s      r>   r  z4Cookies._CookieCompatRequest.add_unredirected_header  s&    G+C7(-DLL  %rM   )	r   r   r   r   r   r?   r   r  __classcell__)r   s   @r>   r  r    s:    	
	#G 	# 	#	.s 	.3 	.4 	. 	.rM   r  c                   P    e Zd ZdZdefdZdej                  j                  fdZ	y)Cookies._CookieCompatResponser  rC  c                     || _         y rI   )rC  )r;   rC  s     r>   r?   z&Cookies._CookieCompatResponse.__init__  s	    $DMrM   r3   c                     t         j                  j                         }| j                  j                  j                         D ]
  \  }}|||<    |S rI   )emailrE  MessagerC  r1   r]   )r;   inforF   rG   s       r>   r  z"Cookies._CookieCompatResponse.info  sH    ==((*D"mm33??A
U "S		 B
 KrM   N)
r   r   r   r   r   r?   r  rE  r  r  r   rM   r>   r  r    s)    	
	%X 	%	%--// 	rM   r  rI   )r   /)NNNr   ) r   r   r   r   r   r   r   r?   r   rO  r   r   r   r  ra   r  r  rq   r   r{   r   r   r   r   r   r   r  r   urllibr   r  r  r   rM   r>   r   r     s    <  "B BT B3 3T 3$ $C $ $ $t $: )-'+%) % $	
 ooc" 
	8 (,%)	DD $D ooc"	D
 
D2 QUooc*9?9M	(fook: (d (
% %C %D %  ! ! ! 4&//#. 4$ 
,# ,.v~~55 .$ rM   r   )Cr  email.messager  r   rK  r   urllib.requestr  collections.abcr   http.cookiejarr   r   r   r   r   r	   r
   	_decodersr   r   r   r   r   r   r   r   _exceptionsr   r   r   r   r   r   r   
_multipartr   _status_codesr   _typesr   r   r   r   r    r!   r"   r#   r$   r%   r&   _urlsr'   _utilsr(   r)   r*   r+   r,   r-   r.   MutableMappingr   r0   r   r   r   r   rM   r>   <module>r     s         # , S S	 	 	   A        x:f##CH- x:vG) G)Tq+ q+hHf##CH- HrM   