
    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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"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J0r0J1r1   " S S5      r2 " S S5      r3 " S S5      r4 " S S5      r5 " S S5      r6 " S S5      r7 " S S5      r8 " S S5      r9 " S S5      r: " S S5      r; " S  S!5      r<S"=r=r>\R~                  " \=S#5      r@\R~                  " \>S#5      rA\R                  R                  S$S%\@ S&\A S'3\=\>44S(S)S*S+S,S-45      S. 5       rD\R                  R                  S/S05      S1 5       rE\R                  R                  S/S25      S3 5       rF\R                  R                  S4S55      S6 5       rGS7S8S9.rHS:S;S<.rIS7S8S:S=.rJ\R                  R                  S>S?S8\H4S@S7\H4SAS7\H4SBS\H4SCS\H4S?S;\I4S@S:\I4SAS:\I4SBS:\I4SDS7\J4SES8\J4SFS:\J4SGS:\J4SHS:\J4SCS:\I445      SI 5       rK\R                  R                  SJSKSLSMSN.4SOSOS0445      SP 5       rL\R                  R                  SJSQSQ0 44SRSSSTSU044SVSSSTSU044SWSW0 44SXSYSZS[S\S].44S^SYSZS[S\S].44S_SYSZS[S\S].44S`SYSZS[S\S].44SaSS0 444	5      Sb 5       rM\R                  R                  SJ\" 5       S4\" ScSd05      SU4\" ScSW05      Se445      Sf 5       rN\R                  R                  SgSh5      Si 5       rO\R                  R                  SJSjSkSlSmSn./4SoSpSk0/4SqSpSk0/4SrSkSmSs.SpSt0/4S#/ 445      Su 5       rP\R                  R                  SJSv5      Sw 5       rQ\R                  R                  SJSx5      Sy 5       rR\R                  R                  SzS{5      S| 5       rS\R                  R                  SzS}5      S~ 5       rT\R                  R                  SzS5      S 5       rU\R                  R                  S\R                  R                  5       \" 5       45      S 5       rX\R                  R                  SJS5      S 5       rY\R                  R                  SzS5      S 5       rZ\R                  R                  \R                  S:g  SS9\R                  R                  SS5      S 5       5       r]\R                  R                  \R                  S:g  SS9S 5       r^\R                  R                  SS5      S 5       r_S r`\R                  R                  \R                  S:g  SS9S 5       rag)    N)deque)BytesIO)mock)compatunicode_is_ascii)RequestsCookieJar)CaseInsensitiveDict)_parse_content_type_headeradd_dict_to_cookiejaraddress_in_networkdotted_netmaskextract_zipped_pathsget_auth_from_urlget_encoding_from_headersget_encodings_from_contentget_environ_proxiesguess_filenameguess_json_utfis_ipv4_addressis_valid_cidriter_slicesparse_dict_headerparse_header_linksprepend_scheme_if_neededrequote_uriselect_proxyset_environshould_bypass_proxies	super_lento_key_val_listto_native_stringunquote_header_valueunquote_unreservedurldefragauth   )StringIO	cStringIOc                      \ rS rSr\R
                  R                  S\R                  S4\S4\R                  " \
S\R
                  R                  S5      S945      S 5       rS r\R
                  R                  S	\\/5      S
 5       r\R
                  R                  S	\\/5      S 5       rS r\R
                  R                  SS5      S 5       rS rS rS rS rS rS rSrg)TestSuperLen1   zstream, valueTests   TestzcStringIO is None)marksc                 ^    [        U" 5       5      S:X  d   e[        U" U5      5      S:X  d   eg)zAEnsures that we properly deal with different kinds of IO streams.r      Nr    )selfstreamvalues      8platform/gsutil/third_party/requests/tests/test_utils.pytest_io_streamsTestSuperLen.test_io_streams2   s0     "a''''1,,,    c                 r    [         R                   " 5       nUR                  S5        [        U5      S:X  d   eg)z;Ensure that we handle partially consumed file like objects.foobarbogusr   N)r'   writer    )r1   ss     r4   >test_super_len_correctly_calculates_len_of_partially_read_fileKTestSuperLen.test_super_len_correctly_calculates_len_of_partially_read_fileA   s.    	|q   r7   errorc                 L   ^  " U4S jS5      n[        U" 5       5      S:X  d   eg)z?If tell() raises errors, assume the cursor is at position zero.c                   (   > \ rS rSrS rU 4S jrSrg)XTestSuperLen.test_super_len_handles_files_raising_weird_errors_in_tell.<locals>.BoomFileK   c                     gN    r1   s    r4   __len__`TestSuperLen.test_super_len_handles_files_raising_weird_errors_in_tell.<locals>.BoomFile.__len__L   s    r7   c                    > T" 5       eNrF   r1   r>   s    r4   tell]TestSuperLen.test_super_len_handles_files_raising_weird_errors_in_tell.<locals>.BoomFile.tellO   
    gr7   rF   N)__name__
