
    1j                    B   U d Z 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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mZmZ ddl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$ ddl%m&Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl(m6Z7 ddl8m9Z9 ddl:m;Z;m<Z<m=Z=m>Z> ddl?m@Z@ erddlAmBZB ddlmCZC ddlm%ZD ddlEmFZFmGZGmHZH dZIdeJd<    ej                         ZLdeJd<   dddZMdeJd<    ed      ZN ed       ZOd!j                   ej                  d" ed#$      d%               ZRdeJd&<   e
j                  d'k(  rd\d(ZTd\d)Z/	 	 	 	 d]d*ZUd^d+ZV	 d_	 	 	 	 	 d`d,ZWdad-ZXdbd.ZYej                  dcd/       Z[	 	 	 	 ddd0Z\eded1       Z]e	 	 	 	 dfd2       Z]	 	 	 	 dgd3Z]dhd4Z^did5Z_d_djd6Z`dkd7Zadld8Zbdmd9Zcdnd:Zddod;Ze	 	 	 	 	 	 dpd<Zfe	 	 	 	 	 	 dqd=       Zge	 	 	 	 	 	 drd>       Zg	 	 	 	 	 	 dsd?Zgdtd@Zh eidA      ZjdeJdB<   dudCZkdudDZldvdEZmdwdFZndxdGZodydHZpej                  dzdI       Zqd{dJZrd|d}dKZsd~dLZt	 d	 	 	 	 	 	 	 ddMZudddNZvddOZwddPZxdQj                  dR      ZzezdSz  Z{ezdTz  Z|ddUZ}ddVZ~ddWZddXZ	 	 	 	 	 	 	 	 ddYZddZZdd[Zy)z
requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
that are also useful for external consumption.
    )annotationsN)OrderedDict)	GeneratorIterable)TYPE_CHECKINGAnyFinalTypeVarcastoverload)make_headers	parse_url   )certs__version__)_HEADER_VALIDATORS_BYTE_HEADER_VALIDATORS_STRHEADER_VALIDATORSto_native_string)SupportsItems)Mappingbytes
getproxiesgetproxies_environmentinteger_typesis_urllib3_1proxy_bypassproxy_bypass_environmentquotestrunquoteurlparse
urlunparse)parse_http_listcookiejar_from_dict)FileModeWarningInvalidHeader
InvalidURLUnrewindableBodyError)CaseInsensitiveDict)	CookieJar)BufferedWriter)_types)PreparedRequestRequestResponse)z.netrc_netrcr	   NETRC_FILESr!   DEFAULT_CA_BUNDLE_PATHP   i  )httphttpsDEFAULT_PORTS_KT_VTz, z,\s*T)accept_encodingzaccept-encodingDEFAULT_ACCEPT_ENCODINGwin32c                   	 dd l }	 |j                  |j                  d      }t	        |j                  |d      d         }|j                  |d      d   }|r|sy|j                  d      }t        d |      }|D ]j  }|dk(  rd| vr y	|j                  dd
      }|j                  dd      }|j                  dd      }t        j                  || t        j                        sj y	 y# t        $ r Y yw xY w# t        t        f$ r Y yw xY w)Nr   Fz;Software\Microsoft\Windows\CurrentVersion\Internet SettingsProxyEnableProxyOverride;z<local>.Tz\.*z.*?)winregImportErrorOpenKeyHKEY_CURRENT_USERintQueryValueExOSError
ValueErrorsplitfilterreplacerematchI)hostrF   internetSettingsproxyEnableproxyOverridetests         B/home/qreelify/venv/lib/python3.12/site-packages/requests/utils.pyproxy_bypass_registryrZ   c   s%   	
	%~~((N 
 f112BMRSTUVK"//0@/RSTUM -
 &++C0t]3! 	Dy d?<<U+D<<U+D<<T*DxxdBDD)	 C  		 $ 		s#   C( AC7 (	C43C47D	D	c                B    t               rt        |       S t        |       S )zReturn True, if the host should be bypassed.

        Checks proxy settings gathered from the environment, if specified,
        or the registry.
        )r   r   rZ   )rT   s    rY   r   r      s      "#+D11(..    c                F    t        | t              r| j                         S | S )z/Returns an internal sequence dictionary update.)
