
                  	          S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&  SSK'J(r(  SSK)J*r*  SSK+J,r,J-r-J.r.J/r/  Sr0\Rb                  " 5       r2SSS.r3SRi                  \Rj                  " S\" SS9S   5      5      r6\Rn                  S:X  a  S r8S rS r9S r:SIS jr;S r<S r=\R|                  S  5       r?S! r@S" rAS# rBS$ rCSIS% jrDS& rES' rFS( rGS) rHS* rIS+ rJS, rKS- rL\M" S.5      rNS/ rOS0 rPS1 rQS2 rRS3 rSS4 rT\R|                  S5 5       rUS6 rVSJS7 jrWS8 rXSKS9 jrYSLS: jrZS; r[S< r\S=R                  S>5      r^\^S?-  r_\^S@-  r`SA raSB rbSC rc\R                  " SD5      re\R                  " SE5      rfSF rgSG rhSH rig)Mz
requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
that are also useful for external consumption.
    N)OrderedDict)make_headers)	parse_url   __version__)certs)to_native_string)parse_http_list)quoteurlparsebytesstrunquote
getproxiesproxy_bypass
urlunparse
basestringinteger_typesis_py3proxy_bypass_environmentgetproxies_environmentMappingcookiejar_from_dict)CaseInsensitiveDict)
InvalidURLInvalidHeaderFileModeWarningUnrewindableBodyError)z.netrc_netrcP   i  )httphttpsz, z,\s*T)accept_encodingzaccept-encodingwin32c                 B    [         (       a  SS KnOSS Kn  UR	                  UR
                  S5      n[        UR                  US5      S   5      nUR                  US5      S   nU(       a  U(       d  gUR                  S5      nU Hs  nUS:X  a  SU ;  a    g	UR                  SS
5      nUR                  SS5      nUR                  SS5      n[        R                  " XP[        R                  5      (       d  Ms    g	   g! [         a     gf = f! [         a     gf = f)Nr   Fz;Software\Microsoft\Windows\CurrentVersion\Internet SettingsProxyEnableProxyOverride;z<local>.Tz\.*z.*?)r   winreg_winregImportErrorOpenKeyHKEY_CURRENT_USERintQueryValueExOSErrorsplitreplacerematchI)hostr.   internetSettingsproxyEnableproxyOverridetests         )platform/bq/third_party/requests/utils.pyproxy_bypass_registryrA   8   s)   	v(
	%~~f.F.FN P f112B.;==>@ AK #//0@0?AABDM -
 &++C0!Dy d?<<U+D<<U+D<<T*DxxBDD)) " ?  		  		s(   D D AD 
DD
DDc                 L    [        5       (       a  [        U 5      $ [        U 5      $ )zReturn True, if the host should be bypassed.

Checks proxy settings gathered from the environment, if specified,
or the registry.
)r   r   rA   )r;   s    r@   r   r   _   s#     "##+D11(..    c                 H    [        U S5      (       a  U R                  5       n U $ )z/Returns an internal sequence dictionary update.items)hasattrrE   )ds    r@   dict_to_sequencerH   k   s!     q'GGIHrC   c                    S nSn[        U S5      (       a  [        U 5      nO[        U S5      (       a  U R                  nOm[        U S5      (       a\   U R                  5       n[        R                  " U5      R
                  nSU R                  ;  a  [        R                  " S[        5        [        U S5      (       ab   U R                  5       n[        U S5      (       a@  Uc=   U R                  SS	5        U R                  5       nU R                  U=(       d    S5        Uc  Sn[#        SX-
  5      $ ! [        R                  [        4 a     Nf = f! [        [         4 a    Sn NGf = f! [        [         4 a    Ub  Un Nbf = f)
Nr   __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   )rF   rK   rL   osfstatst_sizemodewarningswarnr   ioUnsupportedOperationAttributeErrorrN   rO   r5   IOErrormax)ototal_lengthcurrent_positionrL   s       r@   	super_lenr_   t   ss   Lq)1v	E		uu	H			XXZF 88F+33L !&& . $ q&	% vvx q&!!l&:	%FF1aL#$668L FF+0q1 q,122a ''8 	 		T  ) %#$L%% ! 	0
 '#/ 	0s6   D3 ?E+ $<E 3EEE('E(+FFc                    [         R                  R                  S5      nUb  U4nOS [         5       n SSKJnJn  SnU HK  n [         R                  R                  U5      n[         R                  R                  U5      (       d  MI  Un  O   Uc  g[        U 5      n	Sn
[        U [        5      (       a  U
R                  S5      n
U	R                  R                  U
5      S   n U" U5      R!                  U5      nU(       a  US   (       a  SOSnX   US	   4$ g! [         a       gf = f! U["        4 a    U(       a  e  gf = f! [$        [&        4 a     gf = f)
z;Returns the Requests tuple auth for a given url from netrc.NETRCNc              3   D   #    U  H  nS R                  U5      v   M     g7f)z~/{}N)format).0fs     r@   	<genexpr>!get_netrc_auth.<locals>.<genexpr>   s     A[6==++[s    r   )netrcNetrcParseError   :asciir   rP   )rQ   environgetNETRC_FILESrh   ri   path
expanduserKeyErrorexistsr   
isinstancer   decodenetlocr6   authenticatorsrZ   r0   rY   )urlraise_errors
netrc_filenetrc_locationsrh   ri   
netrc_pathre   locrisplitstrr;   r!   login_is                 r@   get_netrc_authr      sW    (J%-A[A-0
 Agg((+ ww~~c"" 
 ! c] c3w/Hyyx(+
	:&55d;F &q	1q33 3   	:  ) 	  	 ( s`   E D$"E 
	E AE &4D- 
D*&E )D**E -EE EE EEc                     [        U SS5      nU(       aI  [        U[        5      (       a3  US   S:w  a)  US   S:w  a  [        R                  R                  U5      $ gggg)z0Tries to guess the filename of the given object.nameNr   <>)getattrrs   r   rQ   ro   basename)objr   s     r@   guess_filenamer      sY    3%DD*--$q'S.HOww%%  3A-rC   c                    [         R                  R                  U 5      (       a  U $ [         R                  R                  U 5      u  pU(       a  [         R                  R                  U5      (       dh  [         R                  R                  U5      u  pU(       d  O?SR	                  X2/5      nU(       a&  [         R                  R                  U5      (       d  Mh  [
        R                  " U5      (       d  U $ [
        R                  " U5      nX$R                  5       ;  a  U $ [        R                  " 5       n[         R                  R	                  XRR                  S5      S   5      n[         R                  R                  U5      (       d6  [        U5       nUR                  UR                  U5      5        SSS5        U$ U$ ! , (       d  f       U$ = f)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   N)rQ   ro   rr   r6   joinzipfile
is_zipfileZipFilenamelisttempfile
gettempdiratomic_openwriteread)ro   archivememberprefixzip_filetmpextracted_pathfile_handlers           r@   extract_zipped_pathsr      sH   
 
ww~~d ggmmD)OG
"''..11''--0 6*+ "''..11 g&&w'H&&(( 


CWW\\#||C'8'<=N77>>.))(Lx}}V45 )> )(s   !G
Gc              #     #    [         R                  S   S:X  a  [        R                  O[        R                  n[
        R                  " [        R                  R                  U 5      S9u  p# [        R                  " US5       nUv   SSS5        U" X05        g! , (       d  f       N= f! [         a    [        R                  " U5        e f = f7f)z-Write a file to the disk in an atomic fashionr   rP   )dirwbN)sysversion_inforQ   renamer7   r   mkstempro   dirnamefdopenBaseExceptionremove)filenamereplacertmp_descriptortmp_nametmp_handlers        r@   r   r     s       ,,Q/14ryy"**H'//BGGOOH4MNNYY~t, -$ -,  
		(s6   A+C.B, B
B, C
B)%B, ,"CCc                     U c  g[        U [        [        [        [        45      (       a  [        S5      e[        U 5      $ )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)rs   r   r   boolr3   
ValueErrorr   values    r@   from_key_val_listr   (  s9    $ }%#udC011FGGurC   c                     U c  g[        U [        [        [        [        45      (       a  [        S5      e[        U [        5      (       a  U R                  5       n [        U 5      $ )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   )	rs   r   r   r   r3   r   r   rE   listr   s    r@   to_key_val_listr   C  sP    " }%#udC011FGG%!!;rC   c                     / n[        U 5       H8  nUSS USS s=:X  a  S:X  a  O  O[        USS 5      nUR                  U5        M:     U$ )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      r@   parse_list_headerr   a  sT    . F"5)8tBCy'C''Qr
3Dd * MrC   c                     0 n[        U 5       HK  nSU;  a  SX'   M  UR                  SS5      u  p0U SS U SS s=:X  a  S:X  a  O  O[        U SS 5      n XU'   MM     U$ )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   r6   r   )r   r   r   r   s       r@   parse_dict_headerr     sr    , F"5)d?FLjja(!9bc
)c)(q5Et * MrC   c                     U (       aN  U S   U S   s=:X  a  S:X  a;  O  U $ U SS n U(       a	  U SS S:w  a"  U R                  SS5      R                  S	S5      $ U $ )
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   NrP   z\\\z\")r7   )r   is_filenames     r@   r   r     sd     qU2Y-#- L a eBQi61==.66ucBBLrC   c                 L    0 nU  H  nUR                   XR                  '   M     U$ )ztReturns a key/value dictionary from a CookieJar.

:param cj: CookieJar object to extract cookies from.
:rtype: dict
)r   r   )cjcookie_dictcookies      r@   dict_from_cookiejarr     s+     K#)<<KK   rC   c                     [        X5      $ )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     r@   add_dict_to_cookiejarr     s     {//rC   c                 Z   [         R                  " S[        5        [        R                  " S[        R
                  S9n[        R                  " S[        R
                  S9n[        R                  " S5      nUR                  U 5      UR                  U 5      -   UR                  U 5      -   $ )zdReturns 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=["\']*(.+?)["\'>])rU   rV   DeprecationWarningr8   compiler:   findall)content
charset_re	pragma_rexml_res       r@   get_encodings_from_contentr     s    
 MM	- 		 @MJ

IQSQUQUVIZZ?@Fw'g&'NN7#$ %rC   c                 P   U R                  S5      nUS   R                  5       USS p20 nSnU Hr  nUR                  5       nU(       d  M  USpUR                  S5      n	U	S:w  a*  USU	 R                  U5      nXiS-   S R                  U5      nXUR                  5       '   Mt     X$4$ )	zReturns content type and parameters from given header

:param header: string
:return: tuple containing content type and dictionary of
     parameters
r*   r   r   Nz"' Tr   r   )r6   stripfindlower)
headertokenscontent_typeparamsparams_dictitems_to_stripparamkeyr   index_of_equalss
             r@   _parse_content_type_headerr     s     \\#F!!9??,fQRj&KN5#jjoO"$,_-33NC12399.I',		$  $$rC   c                     U R                  S5      nU(       d  g[        U5      u  pSU;   a  US   R                  S5      $ SU;   a  gSU;   a  gg)	zqReturns encodings from given HTTP Header Dict.

:param headers: dictionary to extract encoding from.
:rtype: str
zcontent-typeNcharsetz'"textz
ISO-8859-1zapplication/jsonutf-8)rm   r   r   )headersr   r   s      r@   get_encoding_from_headersr     s^     ;;~.L5lCLFi &&u--\) *rC   c              #     #    UR                   c  U  H  nUv   M	     g[        R                  " UR                   5      " SS9nU  H!  nUR                  U5      nU(       d  M  Uv   M#     UR                  SSS9nU(       a  Uv   gg7f)zStream decodes a iterator.Nr7   errorsrC   T)final)encodingcodecsgetincrementaldecoderrt   )iteratorrr   decoderchunkrvs         r@   stream_decode_response_unicoder     s      	zzDJ **1::6iHG^^E"2H  
4	(B	 
s   AB!%Bc              #      #    SnUb  US::  a  [        U 5      nU[        U 5      :  a  XX!-    v   X!-  nU[        U 5      :  a  M  gg7f)z Iterate over slices of a string.r   N)rK   )stringslice_lengthposs      r@   iter_slicesr   /  sP     
C|q06{
F
+,, F
s   AAAc                 H   [         R                  " S[        5        / n[        U R                  5      nU(       a   [        U R                  U5      $  [        U R                  USS9$ ! [         a    UR                  U5         N3f = f! [         a    U R                  s $ f = f)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.)r7   r   )
rU   rV   r   r   r   r   r   UnicodeErrorr   	TypeError)r   tried_encodingsr   s      r@   get_unicode_from_responser  9  s     MM	- 		 O )3H	-qyy(++
199hy99  	-""8,	-  yys#   A' B 'BBB! B!zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~c                    U R                  S5      n[        S[        U5      5       Hp  nX   SS n[        U5      S:X  aN  UR                  5       (       a9   [	        [        US5      5      nU[        ;   a  XAU   SS -   X'   M\  SX   -   X'   Mg  SX   -   X'   Mr     SR                  U5      $ ! [         a    [        SU-  5      ef = f)	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   rP      z%Invalid percent-escape sequence: '%s'N )
r6   rangerK   isalnumchrr3   r   r   UNRESERVED_SETr   )uripartsihcs        r@   unquote_unreservedr  b  s     IIcNE1c%j!HQqMq6Q;199;;NAr
O N"Qx|+>UX~EH " 775>  N !H1!LMMNs   B,,Cc                 d    SnSn [        [        U 5      US9$ ! [         a    [        XS9s $ f = f)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      r@   requote_urir  z  sG     /0	5 ',3DEE 5 S44	5s    //c           
      x   [         R                  " S[        R                  " U 5      5      S   nUR	                  S5      u  p4[         R                  " S[        R                  " [        [        U5      5      5      5      S   n[         R                  " S[        R                  " U5      5      S   U-  nX%-  Xe-  :H  $ )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_atonr6   dotted_netmaskr3   )ipnetipaddrnetaddrbitsnetmasknetworks          r@   address_in_networkr"    s     ]]4!1!1"!56q9FIIcNMGmmD&"2"2>#d)3L"MNqQGmmD&"2"27";<Q?'IG'"344rC   c                 t    SSSU -
  -  S-
  -  n[         R                  " [        R                  " SU5      5      $ )zuConverts 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)r  	inet_ntoar  pack)maskr  s     r@   r  r    s7     b4i1,,DFKKd344rC   c                 f     [         R                  " U 5        g! [         R                   a     gf = f)z
:rtype: bool
FT)r  r  error)	string_ips    r@   is_ipv4_addressr+    s2    #  << s    00c                 ,   U R                  S5      S:X  aU   [        U R                  S5      S   5      nUS:  d  US:  a  g [        R
                  " U R                  S5      S   5        gg! [         a     gf = f! [        R                   a     gf = f)zJ
Very simple check of the cidr format in no_proxy variable.

:rtype: bool
r   r   Fr$  r   T)countr3   r6   r   r  r  r)  )string_networkr'  s     r@   is_valid_cidrr/    s     C A%	~++C034D !8tby	^11#6q9:
    		 || 		s#   A, (A< ,
A98A9<BBc              #   Z  #    USLnU(       a2  [         R                  R                  U 5      nU[         R                  U '    Sv   U(       a)  Wc  [         R                  U 	 gU[         R                  U '   gg! U(       a)  Wc  [         R                  U 	 f U[         R                  U '   f f = f7f)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)rQ   rl   rm   )env_namer   value_changed	old_values       r@   set_environr4    s      %MJJNN8,	$

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

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

8$	 s   >B+A6 1B+62B((B+c                 D   S nUnUc  U" S5      n[        U 5      nUR                  c  gU(       Ga	  S UR                  SS5      R                  S5       5       n[	        UR                  5      (       aK  U HD  n[        U5      (       a  [        UR                  U5      (       a    gM2  UR                  U:X  d  MD    g   O|UR                  nUR                  (       a  US	R                  UR                  5      -  nU H;  nUR                  R                  U5      (       d  UR                  U5      (       d  M;    g   [        SU5          [        UR                  5      nSSS5        W(       a  gg
! [        [        R                  4 a    S
n N/f = f! , (       d  f       N9= f)z@
Returns whether we should bypass proxies or not.

:rtype: bool
c                     [         R                  R                  U 5      =(       d-    [         R                  R                  U R                  5       5      $ N)rQ   rl   rm   upper)ks    r@   <lambda>'should_bypass_proxies.<locals>.<lambda>  s,    "**..+Hrzz~~aggi/HHrC   Nno_proxyTc              3   6   #    U  H  o(       d  M  Uv   M     g 7fr7   )rd   r;   s     r@   rf   (should_bypass_proxies.<locals>.<genexpr>  s      
ATTDDAs   
	 r  ,z:{}F)r   hostnamer7   r6   r+  r/  r"  portrc   endswithr4  r   r   r  gaierror)	rw   r<  	get_proxyno_proxy_argparsedproxy_iphost_with_portr;   bypasss	            r@   should_bypass_proxiesrL    sf    II LZ(c]F
%--c26<<SA
 6??++$ **)&//8DD# E__0   % $__N{{%,,v{{";; ??++D11^5L5LT5R5R  	 ! 
Z	.	!&//2F 
/  6??+ 	F		 
/	.s*   F	E//FFFF
Fc                 6    [        XS9(       a  0 $ [        5       $ )z5
Return a dict of environment proxies.

:rtype: dict
r<  )rL  r   )rw   r<  s     r@   get_environ_proxiesrO     s     S4	|rC   c                 >   U=(       d    0 n[        U 5      nUR                  c+  UR                  UR                  UR                  S5      5      $ UR                  S-   UR                  -   UR                  SUR                  -   S/nSnU H  nXQ;   d  M
  X   n  U$    U$ )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   rB  rm   scheme)rw   proxiesurlparts
proxy_keysproxy	proxy_keys         r@   select_proxyrX  ,  s     mG}H {{8??GKK,>?? 	%("3"338$$$	J E	&EL  
 LrC   c                 D   Ub  UO0 nU R                   n[        U5      R                  nUR                  S5      nUR	                  5       nU(       aO  [        X5S9(       dA  [        X5S9nUR                  XGR                  S5      5      nU(       a  UR                  XH5        U$ )a  This method takes proxy information from a request and configuration
input to resolve a mapping of target proxies. This will consider settings
such a 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
r<  rN  rQ  )rw   r   rR  rm   copyrL  rO  
setdefault)	requestrS  	trust_envrw   rR  r<  new_proxiesenviron_proxiesrV  s	            r@   resolve_proxiesr`  F  s     !,g"G
++Cc]!!F{{:&H,,.K.sF-cE##F,?,?,FG""61rC   c                     U < S[         < 3$ )zC
Return a string representing the default user agent.

:rtype: str
r   r   )r   s    r@   default_user_agentrb  a  s     K((rC   c                  :    [        [        5       [        SSS.5      $ )z1
:rtype: requests.structures.CaseInsensitiveDict
z*/*z
keep-alive)z
User-AgentzAccept-EncodingAccept
Connection)r   rb  DEFAULT_ACCEPT_ENCODINGr>  rC   r@   default_headersrg  j  s%     (*2"	   rC   c                    / nSnU R                  U5      n U (       d  U$ [        R                  " SU 5       H  n UR                  SS5      u  pESUR                  S5      0nUR                  S5       H9  n UR                  S5      u  pU R                  U5      XhR                  U5      '   M;     UR	                  U5        M     U$ ! [         a    USpT Nf = f! [         a       M8  f = f)	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, *<r*   r   r  rw   z<> '"r   )r   r8   r6   r   r   )	r   linksreplace_charsvalrw   r   linkr   r   s	            r@   parse_header_linksrm  v  s     EMKK&Exx&	"))C+KC syy*+\\#&E"[[-
 .3[[-GD=)* ' 	T! '$ L  	"r	"  s#   C6CCC
C('C( rk   rP      c                    U SS nU[         R                  [         R                  4;   a  gUSS [         R                  :X  a  gUSS [         R                  [         R
                  4;   a  gUR                  [        5      nUS:X  a  g	US:X  a"  USSS2   [        :X  a  g
USSS2   [        :X  a  gUS:X  a  USS [        :X  a  gUSS [        :X  a  gg)z
:rtype: str
N   zutf-32ro  z	utf-8-sigrP   zutf-16r   r   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_BEr-  _null_null2_null3)datasample	nullcounts      r@   guess_json_utfr}    s     "1XF&%%v':':;;bqzV__$bqzf))6+>+>??U#IA~A~#A#;& !$Q$<6!A~"1:!":rC   c                     [        U 5      nUu  p4pVpxn	UR                  n
U
(       d  XzpzU(       a  SR                  XJ/5      n
Uc  UnUc  Sn[        X:USX45      $ )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   ru   r   r   )rw   
new_schemerH  rR  authr;   rC  ro   queryfragmentru   s              r@   prepend_scheme_if_neededr    sk     s^F6<3F$d8 ]]F 4.)~|vtRABBrC   c                     [        U 5      n [        UR                  5      [        UR                  5      4nU$ ! [        [
        4 a    Sn U$ f = f)zoGiven a url with authentication components, extract them into a tuple of
username,password.

:rtype: (str,str)
)r  r  )r   r   usernamepasswordrY   r   )rw   rH  r  s      r@   get_auth_from_urlr    sU     c]F('&//*BC K I& Ks   *9 AAs   ^\S[^\r\n]*$|^$z^\S[^\r\n]*$|^$c                     U u  p[        U[        5      (       a  [        nO[        n UR	                  U5      (       d  [        SU-  5      eg! [         a!    [        SU< SU< S[        U5      < 35      ef = f)zVerifies that header value is a string which doesn't contain
leading whitespace or return characters. This prevents unintended
header injection.

:param header: tuple, in the format (name, value).
z7Invalid return character or leading space in header: %szValue for header {z: z$} must be of type str or bytes, not N)rs   r   _CLEAN_HEADER_REGEX_BYTE_CLEAN_HEADER_REGEX_STRr9   r   r   type)r   r   r   pats       r@   check_header_validityr    s     KD%&%Jyy Y\` `aa   J/3UDKI J 	JJs   $A +A8c                 z    [        U 5      u  pp4pVU(       d  X2p2UR                  SS5      S   n[        XX4US45      $ )zK
Given a url remove the fragment and the authentication part.

:rtype: str
r  r   r   r  )r   rsplitr   )rw   rR  ru   ro   r   r  r  s          r@   urldefragauthr    sG     5=SM1FD% ]]3"2&FvtUB?@@rC   c                     [        U R                  SS5      nUb3  [        U R                  [        5      (       a   U" U R                  5        g[        S5      e! [
        [        4 a    [        S5      ef = f)z^Move file pointer back to its recorded starting position
so it can be read again on redirect.
rO   Nz;An error occurred when rewinding request body for redirect.z+Unable to rewind request body for redirect.)r   bodyrs   _body_positionr   rZ   r5   r    )prepared_request	body_seeks     r@   rewind_bodyr    s|     (--vt<I,<,K,K]![![	>&556
 $$QRR	 ! 	>' )= > >	>s   A A5)Fr7  )T)zpython-requests)j__doc__r   
contextlibrW   rQ   r8   r  r  r   r   rU   r   collectionsr   urllib3.utilr   r   r   r  r	   _internal_utilsr
   compatr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   cookiesr   
structuresr   
exceptionsr   r   r   r    rn   whereDEFAULT_CA_BUNDLE_PATHDEFAULT_PORTSr   r6   rf  platformrA   rH   r_   r   r   r   contextmanagerr   r   r   r   r   r   r   r   r   r   r   r   r   r  	frozensetr	  r  r  r"  r  r+  r/  r4  rL  rO  rX  r`  rb  rg  rm  encoderw  rx  ry  r}  r  r  r   r  r  r  r  r  r>  rC   r@   <module>r     s     	 	 	   
    # % " $  - 9? ? ? ? ) +G G # c* ))HHWl489JKL 
 <<7%N	/=3@6r&"J 
 
6<@F20%(%22$!J MO05,550 1 1*:z	46)	"L 	g		@C:" ::&;< **%78 J*A"SrC   