__module____qualname____firstlineno__rH   rM   __static_attributes__r>   s   r4   BoomFilerA   K   s     r7   rV   r   Nr0   )r1   r>   rV   s    ` r4   9test_super_len_handles_files_raising_weird_errors_in_tellFTestSuperLen.test_super_len_handles_files_raising_weird_errors_in_tellG   s$    	 	 $)))r7   c                 L   ^  " U4S jS5      n[        U" 5       5      S:X  d   eg)z;Ensure that if tell gives an IOError super_len doesn't failc                   (   > \ rS rSrU 4S jrS rSrg)?TestSuperLen.test_super_len_tell_ioerror.<locals>.NoLenBoomFileX   c                    > T" 5       erK   rF   rL   s    r4   rM   DTestSuperLen.test_super_len_tell_ioerror.<locals>.NoLenBoomFile.tellY   rO   r7   c                     g rK   rF   )r1   offsetwhences      r4   seekDTestSuperLen.test_super_len_tell_ioerror.<locals>.NoLenBoomFile.seek\   s    r7   rF   N)rP   rQ   rR   rS   rM   rb   rT   rU   s   r4   NoLenBoomFiler[   X   s    r7   rd   r   Nr0   )r1   r>   rd   s    ` r4   test_super_len_tell_ioerror(TestSuperLen.test_super_len_tell_ioerrorT   s$    	 	 )Q...r7   c                 &    [        S5      S:X  d   eg )Nr,   r/   r0   rG   s    r4   test_stringTestSuperLen.test_stringa   s     A%%%r7   zmode, warnings_num))rr&   )rbr   c                     UR                  S5      nUR                  S5        UR                  U5       n[        U5      S:X  d   e S S S 5        [	        U5      U:X  d   eg ! , (       d  f       N = f)Ntest.txtr,   r/   )joinr:   openr    len)r1   tmpdirmodewarnings_numrecwarnfile_objfds          r4   	test_fileTestSuperLen.test_filed   s^     ;;z*v]]4 BR=A%%% !7||+++ ! s   A!!
A/c                    UR                  S5      nUR                  S5        [        UR                  S5      5      n[        R                  " US5       nUR                  [        U5      SS9  S S S 5        [        R                  " U5       nUR                  S5      n[        U5      S:X  d   e S S S 5        g ! , (       d  f       NQ= f! , (       d  f       g = f)Nrm   r,   ztest.tarw)arcnamer/   )rn   r:   strtarfilero   addextractfiler    )r1   rq   ru   tar_objtarmembers         r4   test_tarfile_member TestSuperLen.test_tarfile_memberr   s    ;;z*vfkk*-.\\'3'3GGCM:G6 ( \\'"c__Z0FV$))) #" (' #"s   B9#C
9
C

Cc                 2    / SQn[        U5      nUS:X  d   eg )N)r&         r/   r/   r0   )r1   foolen_foos      r4   test_super_len_with__len__'TestSuperLen.test_super_len_with__len__~   s    C.!||r7   c                 D     " S S5      n[        U" 5       5      S:X  d   eg )Nc                       \ rS rSrS rSrg);TestSuperLen.test_super_len_with_no__len__.<locals>.LenFile   c                     SU l         g rD   rp   rG   s    r4   __init__DTestSuperLen.test_super_len_with_no__len__.<locals>.LenFile.__init__   s	    r7   r   N)rP   rQ   rR   rS   r   rT   rF   r7   r4   LenFiler      s    r7   r   rE   r0   )r1   r   s     r4   test_super_len_with_no__len__*TestSuperLen.test_super_len_with_no__len__   s#    	 	 #q(((r7   c                     [         R                   " S5      n[        U5      S:X  d   eUR                  S5        [        U5      S:X  d   eg )N12345rE   r   r   )r'   r    read)r1   r   s     r4   test_super_len_with_tell%TestSuperLen.test_super_len_with_tell   sA    (~"""~"""r7   c                     [        [        S5       n[        U5      nUR                  5       nS S S 5        W[	        W5      :X  d   eg ! , (       d  f       N = f)Nrk   )ro   __file__r    r   rp   )r1   flength	file_datas       r4   test_super_len_with_fileno'TestSuperLen.test_super_len_with_fileno   sD    (D!Qq\FI " Y''' "!s   A
Ac                 6    [        [        5       5      S:X  d   eg)z;Ensure that objects without any length methods default to 0r   N)r    objectrG   s    r4   test_super_len_with_no_matches+TestSuperLen.test_super_len_with_no_matches   s    "a'''r7   rF   N)rP   rQ   rR   rS   pytestmarkparametrizer'   r   paramr(   skipifr5   r<   IOErrorOSErrorrW   re   rh   rw   r   r   r   r   r   r   rT   rF   r7   r4   r*   r*   1   s   [['gLL6););<O)P	
	-	-
! [[Ww&89
* :
* [[Ww&89
/ :
/& [[	
,,
*
)#((r7   r*   c                   ~    \ rS rSr\R
                  R                  SS/S/4SS/4SS0S/4S45      S 5       rS	 rS
r	g)TestToKeyValList   value, expectedkeyval)r   r   r   NNc                 &    [        U5      U:X  d   eg rK   )r!   r1   r3   expecteds      r4   
test_validTestToKeyValList.test_valid   s     u%111r7   c                     [         R                  " [        5         [        S5        S S S 5        g ! , (       d  f       g = f)Nstring)r   raises
ValueErrorr!   rG   s    r4   test_invalidTestToKeyValList.test_invalid   s"    ]]:&H% '&&s   0
>rF   N)
rP   rQ   rR   rS   r   r   r   r   r   rT   rF   r7   r4   r   r      s[    [[/0 01U^n-.		
22&r7   r   c                   ^    \ rS rSr\R
                  R                  SS5      S 5       rS rSr	g)TestUnquoteHeaderValue   r   )r   )r,   r,   )z"Test"r,   )z"Test\\"zTest\)"\\Comp\Res"z	\Comp\Resc                 &    [        U5      U:X  d   eg rK   r#   r   s      r4   r   !TestUnquoteHeaderValue.test_valid   s     $E*h666r7   c                 (    [        SS5      S:X  d   eg )Nr   Tz
\\Comp\Resr   rG   s    r4   test_is_filename'TestUnquoteHeaderValue.test_is_filename   s    #$5t<OOOr7   rF   N)
rP   rQ   rR   rS   r   r   r   r   r   rT   rF   r7   r4   r   r      s1    [[	
	7	7Pr7   r   c                   Z   \ rS rSrSr\R                  " SSS/S9S 5       r\R                  R                  SS	5      S
 5       r
\R                  R                  SS5      S 5       r\R                  R                  SS5      S 5       r\R                  R                  SS	5      S 5       rSrg)TestGetEnvironProxies   zREnsures that IP addresses are correctly matches with ranges
in no_proxy variable.
Tno_proxyNO_PROXY)autouseparamsc                 <    UR                  UR                  S5        g )N9192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1)setenvr   )r1   requestmonkeypatchs      r4   r   TestGetEnvironProxies.no_proxy   s    MMV	
r7   url)http://192.168.0.1:5000/http://192.168.0.1/http://172.16.1.1/http://172.16.1.1:5000/'http://localhost.localdomain:5000/v1.0/c                 $    [        US S90 :X  d   eg Nr   r   r1   r   s     r4   test_bypass!TestGetEnvironProxies.test_bypass   s     #36"<<<r7   )zhttp://192.168.1.1:5000/zhttp://192.168.1.1/zhttp://www.requests.com/c                 $    [        US S90 :w  d   eg r   r   r   s     r4   test_not_bypass%TestGetEnvironProxies.test_not_bypass   s     #36"<<<r7   c                 &    Sn[        XS90 :X  d   eg )N192.168.1.1,requests.comr   r   )r1   r   r   s      r4   test_bypass_no_proxy_keyword2TestGetEnvironProxies.test_bypass_no_proxy_keyword   s     ."3:b@@@r7   c                 J    UR                  SS5        Sn[        XS90 :w  d   eg )N
http_proxyzhttp://proxy.example.com:3128/r   r   )r   r   )r1   r   r   r   s       r4    test_not_bypass_no_proxy_keyword6TestGetEnvironProxies.test_not_bypass_no_proxy_keyword   s-     	<)IJ-"3:b@@@r7   rF   N)rP   rQ   rR   rS   __doc__r   fixturer   r   r   r   r   r   r   rT   rF   r7   r4   r   r      s     ^^D*j)AB
 C

 [[	
	=	= [[	
== [[	
AA [[	
	A	Ar7   r   c                   ^    \ rS rSrS r\R                  R                  SS5      S 5       rSr	g)TestIsIPv4Address   c                 (    [        S5      (       d   eg )N8.8.8.8r   rG   s    r4   r   TestIsIPv4Address.test_valid  s    y))))r7   r3   )z	8.8.8.8.8zlocalhost.localdomainc                 (    [        U5      (       a   eg rK   r   r1   r3   s     r4   r   TestIsIPv4Address.test_invalid  s    "5)))))r7   rF   N
rP   rQ   rR   rS   r   r   r   r   r   rT   rF   r7   r4   r   r      s.    * [[W&LM* N*r7   r   c                   ^    \ rS rSrS r\R                  R                  SS5      S 5       rSr	g)TestIsValidCIDRi	  c                 (    [        S5      (       d   eg )N192.168.1.0/24r   rG   s    r4   r   TestIsValidCIDR.test_valid
  s    -....r7   r3   )r   z192.168.1.0/az192.168.1.0/128z192.168.1.0/-1z192.168.1.999/24c                 (    [        U5      (       a   eg rK   r  r   s     r4   r   TestIsValidCIDR.test_invalid  s     !'''''r7   rF   Nr   rF   r7   r4   r   r   	  s2    / [[	
	(	(r7   r   c                        \ rS rSrS rS rSrg)TestAddressInNetworki  c                 *    [        SS5      (       d   eg )Nz192.168.1.1r   r   rG   s    r4   r   TestAddressInNetwork.test_valid  s    !-1ABBBBr7   c                 *    [        SS5      (       a   eg )Nz
172.16.0.1r   r  rG   s    r4   r   !TestAddressInNetwork.test_invalid  s    %l4DEEEEEr7   rF   N)rP   rQ   rR   rS   r   r   rT   rF   r7   r4   r  r    s    CFr7   r  c            
          \ rS rSr\R
                  R                  SS\" S\4SS05      " 5       45      S 5       r	\R
                  R                  SS\
R                  4SR                  S	5      \
R                  445      S
 5       rSrg)TestGuessFilenamei#  r3   r&   Fakenamec                      [        U5      b   eg rK   )r   r   s     r4   test_guess_filename_invalid-TestGuessFilename.test_guess_filename_invalid$  s    
 e$,,,r7   zvalue, expected_types   valueutf-8c                 ~    [        S[        4SU05      " 5       n[        U5      nXA:X  d   e[        XB5      (       d   eg )Nr  r  )typer   r   
isinstance)r1   r3   expected_typeobjresults        r4   test_guess_filename_valid+TestGuessFilename.test_guess_filename_valid+  s@     6F9vuo68$&0000r7   rF   N)rP   rQ   rR   rS   r   r   r   r  r   r  r   bytesdecoder|   r  rT   rF   r7   r4   r  r  #  s    [[	
D&VQK023-	- [[v||$__W%vzz2	
11r7   r  c                       \ rS rSr\R
                  R                  SS\\R                  S45      S 5       rS r	S r
Srg	)
TestExtractZippedPathsi9  path/z/etc/invalid/locationc                 &    U[        U5      :X  d   eg rK   r   r1   r   s     r4   test_unzipped_paths_unchanged4TestExtractZippedPaths.test_unzipped_paths_unchanged:  s     +D1111r7   c                 6   UR                  S5      n[        R                  " UR                  S5       nUR	                  [
        5        S S S 5        [        R                  R                  [
        5      u  pE[        R                  R                  UR                  UR                  S5      5      n[        U5      nXv:w  d   e[        R                  R                  U5      (       d   e[        R                  " U[
        5      (       d   eg ! , (       d  f       N= f)Nztest.ziprz   z\/)rn   zipfileZipFilestrpathr:   r   osr   
splitdrivelstripr   existsfilecmpcmp)r1   rq   	zipped_pyr   _r  zipped_pathextracted_paths           r4   test_zipped_paths_extracted2TestExtractZippedPaths.test_zipped_paths_extractedF  s    KK
+	__Y..4GGH 5 ''$$X.ggll9#4#4dkk%6HI-k:,,,ww~~n----{{>84444 54s   D


Dc                 *    Sn[        U5      U:X  d   eg )Nz\\localhost\invalid\locationr#  r$  s     r4   test_invalid_unc_path,TestExtractZippedPaths.test_invalid_unc_pathS  s    .#D)T111r7   rF   N)rP   rQ   rR   rS   r   r   r   r   r%  r5  r8  rT   rF   r7   r4   r  r  9  sE    [[OO#		
2252r7   r  c                   d    \ rS rSrS r\R                  R                  SS5      S 5       rS r	Sr
g)	TestContentEncodingDetectioniX  c                 >    [        S5      n[        U5      (       a   eg )N r   rp   )r1   	encodingss     r4   	test_none&TestContentEncodingDetection.test_noneY  s    .r2	y>>!!>r7   content)z<meta charset="UTF-8">zB<meta http-equiv="Content-type" content="text/html;charset=UTF-8">zD<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />z&<?xml version="1.0" encoding="UTF-8"?>c                 R    [        U5      n[        U5      S:X  d   eUS   S:X  d   eg )Nr&   r   zUTF-8r>  )r1   rB  r?  s      r4   test_pragmas)TestContentEncodingDetection.test_pragmas]  s2     /w7	9~"""|w&&&r7   c                 J    SR                  5       n[        U5      / SQ:X  d   eg )Nz
        <?xml version="1.0" encoding="XML"?>
        <meta charset="HTML5">
        <meta http-equiv="Content-type" content="text/html;charset=HTML4" />
        )HTML5HTML4XML)stripr   )r1   rB  s     r4   test_precedence,TestContentEncodingDetection.test_precedenceo  s+     EG	 	
 *'26OOOOr7   rF   N)rP   rQ   rR   rS   r@  r   r   r   rD  rK  rT   rF   r7   r4   r;  r;  X  s8    " [[		
''
Pr7   r;  c                       \ rS rSr\R
                  R                  SS5      S 5       rS r\R
                  R                  SS5      S 5       r	S	r
g
)TestGuessJSONUTFix  encoding)utf-32z	utf-8-sigutf-16r  	utf-16-be	utf-16-le	utf-32-be	utf-32-lec                 H    SR                  U5      n[        U5      U:X  d   eg )Nz{}encoder   )r1   rO  datas      r4   test_encodedTestGuessJSONUTF.test_encodedy  s%     {{8$d#x///r7   c                      [        S5      b   eg )Ns       )r   rG   s    r4   test_bad_utf_like_encoding+TestGuessJSONUTF.test_bad_utf_like_encoding  s    12:::r7   )rO  r   ))rR  rQ  )rS  rQ  )rT  rP  )rU  rP  c                 H    SR                  U5      n[        U5      U:X  d   eg )Nu   ﻿{}rW  )r1   rO  r   rY  s       r4   test_guess_by_bom"TestGuessJSONUTF.test_guess_by_bom  s'       *d#x///r7   rF   N)rP   rQ   rR   rS   r   r   r   rZ  r]  r`  rT   rF   r7   r4   rN  rN  x  s[    [[		
00; [[ 	
00r7   rN  z%!*'();:@&=+$,/?#[] r=  z	url, authzhttp://:z@request.com/url.html#test)z/http://user:pass@complex.url.com/path?query=yes)userpass)z6http://user:pass%20pass@complex.url.com/path?query=yesrc  z	pass pass)z4http://user:pass pass@complex.url.com/path?query=yesre  )z6http://user%25user:pass@complex.url.com/path?query=yes)z	user%userrd  )z6http://user:pass%23pass@complex.url.com/path?query=yes)rc  z	pass#pass)z%http://complex.url.com/path?query=yes)r=  r=  c                 &    [        U 5      U:X  d   eg rK   )r   )r   auths     r4   test_get_auth_from_urlrh    s    2 S!T)))r7   zuri, expected))&http://example.com/fiz?buz=%25ppictureri  )z$http://example.com/fiz?buz=%ppictureri  c                 &    [        U 5      U:X  d   eg)z0See: https://github.com/psf/requests/issues/2356N)r   urir   s     r4   'test_requote_uri_with_unquoted_percentsrm    s    " sx'''r7   ))http://example.com/?a=%--rn  )zhttp://example.com/?a=%300zhttp://example.com/?a=00c                 &    [        U 5      U:X  d   eg rK   )r$   rk  s     r4   test_unquote_unreservedrp    s      c"h...r7   zmask, expected))   z	255.0.0.0)   z255.255.255.0)   z255.255.255.128c                 &    [        U 5      U:X  d   eg rK   )r   )maskr   s     r4   test_dotted_netmaskrv    s     $8+++r7   zhttp://http.proxyzhttp://some.host.proxy)httphttp://some.hostzsocks5://http.proxyzsocks5://some.host.proxy)allzall://some.host)rw  rx  ry  zurl, expected, proxieszhTTp://u:p@Some.Host/pathzhTTp://u:p@Other.Host/pathzhTTp:///pathzhTTps://Other.Hostzfile:///etc/motdzhttp://u:p@other.host/pathzhttp://u:p@some.host/pathzhttps://u:p@other.host/pathzhttps://u:p@some.host/pathzhttps://c                 &    [        X5      U:X  d   eg)z3Make sure we can select per-host proxies correctly.N)r   )r   r   proxiess      r4   test_select_proxiesr|    s    . %111r7   r   zfoo="is a fish", bar="as well"z	is a fishzas well)r   barkey_without_valuec                 &    [        U 5      U:X  d   eg rK   )r   r3   r   s     r4   test_parse_dict_headerr    s     U#x///r7   zapplication/xmlz application/json ; charset=utf-8zapplication/jsoncharsetr  z application/json ; Charset=utf-8z
text/plainzSmultipart/form-data; boundary = something ; boundary2='something_else' ; no_equals zmultipart/form-data	somethingsomething_elseT)boundary	boundary2	no_equalszSmultipart/form-data; boundary = something ; boundary2="something_else" ; no_equals zSmultipart/form-data; boundary = something ; 'boundary2=something_else' ; no_equals zSmultipart/form-data; boundary = something ; "boundary2=something_else" ; no_equals zapplication/json ; ; c                 &    [        U 5      U:X  d   eg rK   )r   r  s     r4   test__parse_content_type_headerr  #  s    z &e,888r7   zcontent-typezapplication/json; charset=utf-8z
ISO-8859-1c                 &    [        U 5      U:X  d   eg rK   )r   r  s     r4   test_get_encoding_from_headersr  c  s     %U+x777r7   zvalue, length))r=  r   )Tr&   )r,   r/   )Contr   )Other)ContentNc                     Ub  US::  a3  [        U 5      S:  a$  [        [        [        X5      5      5      S:X  d   eg [        [        [        U S5      5      5      U:X  d   eg )Nr   r&   )rp   listr   )r3   r   s     r4   test_iter_slicesr  r  sU     ~&A+#e*q.4E2349994E1-./6999r7   z4<http:/.../front.jpeg>; rel=front; type="image/jpeg"zhttp:/.../front.jpegfrontz
image/jpeg)r   relr  z<http:/.../front.jpeg>r   z<http:/.../front.jpeg>;zA<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;)r   r  zhttp://.../back.jpegc                 &    [        U 5      U:X  d   eg rK   )r   r  s     r4   test_parse_header_linksr    s    ( e$000r7   ))example.com/pathhttp://example.com/path)//example.com/pathr  )zexample.com:80zhttp://example.com:80)'http://user:pass@example.com/path?queryr  )"http://user@example.com/path?queryr  c                 (    [        U S5      U:X  d   eg )Nrw  )r   r  s     r4   test_prepend_scheme_if_neededr    s     $E62h>>>r7   )r  r  )   Tr  r  c                 &    [        U 5      U:X  d   eg rK   )r"   r  s     r4   test_to_native_stringr    s     E"h...r7   zurl, expected))z$http://u:p@example.com/path?a=1#testzhttp://example.com/path?a=1)r  r  )z//u:p@example.com/pathr  )r  r  )r  r  )zscheme:u:p@example.com/pathzscheme://example.com/pathc                 &    [        U 5      U:X  d   eg rK   )r%   )r   r   s     r4   test_urldefragauthr    s     )))r7   )
r   Tr   Tr   Tr   Tr   T)zhttp://google.com:6000/Tzhttp://172.16.1.12/Fzhttp://172.16.1.12:5000/Fhttp://google.com:5000/v1.0/F)zfile:///some/path/on/diskTc                 l    UR                  SS5        UR                  SS5        [        U SS9U:X  d   eg)zRTests for function should_bypass_proxies to check if proxy
can be bypassed or not
r   zJ192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000r   Nr   )r   r   )r   r   r   s      r4   test_should_bypass_proxiesr    sE    & T T !t4@@@r7   ))r   
172.16.1.1)r   r  )zhttp://user:pass@172.16.1.1r  )z http://user:pass@172.16.1.1:5000r  )zhttp://hostname/hostname)zhttp://hostname:5000/r  )zhttp://user:pass@hostnamer  )zhttp://user:pass@hostname:5000r  c                     [         R                  " S5       n[        U SS9  UR                  U5        SSS5        g! , (       d  f       g= f)zlThe proxy_bypass function should be called with a hostname or IP without
a port number or auth credentials.
zrequests.utils.proxy_bypassNr   )r   patchr   assert_called_once_with)r   r   proxy_bypasss      r4   -test_should_bypass_proxies_pass_only_hostnamer    s7    " 
1	2lcD1,,X6 
3	2	2s	   <
A
	cookiejarc                     SSS.n[        X5      nU Vs0 s H  o3R                  UR                  _M     nnX:X  d   egs  snf )zHEnsure add_dict_to_cookiejar works for