isinstance_SupportsItemsitems)ds    rY   dict_to_sequencerb      s    
 !^$wwyHr\   c                   d }d}t         s!t        | t              r| j                  d      } t	        | d      rt        |       }n~t	        | d      r| j
                  }net	        | d      rY	 | j                         }t        j                  |      j                  }d| j                  vrt        j                  dt               	 t	        | d      rW	 | j#                         }t	        | d	      r:|8	 | j%                  dd
       | j#                         }| j%                  |xs d       |d}t)        d||z
        S # t        j                  t         f$ r Y w xY w# t&        $ r d}Y ?w xY w# t&        $ r ||}Y Rw xY w)Nr   utf-8__len__lenfilenoba%  Requests has determined the content-length for this request using the binary size of the file: however, the file has been opened in text mode (i.e. without the 'b' flag in the mode). This may lead to an incorrect content-length. In Requests 3.0, support will be removed for files in text mode.tellseek   )r   r^   r!   encodehasattrrf   rg   osfstatst_sizemodewarningswarnr(   ioUnsupportedOperationAttributeErrorri   rj   rL   max)ototal_lengthcurrent_positionrg   s       rY   	super_lenr{      sy   LJq#. HHWq)1v	E	uu	H		XXZF 88F+33L !&& 2 $
 q&	% vvx q&!l&:	%FF1aL#$668L FF+0q1 q,!1122e ''8 	 		X  %#$L%%  	0
 '#/ 	0s6   *D8 E( .7E 8EEE%$E%(E87E8c                `   t        | t              r| j                  d      } t        j                  j                  d      }||f}nd t        D        }	 ddlm}m} d}|D ]D  }t        j                  j                  |      }t        j                  j                  |      sB|} n |yt        |       }	|	j                  }
|
y	  ||      j                  |
      }|r't        |      r|d   rdnd}||   xs d|d	   xs dfS yy# |t         f$ r |r Y yw xY w# t"        t$        f$ r Y yw xY w)
z;Returns the Requests tuple auth for a given url from netrc.rd   NETRCNc              3  &   K   | ]	  }d |   yw)z~/N ).0fs     rY   	<genexpr>z!get_netrc_auth.<locals>.<genexpr>   s     9Rs89s   r   )NetrcParseErrornetrcr    rk   )r^   r   decodern   environgetr4   r   r   path
expanduserexistsr#   hostnameauthenticatorsanyrL   rG   rv   )urlraise_errors
netrc_filenetrc_locationsr   r   
netrc_pathr   locrirT   r3   login_is                rY   get_netrc_authr      s@   
 #ujj!(J%-9[9#0
  	A''$$Q'Cww~~c" 
		 c]{{<
	:&55d;F#f+%ay!aw-2vayB?? &v  ) 	  	 ( s=   AD #D +D >D DD DD D-,D-c                    t        | dd      }|rHt        |t        t        f      r1|d   dk7  r(|d   dk7  rt        j
                  j                  |      S yyyy)z0Tries to guess the filename of the given object.nameNr   <>)getattrr^   r!   r   rn   r   basename)objr   s     rY   guess_filenamer     sX    3%D
4#u.47c>d2hRUoww%% GV>.tr\   c                F   t         j                  j                  |       r| S t         j                  j                  |       \  }}|ryt         j                  j                  |      sZt         j                  j                  |      \  }}|sn5dj	                  ||g      }|r t         j                  j                  |      sZt        j                  |      s| S t        j                  |      }||j                         vr| S t         j                  j                  |j                  d      d         d   }t        j                  |      \  }}	 t        j                  ||j                  |             t        j                  |       |S # t        j                  |       w xY w)zReplace nonexistent paths that look like they refer to a member of a zip
    archive with the location of an extracted copy of the target, or else
    just return the provided path unchanged.
    /r   )suffix)rn   r   r   rN   joinzipfile
is_zipfileZipFilenamelistsplitexttempfilemkstempwritereadclose)r   archivememberprefixzip_filer   fdextracted_paths           rY   extract_zipped_pathsr   "  s;   
 
ww~~d ggmmD)OGV
"''..1''--0 66*+ "''..1 g&w'HX&&(( WWfll3/34R8F!))8B
X]]6*+
 	s   %F	 	F c              #  J  K   t        j                  t        j                  j	                  |             \  }}	 t        j
                  |d      5 }| ddd       t        j                  ||        y# 1 sw Y    xY w# t        $ r t        j                  |        w xY ww)z-Write a file to the disk in an atomic fashion)dirwbN)	r   r   rn   r   dirnamefdopenrP   BaseExceptionremove)filenametmp_descriptortmp_nametmp_handlers       rY   atomic_openr   H  s       (//BGGOOH4MNNHYY~t, 		


8X&	 	  
		(s4   7B#B  A4B  3B#4A=9B    B  B#c                t    | yt        | t        t        t        t        f      rt        d      t        |       S )a  Take an object and test to see if it can be represented as a
    dictionary. Unless it can not be represented as such, return an
    OrderedDict, e.g.,

    ::

        >>> from_key_val_list([('key', 'val')])
        OrderedDict([('key', 'val')])
        >>> from_key_val_list('string')
        Traceback (most recent call last):
        ...
        ValueError: cannot encode objects that are not 2-tuples
        >>> from_key_val_list({'key': 'val'})
        OrderedDict([('key', 'val')])

    :rtype: OrderedDict
    N+cannot encode objects that are not 2-tuples)r^   r!   r   boolrJ   rM   r   values    rY   from_key_val_listr   U  s6    ( }%#udC01FGGur\   c                     y Nr   r   s    rY   to_key_val_listr   r  s    *-r\   c                     y r   r   r   s    rY   r   r   t  s      r\   c                    | yt        | t        t        t        t        f      rt        d      t        | t              rt        | j                               S t        |       S )a  Take an object and test to see if it can be represented as a
    dictionary. If it can be, return a list of tuples, e.g.,

    ::

        >>> to_key_val_list([('key', 'val')])
        [('key', 'val')]
        >>> to_key_val_list({'key': 'val'})
        [('key', 'val')]
        >>> to_key_val_list('string')
        Traceback (most recent call last):
        ...
        ValueError: cannot encode objects that are not 2-tuples

    :rtype: list
    Nr   )	r^   r!   r   r   rJ   rM   r_   listr`   r   s    rY   r   r   x  sP    & }%#udC01FGG%(EKKM"";r\   c                    g }t        |       D ]5  }|dd |dd cxk(  rdk(  rn nt        |dd       }|j                  |       7 |S )a  Parse lists as described by RFC 2068 Section 2.

    In particular, parse comma-separated lists where the elements of
    the list may include quoted-strings.  A quoted-string could
    contain a comma.  A non-quoted string could have quotes in the
    middle.  Quotes are removed automatically after parsing.

    It basically works like :func:`parse_set_header` just that items
    may appear multiple times and case sensitivity is preserved.

    The return value is a standard :class:`list`:

    >>> parse_list_header('token, "quoted value"')
    ['token', 'quoted value']

    To create a header from the :class:`list` again, use the
    :func:`dump_header` function.

    :param value: a string with a list header.
    :return: :class:`list`
    :rtype: list
    Nr   r   ")_parse_list_headerunquote_header_valueappend)r   resultitems      rY   parse_list_headerr     sY    . F"5) 8tBCy'C''Qr
3Dd Mr\   c                    i }t        |       D ]H  }d|vrd||<   |j                  dd      \  }} | dd | dd cxk(  rdk(  rn nt        | dd       } | ||<   J |S )a^  Parse lists of key, value pairs as described by RFC 2068 Section 2 and
    convert them into a python dict:

    >>> d = parse_dict_header('foo="is a fish", bar="as well"')
    >>> type(d) is dict
    True
    >>> sorted(d.items())
    [('bar', 'as well'), ('foo', 'is a fish')]

    If there is no value for a key it will be `None`:

    >>> parse_dict_header('key_without_value')
    {'key_without_value': None}

    To create a header from the :class:`dict` again, use the
    :func:`dump_header` function.

    :param value: a string with a dict header.
    :return: :class:`dict`
    :rtype: dict
    =Nr   r   r   )r   rN   r   )r   r   r   r   s       rY   parse_dict_headerr     s}    , %'F"5) d?F4Ljja(e!9bc
)c)(q5Et Mr\   c                    | rF| d   | d   cxk(  rdk(  r5n | S | dd } |r| dd dk7  r"| j                  dd      j                  d	d      S | S )
zUnquotes a header value.  (Reversal of :func:`quote_header_value`).
    This does not use the real unquoting but what browsers are actually
    using for quoting.

    :param value: the header value to unquote.
    :rtype: str
    r   r   r   r   Nrk   z\\\z\")rP   )r   is_filenames     rY   r   r     sd     qU2Y-#- L a eBQi61==.66ucBBLr\   c                X    | D ci c]  }|j                   |j                   }}|S c c}w )zReturns a key/value dictionary from a CookieJar.

    :param cj: CookieJar object to extract cookies from.
    :rtype: dict
    )r   r   )cjcookiecookie_dicts      rY   dict_from_cookiejarr     s/     <>>6;;,>K> ?s   'c                    t        ||       S )zReturns a CookieJar from a key/value dictionary.

    :param cj: CookieJar to insert cookies into.
    :param cookie_dict: Dict of key/values to insert into CookieJar.
    :rtype: CookieJar
    r&   )r   r   s     rY   add_dict_to_cookiejarr     s     {B//r\   c                ^   t        j                  dt               t        j                  dt        j
                        }t        j                  dt        j
                        }t        j                  d      }|j                  |       |j                  |       z   |j                  |       z   S )zlReturns encodings from given content string.

    :param content: bytestring to extract encodings from.
    zIn requests 3.0, get_encodings_from_content will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)z!<meta.*?charset=["\']*(.+?)["\'>])flagsz+<meta.*?content=["\']*;?charset=(.+?)["\'>]z$^<\?xml.*?encoding=["\']*(.+?)["\'>])rr   rs   DeprecationWarningrQ   compilerS   findall)content
charset_re	pragma_rexml_res       rY   get_encodings_from_contentr   
  s    
 MM1 	 @MJ

IQSQUQUVIZZ?@F 	7#


G
$	%
..
!	"r\   c                B   | j                  d      }|d   j                         |dd }}i }d}|D ]j  }|j                         }|s|j                  d      x}dk7  s-|d| j                  |      }||dz   d j                  |      }	|	||j                         <   l ||fS )zReturns content type and parameters from given header.

    :param header: string
    :return: tuple containing content type and dictionary of
         parameters.
    rB   r   r   Nz"' r   r   )rN   stripfindlower)
headertokenscontent_typeparamsparams_dictstrip_charsparamidxkeyr   s
             rY   _parse_content_type_headerr   #  s     \\#F!!9??,fQRj&L)+KK -UZZ_,c3+##K0C#')$**;7E',K		$- $$r\   c                    | j                  d      }|syt        |      \  }}d|v r|d   j                  d      S d|v ryd|v ryy)	z}Returns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    :rtype: str
    zcontent-typeNcharsetz'"textz
ISO-8859-1zapplication/jsonrd   )r   r   r   )headersr   r   s      rY   get_encoding_from_headersr   9  s`     ;;~.L5lCL&Fi &&u--\) *r\   c              #     K   |j                   | E d{    y t        j                  |j                         d      }| D ]  }|j                  |      }|s|  |j                  dd      }|r| yy7 ew)zStream decodes an iterator.NrP   errorsr\   T)final)encodingcodecsgetincrementaldecoderr   )iteratorrdecoderchunkrvs        rY   stream_decode_response_unicoder  R  s     
 	zz6f**1::6iHG ^^E"H 