non-RequestsCookieJar CookieJars
cookies)testgoodN)r   r  r3   )r  
cookiedictcjcookier  s        r4   test_add_dict_to_cookiejarr    sH     $Y7J	y	5B79:rV{{FLL(rG:    ;s    ?))r  T)u   æíöûF)u   ジェーピーニックFc                 $    [        U 5      UL d   eg rK   r   r  s     r4   test_unicode_is_asciir    s     E"h...r7   )r  r  r  r  r  r  r  r  c                 &    Sn[        XS9U:X  d   eg)zpTests for function should_bypass_proxies to check if proxy
can be bypassed or not using the 'no_proxy' argument
r   r   N)r   )r   r   r   r   s       r4   #test_should_bypass_proxies_no_proxyr    s    " KH 8HDDDr7   ntzTest only on Windows)reasonzurl, expected, override)
)r   TN)r   TN)r   TN)r   TN)r   TN)zhttp://172.16.1.22/FN)zhttp://172.16.1.22:5000/FN)r  FN)z!http://mylocalhostname:5000/v1.0/Tz<local>)r   Fr=  c                   ^^^	 Tc  SmSSK n " S S5      nU" 5       m[        SS/5      m	U4S jnUUU	4S	 jnUR                  S
S5        UR                  SS5        UR                  SS5        UR                  SS5        UR                  SS5        UR                  USU5        UR                  USU5        [	        U S5      U:X  d   eg)zqTests for function should_bypass_proxies to check if proxy
can be bypassed or not with Windows registry settings
N4192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1r   c                       \ rS rSrS rSrg):test_should_bypass_proxies_win_registry.<locals>.RegHandleiG  c                     g rK   rF   rG   s    r4   Close@test_should_bypass_proxies_win_registry.<locals>.RegHandle.CloseH      r7   rF   NrP   rQ   rR   rS   r  rT   rF   r7   r4   	RegHandler  G      	r7   r  r&   1c                    > T$ rK   rF   r   subkeyie_settingss     r4   OpenKey8test_should_bypass_proxies_win_registry.<locals>.OpenKeyN  	    r7   c                 \   > U TL a&  US:X  a  TR                  5         TS   /$ US:X  a  T/$ g g )NProxyEnabler   ProxyOverride)rotate)r   
value_namer  overrideproxyEnableValuess     r4   QueryValueEx=test_should_bypass_proxies_win_registry.<locals>.QueryValueExQ  sG    +]*!((*)!,--. z! / r7   r   r=  https_proxy	ftp_proxyr   r   r  r  )winregr   r   setattrr   )
r   r   r  r   r  r  r  r  r  r  s
     `     @@r4   'test_should_bypass_proxies_win_registryr  /  s    ( I  +Kq#h" |R(}b){B'z2&z2&	73= d+x777r7   c                 F  ^ SSK n " S S5      nU" 5       mU4S jnU4S jnU R                  SS5        U R                  S	S5        U R                  S
S5        U R                  SS5        U R                  USU5        U R                  USU5        [        SS5      SL d   eg)zzTests for function should_bypass_proxies to check if proxy
can be bypassed or not with Windows invalid registry settings.
r   Nc                       \ rS rSrS rSrg)Etest_should_bypass_proxies_win_registry_bad_values.<locals>.RegHandleik  c                     g rK   rF   rG   s    r4   r  Ktest_should_bypass_proxies_win_registry_bad_values.<locals>.RegHandle.Closel  r  r7   rF   Nr  rF   r7   r4   r  r  k  r  r7   r  c                    > T$ rK   rF   r  s     r4   r  Ctest_should_bypass_proxies_win_registry_bad_values.<locals>.OpenKeyq  r  r7   c                 6   > U TL a  US:X  a  S/$ US:X  a  S/$ g g )Nr  r=  r  r  rF   r   r  r  s     r4   r  Htest_should_bypass_proxies_win_registry_bad_values.<locals>.QueryValueExt  s5    +]*t.NOO /	 r7   r   r=  r  r   r   r  r  r   Fr  r   r  r   r   r  r  r  r  r  s        @r4   2test_should_bypass_proxies_win_registry_bad_valuesr  d  s    
   +KP |R(}b)z2&z2&	73= !5t<EEEr7   zenv_name, value))r   .192.168.0.0/24,127.0.0.1,localhost.localdomain)r   N)	a_new_keyr  )r  Nc                    [         R                  " [        R                  5      n[	        X5         [        R                  R                  U 5      U:X  d   e SSS5        [        R                  U:X  d   eg! , (       d  f       N%= f)zGTests set_environ will set environ values and will restore the environ.N)copydeepcopyr+  environr   get)env_namer3   environ_copys      r4   test_set_environr    s[     ==,L	X	%zz~~h'5000 
& ::%%% 
&	%s   &A66
Bc                      [         R                  " [        5       n [        SS5         [        S5      e! , (       d  f       O= f SSS5        O! , (       d  f       O= fS[	        W R
                  5      ;   d   eg)zTTests set_environ will raise exceptions in context when the
value parameter is None.test1NzExpected exception)r   r   	Exceptionr   r|   r3   )	exceptions    r4   !test_set_environ_raises_exceptionr    sY     
y	!Y$'011 ('' 
"	!	!  3y#7777s   A4
A	A
Ac                    ^ SSK n " S S5      nU" 5       mU4S jnU4S jnU R                  SS5        U R                  S	S5        U R                  US
U5        U R                  USU5        [        SS5      SL d   eg)zTests for function should_bypass_proxies to check if proxy
can be bypassed or not with Windows ProxyOverride registry value ending with a semicolon.
r   Nc                       \ rS rSrS rSrg)Ntest_should_bypass_proxies_win_registry_ProxyOverride_value.<locals>.RegHandlei  c                     g rK   rF   rG   s    r4   r  Ttest_should_bypass_proxies_win_registry_ProxyOverride_value.<locals>.RegHandle.Close  r  r7   rF   Nr  rF   r7   r4   r  r    r  r7   r  c                    > T$ rK   rF   r  s     r4   r  Ltest_should_bypass_proxies_win_registry_ProxyOverride_value.<locals>.OpenKey  r  r7   c                 6   > U TL a  US:X  a  S/$ US:X  a  S/$ g g )Nr  r&   r  zA192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;rF   r  s     r4   r  Qtest_should_bypass_proxies_win_registry_ProxyOverride_value.<locals>.QueryValueEx  s9    +]*s
.W  / r7   r   r=  r   r  r  zhttp://example.com/Fr  r  s        @r4   ;test_should_bypass_proxies_win_registry_ProxyOverride_valuer    s    
   +K z2&z2&	73= !6=FFFr7   )br  r/  r+  r}   r(  collectionsr   ior   unittestr   r   requestsr   requests._internal_utilsr   requests.cookiesr	   requests.structuresr
   requests.utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r'   r(   r*   r   r   r   r   r   r  r  r  r;  rN  USERPASSWORDquoteENCODED_USERENCODED_PASSWORDr   r   rh  rm  rp  rv  http_proxiesall_proxiesmixed_proxiesr|  r  r  r  r  r  r  r  r  r  r  	cookielib	CookieJarr  r  r  r   r  r  r  r  r  r  rF   r7   r4   <module>r     s     	        5 . 3       < (g( g(T& &$P P$>A >AB* *( ($F F1 1,2 2>P P@ 0  0F ) (x||D"%<<"-   l^1%5$66PQ8	
 	N	
 	X	
	
 	<'0*10* ((
 // ,,
  0
 !1
  0  	$&>M	%':LI	,l;	t\2	T<0	$&@+N	%'<kJ	.<	4kB	%':MJ	$&>N	&(=}M	%'<mL	*M:	2K@!*2+*2
 	);y+QR	2D9:00 	.34.)W!56	

 /)W!56	
 
b)*a% +!1!%
	
 b% +!1!%
	
 b% +!1!%
	
 b% +!1!%
	
 
!#5r":;o8;x9y;x9 		%1R ST	
 
nl;	<lK
8
8 
:
:  C+G\RS	
 
"U,B$C#DE	"e-C%D$EFO.E./	
 
R&1'&1 	?? // 
*
* AA 	77 ""$!! // 	EE BGGtO,BC"8 D "8J BGGtO,BCF DF@ &&8 BGGtO,BCG DGr7   