4	(B	 
 	s   A<A:AA<"A<c                     y r   r   stringslice_lengths     rY   iter_slicesr  e  s     $'r\   c                     y r   r   r  s     rY   r  r  i  s     "%r\   c              #     K   d}||dk  rt        |       }|t        |       k  r| |||z     ||z  }|t        |       k  ryyw)z Iterate over slices of a string.r   N)rf   )r  r  poss      rY   r  r  m  sY      C|q06{
F
S3-..| F
s   A AAc                `   t        j                  dt               | j                  yg }t	        | j
                        }|r	 t        | j                  |      S 	 t        | j                  |xs dd      S # t        $ r |j                  |       Y 9w xY w# t        $ r | j                  cY S w xY w)zReturns the requested content back in unicode.

    :param r: Response object to get unicode content from.

    Tried:

    1. charset from content-type
    2. fall back and replace all unicode characters

    :rtype: str
    zIn requests 3.0, get_unicode_from_response will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)Nrd   rP   r  )
rr   rs   r   r   r   r   r!   UnicodeErrorr   	TypeError)r  tried_encodingsr  s      rY   get_unicode_from_responser  y  s     MM1 	 	yy!#O )3H	-qyy(++
199h1')DD  	-""8,	-  yys$   A5 B 5BBB-,B-zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~UNRESERVED_SETc                   | j                  d      }t        dt        |            D ]l  }||   dd }t        |      dk(  rI|j                         r9	 t	        t        |d            }|t        v r|||   dd z   ||<   Vd||    ||<   bd||    ||<   n d	j                  |      S # t        $ r t        d| d      w xY w)
zUn-escape any percent-escape sequences in a URI that are unreserved
    characters. This leaves all reserved, illegal and non-ASCII bytes encoded.

    :rtype: str
    %r   r   rk      z"Invalid percent-escape sequence: ''Nr   )
rN   rangerf   isalnumchrrJ   rM   r*   r  r   )uripartsihcs        rY   unquote_unreservedr'    s     IIcNE1c%j! &!HQqMq6Q;199;LAr
O N"uQx|+auQxj>a58*~E!H& 775>  L #EaS!JKKLs   B''C c                p    d}d}	 t        t        |       |      S # t        $ r t        | |      cY S w xY w)zRe-quote the given URI.

    This function passes the given URI through an unquote/quote cycle to
    ensure that it is fully and consistently quoted.

    :rtype: str
    z!#$%&'()*+,/:;=?@[]~z!#$&'()*+,/:;=?@[]~)safe)r    r'  r*   )r"  safe_with_percentsafe_without_percents      rY   requote_urir,    sJ     /0	5 ',3DEE 5 S344	5s    55c           
     r   t        j                  dt        j                  |             d   }|j	                  d      \  }}t        j                  dt        j                  t        t        |                        d   }t        j                  dt        j                  |            d   |z  }||z  ||z  k(  S )zThis function allows you to check if an IP belongs to a network subnet

    Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
             returns False if ip = 192.168.1.1 and net = 192.168.100.0/24

    :rtype: bool
    z=Lr   r   )structunpacksocket	inet_atonrN   dotted_netmaskrJ   )ipnetipaddrnetaddrbitsnetmasknetworks          rY   address_in_networkr:    s     ]]4!1!1"!56q9FIIcNMGTmmD&"2"2>#d)3L"MNqQGmmD&"2"27";<Q?'IGW'G"344r\   c                p    ddd| z
  z  dz
  z  }t        j                  t        j                  d|            S )zConverts mask from /xx format to xxx.xxx.xxx.xxx

    Example: if mask is 24 function returns 255.255.255.0

    :rtype: str
    l    r       z>I)r0  	inet_ntoar.  pack)maskr7  s     rY   r2  r2    s7     b4i1,,DFKKd344r\   c                N    	 t        j                  |        y# t        $ r Y yw xY w)z
    :rtype: bool
    FT)r0  r1  rL   )	string_ips    rY   is_ipv4_addressrB    s.    #   s    	$$c                   | j                  d      dk(  rR	 t        | j                  d      d         }|dk  s|dkD  ry	 t	        j
                  | j                  d      d          yy# t        $ r Y yw xY w# t        $ r Y yw xY w)zV
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    r   r   Fr<  r   T)countrJ   rN   rM   r0  r1  rL   )string_networkr?  s     rY   is_valid_cidrrF    s     C A%	~++C034D !8tby	^11#6q9:
    		  		s"   A( 'A7 (	A43A47	BBc              #  <  K   |du}d}|r2t         j                  j                  |       }|t         j                  | <   	 d |r(|t         j                  | = y|t         j                  | <   yy# |r(|t         j                  | = w |t         j                  | <   w w xY ww)zSet the environment variable 'env_name' to 'value'

    Save previous value, yield, and then restore the previous value stored in
    the environment variable 'env_name'.

    If 'value' is None, do nothingN)rn   r   r   )env_namer   value_changed	old_values       rY   set_environrK    s      %M IJJNN8,	$

81 JJx('0

8$	 = JJx('0

8$	 s   ;BA- +B-,BBc                   dd}|}| |d      }t        |       }|j                  }|y|rd |j                  dd      j                  d      D        }t	        |      r)|D ]#  }t        |      rt        ||      s y||k(  s# y nm|}|j                  r|d	|j                   z  }|D ]H  }	|	j                  d
      }	||	k(  s||	k(  r yd
|	z   }	|j                  |	      s|j                  |	      sH y t        d|      5  	 t        |      }
ddd       
ryy# t        t        j                  f$ r d}
Y )w xY w# 1 sw Y   .xY w)zL
    Returns whether we should bypass proxies or not.

    :rtype: bool
    c                    t         j                  j                  |       xs- t         j                  j                  | j                               S r   )rn   r   r   upper)r   s    rY   	get_proxyz(should_bypass_proxies.<locals>.get_proxy3  s-    zz~~c"AbjjnnSYY[&AAr\   Nno_proxyTc              3  &   K   | ]	  }|s|  y wr   r   )r   rT   s     rY   r   z(should_bypass_proxies.<locals>.<genexpr>E  s     X4SW$Xs    r   ,:rC   F)r   r!   return
str | None)r#   r   rP   rN   rB  rF  r:  portlstripendswithrK  r   r  r0  gaierror)r   rP  rO  no_proxy_argparsedr   no_proxy_hostsproxy_iphost_with_portrT   bypasss              rY   should_bypass_proxiesra  *  sn   B
 LZ(c]FH Y8+;+;C+D+J+J3+OX8$*   *)(H=#)    &N{{Afkk]"33&  {{3't#~'=Tz$$T*n.E.Ed.K  
Z	. 	!(+F  6??+ 	F	 s*   D<DD96D<8D99D<<Ec                4    t        | |      ri S t               S )zA
    Return a dict of environment proxies.

    :rtype: dict
    rP  )ra  r   )r   rP  s     rY   get_environ_proxiesrd  i  s     S84	|r\   c                .   |xs i }t        |       }|j                  +|j                  |j                  |j                  d            S |j                  dz   |j                  z   |j                  d|j                  z   dg}d}|D ]  }||v s||   } |S  |S )zSelect a proxy for the url, if applicable.

    :param url: The url being for the request
    :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
    Nallz://zall://)r#   r   r   scheme)r   proxiesurlparts
proxy_keysproxy	proxy_keys         rY   select_proxyrm  u  s     mG}H {{8??GKK,>?? 	%("3"338$$$	J E 	I&EL
 Lr\   c                T   ||ni }t        t        | j                        }t        |      j                  }|j                  d      }|j                         }|rOt        ||      sBt        ||      }|j                  ||j                  d            }|r|j                  ||       |S )a  This method takes proxy information from a request and configuration
    input to resolve a mapping of target proxies. This will consider settings
    such as NO_PROXY to strip proxy configurations.

    :param request: Request or PreparedRequest
    :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
    :param trust_env: Boolean declaring whether to trust environment configs

    :rtype: dict
    rP  rc  rf  )
r   r!   r   r#   rg  r   copyra  rd  
setdefault)	requestrh  	trust_envr   rg  rP  new_proxiesenviron_proxiesrk  s	            rY   resolve_proxiesru    s     !,g"G
sGKK
 Cc]!!F{{:&H,,.K.sXF-cHE##FO,?,?,FG""651r\   c                    |  dt          S )zO
    Return a string representing the default user agent.

    :rtype: str
    r   r   )r   s    rY   default_user_agentrw    s     V1[M""r\   c                 :    t        t               t        ddd      S )z9
    :rtype: requests.structures.CaseInsensitiveDict
    z*/*z
keep-alive)z
User-AgentzAccept-EncodingAccept
Connection)r,   rw  r=   r   r\   rY   default_headersr{    s%     ,.6&		
 r\   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)	zReturn a list of parsed link headers proxies.

    i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"

    :rtype: list
    z '"z, *<rB   r   r   r   z<> '"r   )r   rQ   rN   rM   r   )	r   linksreplace_charsvalr   r   linkr   r   s	            rY   parse_header_linksr    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 asciirk      c                   | dd }|t         j                  t         j                  fv ry|dd t         j                  k(  ry|dd t         j                  t         j
                  fv ry|j                  t              }|dk(  ry	|dk(  r |ddd   t        k(  ry
|ddd   t        k(  ry|dk(  r|dd t        k(  ry|dd t        k(  ryy)z
    :rtype: str
    N   zutf-32r  z	utf-8-sigrk   zutf-16r   rd   z	utf-16-ber   z	utf-16-lez	utf-32-bez	utf-32-le)
r  BOM_UTF32_LEBOM_UTF32_BEBOM_UTF8BOM_UTF16_LEBOM_UTF16_BErD  _null_null2_null3)datasample	nullcounts      rY   guess_json_utfr    s     "1XF&%%v':':;;bqzV__$bqzf))6+>+>??U#IA~A~#A#;& !$Q$<6!A~"1:!":r\   c                    t        |       }|\  }}}}}}}	|j                  }
|
s||
}}
|r#t        t        |
      }
dj	                  ||
g      }
||}|d}t        ||
|d||	f      S )zGiven a URL that may or may not have a scheme, prepend the given scheme.
    Does not replace a present scheme with the one provided as an argument.

    :rtype: str
    @r   )r   netlocr   r!   r   r$   )r   
new_schemer\  rg  auth_host_portr   queryfragmentr  s              rY   prepend_scheme_if_neededr    s     s^F8>5FD%eX ]]FV c6"4.)~|vvtRABBr\   c                    t        |       }	 t        |j                        t        |j                        f}|S # t        t
        f$ r d}Y |S w xY w)z{Given a url with authentication components, extract them into a tuple of
    username,password.

    :rtype: (str,str)
    )r   r   )r#   r"   usernamepasswordrv   r  )r   r\  r  s      rY   get_auth_from_urlr  .  sU     c]F('&//*BC K I& Ks   *9 AAc                B    | \  }}t        | |d       t        | |d       y)zVerifies that header parts don't contain leading whitespace
    reserved characters, or return characters.

    :param header: tuple, in the format (name, value).
    r   r   N)_validate_header_part)r   r   r   s      rY   check_header_validityr  ?  s%     KD%&$*&%+r\   c           
         t        |t              r
t        |   }n7t        |t              r
t        |   }nt        d|d|  dt        |             |j                  |      s|dk(  rdnd}t        d| d|      y )	NzHeader part (z) from z# must be of type str or bytes, not r   r   r   zTInvalid leading whitespace, reserved character(s), or return character(s) in header z: )r^   r!   r   r   r   r)   typerR   )r   header_partheader_validator_index	validatorheader_kinds        rY   r  r  J  s    
 +s#*+AB		K	'+,BC	K?'& :115k1B0CE
 	

 ??;' 6! ;f&&1]"[OE
 	
 (r\   c                ~    t        |       \  }}}}}}|s||}}|j                  dd      d   }t        |||||df      S )zW
    Given a url remove the fragment and the authentication part.

    :rtype: str
    r  r   r   r   )r#   rsplitr$   )r   rg  r  r   r   r  	_fragments          rY   urldefragauthr  b  sU     6>c]2FFD&% V]]3"2&FvvtVUB?@@r\   c                    t        | j                  dd      }|.t        | j                  t              r	  || j                         yt        d      # t
        $ r t        d      w xY w)zfMove file pointer back to its recorded starting position
    so it can be read again on redirect.
    rj   Nz;An error occurred when rewinding request body for redirect.z+Unable to rewind request body for redirect.)r   bodyr^   _body_positionr   rL   r+   )prepared_request	body_seeks     rY   rewind_bodyr  s  su     (--vt<I''"	&556 $$QRR  	'M 	s   A A()rT   r!   rU  r   )ra   z6_t.SupportsItems[Any, Any] | Iterable[tuple[Any, Any]]rU  zIterable[tuple[Any, Any]])rx   r   rU  rJ   )F)r   z
_t.UriTyper   r   rU  ztuple[str, str] | None)r   r   rU  rV  )r   r!   rU  r!   )r   r!   rU  z%Generator[BufferedWriter, None, None])r   z4Mapping[Any, Any] | Iterable[tuple[Any, Any]] | NonerU  zdict[Any, Any] | None)r   NonerU  r  )r   z6_t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]]rU  zlist[tuple[_KT, _VT]])r   z=_t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]] | NonerU  zlist[tuple[_KT, _VT]] | None)r   r!   rU  	list[str])r   r!   rU  dict[str, str | None])r   r!   r   r   rU  r!   )r   r-   rU  r  )r   r-   r   dict[str, str]rU  r-   )r   r!   rU  r  )r   r!   rU  ztuple[str, dict[str, Any]])r   CaseInsensitiveDict[str]rU  rV  )r  zIterable[bytes]r  r2   rU  z"Generator[str | bytes, None, None])r  r   r  
int | NonerU  zGenerator[bytes, None, None])r  r!   r  r  rU  zGenerator[str, None, None])r  zbytes | strr  r  rU  z"Generator[bytes | str, None, None])r  r2   rU  zstr | bytes | None)r"  r!   rU  r!   )r3  r!   r4  r!   rU  r   )r?  rJ   rU  r!   )rA  r!   rU  r   )rE  r!   rU  r   )rH  r!   r   rV  rU  zGenerator[None, None, None])r   r!   rP  rV  rU  r   r   )r   r!   rP  rV  rU  r  )r   r!   rh  dict[str, str] | NonerU  rV  )T)rq  zRequest | PreparedRequestrh  r  rr  r   rU  r  )zpython-requests)r   r!   rU  r!   )rU  r  )r   r!   rU  zlist[dict[str, str]])r  r   rU  rV  )r   r!   r  r!   rU  r!   )r   r!   rU  ztuple[str, str])r   tuple[str | bytes, str | bytes]rU  r  )r   r  r  zstr | bytesr  rJ   rU  r  )r   r!   rU  r!   )r  r0   rU  r  )__doc__
__future__r   r  
contextlibrt   rn   rQ   r0  r.  sysr   rr   r   collectionsr   collections.abcr   r   typingr   r   r	   r
   r   r   urllib3.utilr   r   r   r   r   _internal_utilsr   r   r   r   r/   r   r_   compatr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r   cookiesr'   
exceptionsr(   r)   r*   r+   
structuresr,   http.cookiejarr-   r.   _tmodelsr0   r1   r2   r4   __annotations__wherer5   r9   r:   r;   r   rN   r=   platformrZ   rb   r{   r   r   r   contextmanagerr   r   r   r   r   r   r   r   r   r   r   r  r  r  	frozensetr  r'  r,  r:  r2  rB  rF  rK  ra  rd  rm  ru  rw  r{  r  rl   r  r  r  r  r  r  r  r  r  r  r   r\   rY   <module>r     s   #   	 	 	   
    # /  1  $  4    : (  ,(!::)U ) *ekkm  + !#S1u 1enen "&BHHWl489JKL"  
 <<7$L	/=D3P +01	1#'11h&#L 	 	?: 
 - 
 -	 A   
 H!@@F202%,2"*'& 
''!+'!' 
' 
%%)%% 
%		'1	'	&T "M 
05,550 1 1,<~	: &"  	>#"L 	g		@C<",
+

  
 
	
0A"Sr\   