
    r                     
   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 d dl	m
Z
 d dlZd dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ d
dlm0Z0m1Z1  G d d      Z2 G d d      Z3 G d d      Z4 G d d      Z5 G d d      Z6 G d d      Z7 G d d      Z8 G d d      Z9 G d d      Z: G d d      Z; G d  d!      Z<d"xZ=Z> ej~                  e=d#      Z@ ej~                  e>d#      ZAej                  j                  d$d%e@ d&eA d'e=e>ffd(d)d*d+d,d-f      d.        ZDej                  j                  d/d0      d1        ZEej                  j                  d/d2      d3        ZFej                  j                  d4d5      d6        ZGd7d8d9ZHd:d;d<ZId7d8d:d=ZJej                  j                  d>d?d8eHfd@d7eHfdAd7eHfdBdeHfdCdeHfd?d;eIfd@d:eIfdAd:eIfdBd:eIfdDd7eJfdEd8eJfdFd:eJfdGd:eJfdHd:eJfdCd:eIff      dI        ZKej                  j                  dJdKdLdMdNfdOdOdiff      dP        ZLej                  j                  dJdQdQi ffdRdSdTdUiffdVdSdTdUiffdWdWi ffdXdYdZd[d\d]ffd^dYdZd[d\d]ffd_dYdZd[d\d]ffd`dYdZd[d\d]ffdadSi fff	      db        ZMej                  j                  dJ e       df edcddi      dUf edcdWi      deff      df        ZNej                  j                  dgdh      di        ZOej                  j                  dJdjdkdldmdngfdodpdkigfdqdpdkigfdrdkdmdsdpdtigfd#g ff      du        ZPej                  j                  dJdv      dw        ZQej                  j                  dJdx      dy        ZRej                  j                  dzd{      d|        ZSej                  j                  dzd}      d~        ZTej                  j                  dzd      d        ZUej                  j                  dej                  j                          e       f      d        ZXej                  j                  dJd      d        ZYej                  j                  dzd      d        ZZej                  j                  ej                  dk7  d      ej                  j                  dd      d               Z]ej                  j                  ej                  dk7  d      d        Z^ej                  j                  dd      d        Z_d Z`ej                  j                  ej                  dk7  d      d        Zay)    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                      e Zd Zej                  j                  dej                  dfedf ej                  e	dej                  j                  d            f      d        Zd Zej                  j                  deeg      d	        Zej                  j                  deeg      d
        Zd Zej                  j                  dd      d        Zd Zd Zd Zd Zd Zd Zy)TestSuperLenzstream, valueTests   TestzcStringIO is None)marksc                 Z    t         |             dk(  sJ t         ||            dk(  sJ y)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_streamszTestSuperLen.test_io_streams2   s0     "a''''1,,,    c                 n    t        j                          }|j                  d       t        |      dk(  sJ y)z;Ensure that we handle partially consumed file like objects.foobarbogusr   N)r'   writer    )r0   ss     r3   >test_super_len_correctly_calculates_len_of_partially_read_filezKTestSuperLen.test_super_len_correctly_calculates_len_of_partially_read_fileA   s.    	|q   r5   errorc                 H     G fdd      }t         |             dk(  sJ y)z?If tell() raises errors, assume the cursor is at position zero.c                       e Zd Zd Z fdZy)XTestSuperLen.test_super_len_handles_files_raising_weird_errors_in_tell.<locals>.BoomFilec                      yN    r0   s    r3   __len__z`TestSuperLen.test_super_len_handles_files_raising_weird_errors_in_tell.<locals>.BoomFile.__len__L   s    r5   c                             NrB   r0   r;   s    r3   tellz]TestSuperLen.test_super_len_handles_files_raising_weird_errors_in_tell.<locals>.BoomFile.tellO   
    gr5   N)__name__
__module____qualname__rD   rH   r;   s   r3   BoomFiler>   K   s    r5   rN   r   Nr/   )r0   r;   rN   s    ` r3   9test_super_len_handles_files_raising_weird_errors_in_tellzFTestSuperLen.test_super_len_handles_files_raising_weird_errors_in_tellG   s$    	 	 $)))r5   c                 H     G fdd      }t         |             dk(  sJ y)z;Ensure that if tell gives an IOError super_len doesn't failc                       e Zd Z fdZd Zy)?TestSuperLen.test_super_len_tell_ioerror.<locals>.NoLenBoomFilec                             rF   rB   rG   s    r3   rH   zDTestSuperLen.test_super_len_tell_ioerror.<locals>.NoLenBoomFile.tellY   rI   r5   c                      y rF   rB   )r0   offsetwhences      r3   seekzDTestSuperLen.test_super_len_tell_ioerror.<locals>.NoLenBoomFile.seek\   s    r5   N)rJ   rK   rL   rH   rW   rM   s   r3   NoLenBoomFilerR   X   s    r5   rX   r   Nr/   )r0   r;   rX   s    ` r3   test_super_len_tell_ioerrorz(TestSuperLen.test_super_len_tell_ioerrorT   s$    	 	 )Q...r5   c                 $    t        d      dk(  sJ y )Nr+   r.   r/   rC   s    r3   test_stringzTestSuperLen.test_stringa   s     A%%%r5   zmode, warnings_num))rr&   )rbr   c                     |j                  d      }|j                  d       |j                  |      5 }t        |      dk(  sJ 	 d d d        t	        |      |k(  sJ y # 1 sw Y   xY w)Ntest.txtr+   r.   )joinr8   openr    len)r0   tmpdirmodewarnings_numrecwarnfile_objfds          r3   	test_filezTestSuperLen.test_filed   s^     ;;z*v]]4 BR=A%%% !7||+++ ! s   AA(c                    |j                  d      }|j                  d       t        |j                  d            }t        j                  |d      5 }|j                  t        |      d       d d d        t        j                  |      5 }|j                  d      }t        |      dk(  sJ 	 d d d        y # 1 sw Y   JxY w# 1 sw Y   y xY w)Nr_   r+   ztest.tarw)arcnamer.   )r`   r8   strtarfilera   addextractfiler    )r0   rc   rg   tar_objtarmembers         r3   test_tarfile_memberz 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                 0    g d}t        |      }|dk(  sJ y )N)r&         r.   r.   r/   )r0   foolen_foos      r3   test_super_len_with__len__z'TestSuperLen.test_super_len_with__len__~   s    C.!||r5   c                 B     G d d      }t         |             dk(  sJ y )Nc                       e Zd Zd Zy);TestSuperLen.test_super_len_with_no__len__.<locals>.LenFilec                     d| _         y r@   )rb   rC   s    r3   __init__zDTestSuperLen.test_super_len_with_no__len__.<locals>.LenFile.__init__   s	    r5   N)rJ   rK   rL   r   rB   r5   r3   LenFiler}      s    r5   r   rA   r/   )r0   r   s     r3   test_super_len_with_no__len__z*TestSuperLen.test_super_len_with_no__len__   s#    	 	 #q(((r5   c                     t        j                   d      }t        |      dk(  sJ |j                  d       t        |      dk(  sJ y )N12345rA   rv   rw   )r'   r    read)r0   rx   s     r3   test_super_len_with_tellz%TestSuperLen.test_super_len_with_tell   sA    (~"""~"""r5   c                     t        t        d      5 }t        |      }|j                         }d d d        t	              k(  sJ y # 1 sw Y   xY w)Nr]   )ra   __file__r    r   rb   )r0   flength	file_datas       r3   test_super_len_with_filenoz'TestSuperLen.test_super_len_with_fileno   sD    (D!Qq\FI " Y''' "!s   AAc                 4    t        t                     dk(  sJ y)z;Ensure that objects without any length methods default to 0r   N)r    objectrC   s    r3   test_super_len_with_no_matchesz+TestSuperLen.test_super_len_with_no_matches   s    "a'''r5   N)rJ   rK   rL   pytestmarkparametrizer'   r   paramr(   skipifr4   r:   IOErrorOSErrorrO   rY   r[   ri   rt   rz   r   r   r   r   rB   r5   r3   r*   r*   1   s   [['gFLL6););<O)P	
	-	-
! [[Ww&89
* :
* [[Ww&89
/ :
/& [[	
,,
*
)#((r5   r*   c                   v    e Zd Zej                  j                  ddgdgfddgfddidgfdf      d        Zd Zy	)
TestToKeyValListvalue, expectedkeyval)r   r   r   NNc                 $    t        |      |k(  sJ y rF   )r!   r0   r2   expecteds      r3   
test_validzTestToKeyValList.test_valid   s     u%111r5   c                 v    t        j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Nstring)r   raises
ValueErrorr!   rC   s    r3   test_invalidzTestToKeyValList.test_invalid   s"    ]]:&H% '&&s   /8N)rJ   rK   rL   r   r   r   r   r   rB   r5   r3   r   r      s[    [[/0 01U^n-.		
22&r5   r   c                   V    e Zd Zej                  j                  dd      d        Zd Zy)TestUnquoteHeaderValuer   )r   )r+   r+   )z"Test"r+   )z"Test\\"zTest\)"\\Comp\Res"z	\Comp\Resc                 $    t        |      |k(  sJ y rF   r#   r   s      r3   r   z!TestUnquoteHeaderValue.test_valid   s     $E*h666r5   c                 &    t        dd      dk(  sJ y )Nr   Tz
\\Comp\Resr   rC   s    r3   test_is_filenamez'TestUnquoteHeaderValue.test_is_filename   s    #$5t<OOOr5   N)rJ   rK   rL   r   r   r   r   r   rB   r5   r3   r   r      s1    [[	
	7	7Pr5   r   c                   X   e Zd ZdZ ej
                  dddg      d        Zej                  j                  dd      d	        Z	ej                  j                  dd
      d        Z
ej                  j                  dd
      d        Zej                  j                  dd      d        Zy)TestGetEnvironProxieszZEnsures that IP addresses are correctly matches with ranges
    in no_proxy variable.
    Tno_proxyNO_PROXY)autouseparamsc                 <    |j                  |j                  d       y )N9192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1)setenvr   )r0   requestmonkeypatchs      r3   r   zTestGetEnvironProxies.no_proxy   s    MMV	
r5   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                 (    t        |d       i k(  sJ y Nr   r   r0   r   s     r3   test_bypassz!TestGetEnvironProxies.test_bypass   s     #36"<<<r5   )zhttp://192.168.1.1:5000/zhttp://192.168.1.1/zhttp://www.requests.com/c                 (    t        |d       i k7  sJ y r   r   r   s     r3   test_not_bypassz%TestGetEnvironProxies.test_not_bypass   s     #36"<<<r5   c                 ,    d}t        ||      i k(  sJ y )N192.168.1.1,requests.comr   r   )r0   r   r   s      r3   test_bypass_no_proxy_keywordz2TestGetEnvironProxies.test_bypass_no_proxy_keyword   s     ."3:b@@@r5   c                 P    |j                  dd       d}t        ||      i k7  sJ y )N
http_proxyzhttp://proxy.example.com:3128/r   r   )r   r   )r0   r   r   r   s       r3    test_not_bypass_no_proxy_keywordz6TestGetEnvironProxies.test_not_bypass_no_proxy_keyword   s/     	<)IJ-"3:b@@@r5   N)rJ   rK   rL   __doc__r   fixturer   r   r   r   r   r   r   rB   r5   r3   r   r      s     V^^D*j)AB
 C

 [[	
	=	= [[	
== [[	
AA [[	
	A	Ar5   r   c                   V    e Zd Zd Zej
                  j                  dd      d        Zy)TestIsIPv4Addressc                     t        d      sJ y )N8.8.8.8r   rC   s    r3   r   zTestIsIPv4Address.test_valid  s    y)))r5   r2   )z	8.8.8.8.8zlocalhost.localdomainc                     t        |      rJ y rF   r   r0   r2   s     r3   r   zTestIsIPv4Address.test_invalid  s    "5))))r5   NrJ   rK   rL   r   r   r   r   r   rB   r5   r3   r   r      s.    * [[W&LM* N*r5   r   c                   V    e Zd Zd Zej
                  j                  dd      d        Zy)TestIsValidCIDRc                     t        d      sJ y )N192.168.1.0/24r   rC   s    r3   r   zTestIsValidCIDR.test_valid
  s    -...r5   r2   )r   z192.168.1.0/az192.168.1.0/128z192.168.1.0/-1z192.168.1.999/24c                     t        |      rJ y rF   r   r   s     r3   r   zTestIsValidCIDR.test_invalid  s     !''''r5   Nr   rB   r5   r3   r   r   	  s2    / [[	
	(	(r5   r   c                       e Zd Zd Zd Zy)TestAddressInNetworkc                      t        dd      sJ y )Nz192.168.1.1r   r   rC   s    r3   r   zTestAddressInNetwork.test_valid  s    !-1ABBBr5   c                      t        dd      rJ y )Nz
172.16.0.1r   r   rC   s    r3   r   z!TestAddressInNetwork.test_invalid  s    %l4DEEEEr5   N)rJ   rK   rL   r   r   rB   r5   r3   r   r     s    CFr5   r   c                   
   e Zd Zej                  j                  dd  edefddi             f      d        Zej                  j                  dde	j                  fdj                  d      e	j                  ff      d	        Zy
)TestGuessFilenamer2   r&   Fakenamec                     t        |      J y rF   )r   r   s     r3   test_guess_filename_invalidz-TestGuessFilename.test_guess_filename_invalid$  s    
 e$,,,r5   zvalue, expected_types   valueutf-8c                 v     t        dt        fd|i             }t        |      }||k(  sJ t        ||      sJ y )Nr   r   )typer   r   
isinstance)r0   r2   expected_typeobjresults        r3   test_guess_filename_validz+TestGuessFilename.test_guess_filename_valid+  sC     7d6F9vuo68$&-000r5   N)rJ   rK   rL   r   r   r   r   r   r   r   bytesdecoderm   r   rB   r5   r3   r   r   #  s    [[	
0D&VQK023-	- [[v||$__W%vzz2	
11r5   r   c                   x    e Zd Zej                  j                  ddeej                  df      d        Zd Zd Z	y)TestExtractZippedPathspath/z/etc/invalid/locationc                 $    |t        |      k(  sJ y rF   r   r0   r   s     r3   test_unzipped_paths_unchangedz4TestExtractZippedPaths.test_unzipped_paths_unchanged:  s     +D1111r5   c                    |j                  d      }t        j                  |j                  d      5 }|j	                  t
               d d d        t        j                  j                  t
              \  }}t        j                  j                  |j                  |j                  d            }t        |      }||k7  sJ t        j                  j                  |      sJ t        j                  |t
              sJ y # 1 sw Y   xY w)Nztest.ziprk   z\/)r`   zipfileZipFilestrpathr8   r   osr   
splitdrivelstripr   existsfilecmpcmp)r0   rc   	zipped_pyr   _r   zipped_pathextracted_paths           r3   test_zipped_paths_extractedz2TestExtractZippedPaths.test_zipped_paths_extractedF  s    KK
+	__Y..4GGH 5 ''$$X.4ggll9#4#4dkk%6HI-k:,,,ww~~n---{{>8444 54s   C??Dc                 (    d}t        |      |k(  sJ y )Nz\\localhost\invalid\locationr   r   s     r3   test_invalid_unc_pathz,TestExtractZippedPaths.test_invalid_unc_pathS  s    .#D)T111r5   N)
rJ   rK   rL   r   r   r   r   r   r  r	  rB   r5   r3   r   r   9  sE    [[OO#		
2252r5   r   c                   \    e Zd Zd Zej
                  j                  dd      d        Zd Zy)TestContentEncodingDetectionc                 4    t        d      }t        |      rJ y )N r   rb   )r0   	encodingss     r3   	test_nonez&TestContentEncodingDetection.test_noneY  s    .r2	y>!!>r5   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                 N    t        |      }t        |      dk(  sJ |d   dk(  sJ y )Nr&   r   zUTF-8r  )r0   r  r  s      r3   test_pragmasz)TestContentEncodingDetection.test_pragmas]  s2     /w7	9~"""|w&&&r5   c                 H    dj                         }t        |      g dk(  sJ y )Nz
        <?xml version="1.0" encoding="XML"?>
        <meta charset="HTML5">
        <meta http-equiv="Content-type" content="text/html;charset=HTML4" />
        )HTML5HTML4XML)stripr   )r0   r  s     r3   test_precedencez,TestContentEncodingDetection.test_precedenceo  s+     EG	 	
 *'26OOOOr5   N)	rJ   rK   rL   r  r   r   r   r  r  rB   r5   r3   r  r  X  s8    " [[		
''
Pr5   r  c                       e Zd Zej                  j                  dd      d        Zd Zej                  j                  dd      d        Zy)	TestGuessJSONUTFencoding)utf-32z	utf-8-sigutf-16r   	utf-16-be	utf-16-le	utf-32-be	utf-32-lec                 F    dj                  |      }t        |      |k(  sJ y )Nz{}encoder   )r0   r  datas      r3   test_encodedzTestGuessJSONUTF.test_encodedy  s%     {{8$d#x///r5   c                     t        d      J y )Ns       )r   rC   s    r3   test_bad_utf_like_encodingz+TestGuessJSONUTF.test_bad_utf_like_encoding  s    12:::r5   )r  r   ))r  r  )r   r  )r!  r  )r"  r  c                 F    dj                  |      }t        |      |k(  sJ y )Nu   ﻿{}r$  )r0   r  r   r&  s       r3   test_guess_by_bomz"TestGuessJSONUTF.test_guess_by_bom  s'       *d#x///r5   N)	rJ   rK   rL   r   r   r   r'  r)  r+  rB   r5   r3   r  r  x  s[    [[		
00; [[ 	
00r5   r  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r-  z	pass pass)z4http://user:pass pass@complex.url.com/path?query=yesr/  )z6http://user%25user:pass@complex.url.com/path?query=yes)z	user%userr.  )z6http://user:pass%23pass@complex.url.com/path?query=yes)r-  z	pass#pass)z%http://complex.url.com/path?query=yes)r  r  c                 $    t        |       |k(  sJ y rF   )r   )r   auths     r3   test_get_auth_from_urlr2    s    2 S!T)))r5   zuri, expected))&http://example.com/fiz?buz=%25ppicturer3  )z$http://example.com/fiz?buz=%ppicturer3  c                 $    t        |       |k(  sJ y)z0See: https://github.com/psf/requests/issues/2356N)r   urir   s     r3   'test_requote_uri_with_unquoted_percentsr7    s    " sx'''r5   ))http://example.com/?a=%--r8  )zhttp://example.com/?a=%300zhttp://example.com/?a=00c                 $    t        |       |k(  sJ y rF   )r$   r5  s     r3   test_unquote_unreservedr:    s      c"h...r5   zmask, expected))   z	255.0.0.0)   z255.255.255.0)   z255.255.255.128c                 $    t        |       |k(  sJ y rF   )r   )maskr   s     r3   test_dotted_netmaskr@    s     $8+++r5   zhttp://http.proxyzhttp://some.host.proxy)httphttp://some.hostzsocks5://http.proxyzsocks5://some.host.proxy)allzall://some.host)rA  rB  rC  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                 &    t        | |      |k(  sJ y)z3Make sure we can select per-host proxies correctly.N)r   )r   r   proxiess      r3   test_select_proxiesrF    s    . W%111r5   r   zfoo="is a fish", bar="as well"z	is a fishzas well)rx   barkey_without_valuec                 $    t        |       |k(  sJ y rF   )r   r2   r   s     r3   test_parse_dict_headerrK    s     U#x///r5   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                 $    t        |       |k(  sJ y rF   )r   rJ  s     r3   test__parse_content_type_headerrS  #  s    z &e,888r5   zcontent-typezapplication/json; charset=utf-8z
ISO-8859-1c                 $    t        |       |k(  sJ y rF   )r   rJ  s     r3   test_get_encoding_from_headersrU  c  s     %U+x777r5   zvalue, length))r  r   )Tr&   )r+   r.   )Contr   )Other)ContentNc                     ||dk  r2t        |       dkD  r$t        t        t        | |                  dk(  sJ y t        t        t        | d                  |k(  sJ y )Nr   r&   )rb   listr   )r2   r   s     r3   test_iter_slicesr]  r  sW     ~&A+#e*q.4E62349994E1-./6999r5   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                 $    t        |       |k(  sJ y rF   )r   rJ  s     r3   test_parse_header_linksra    s    ( e$000r5   ))example.com/pathhttp://example.com/path)//example.com/pathrc  )zexample.com:80zhttp://example.com:80)'http://user:pass@example.com/path?queryre  )"http://user@example.com/path?queryrf  c                 &    t        | d      |k(  sJ y )NrA  )r   rJ  s     r3   test_prepend_scheme_if_neededrh    s     $E62h>>>r5   )rV  rV  )   TrV  ri  c                 $    t        |       |k(  sJ y rF   )r"   rJ  s     r3   test_to_native_stringrl    s     E"h...r5   zurl, expected))z$http://u:p@example.com/path?a=1#testzhttp://example.com/path?a=1)rc  rc  )z//u:p@example.com/pathrd  )rd  rd  )rb  rd  )zscheme:u:p@example.com/pathzscheme://example.com/pathc                 $    t        |       |k(  sJ y rF   )r%   )r   r   s     r3   test_urldefragauthrn    s     )))r5   )
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                 p    |j                  dd       |j                  dd       t        | d      |k(  sJ y)zZTests 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      r3   test_should_bypass_proxiesry    sE    & T T !t4@@@r5   ))r   
172.16.1.1)r   rz  )zhttp://user:pass@172.16.1.1rz  )z http://user:pass@172.16.1.1:5000rz  )zhttp://hostname/hostname)zhttp://hostname:5000/r{  )zhttp://user:pass@hostnamer{  )zhttp://user:pass@hostname:5000r{  c                     t        j                  d      5 }t        | d       |j                  |       ddd       y# 1 sw Y   yxY w)ztThe 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      r3   -test_should_bypass_proxies_pass_only_hostnamer    s7    " 
1	2lcD1,,X6 
3	2	2s	   >A	cookiejarc                     ddd}t        | |      }|D ci c]  }|j                  |j                   }}||k(  sJ yc c}w )zPEnsure add_dict_to_cookiejar works for
    non-RequestsCookieJar CookieJars
    cookies)testgoodN)r   r   r2   )r  
cookiedictcjcookier  s        r3   test_add_dict_to_cookiejarr    sN     $Y7J	y*	5B79:rVv{{FLL(rG:    ;s   >))r  T)u   æíöûF)u   ジェーピーニックFc                 "    t        |       |u sJ y rF   r   rJ  s     r3   test_unicode_is_asciir    s     E"h...r5   )ro  rp  rq  rr  rs  rt  ru  rv  c                 ,    d}t        | |      |k(  sJ y)zxTests 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       r3   #test_should_bypass_proxies_no_proxyr    s    " KH x8HDDDr5   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)rw  FN)z!http://mylocalhostname:5000/v1.0/Tz<local>)r   Fr  c                   	 dddl } G d d      } |       t        ddg      	fd}	fd	}|j                  d
d       |j                  dd       |j                  dd       |j                  dd       |j                  dd       |j                  |d|       |j                  |d|       t	        | d      |k(  sJ y)zyTests 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                       e Zd Zd Zy):test_should_bypass_proxies_win_registry.<locals>.RegHandlec                      y rF   rB   rC   s    r3   Closez@test_should_bypass_proxies_win_registry.<locals>.RegHandle.CloseH      r5   NrJ   rK   rL   r  rB   r5   r3   	RegHandler  G      	r5   r  r&   1c                     S rF   rB   r   subkeyie_settingss     r3   OpenKeyz8test_should_bypass_proxies_win_registry.<locals>.OpenKeyN  	    r5   c                 V    | u r$|dk(  rj                          d   gS |dk(  rgS y y )NProxyEnabler   ProxyOverride)rotate)r   
value_namer  overrideproxyEnableValuess     r3   QueryValueExz=test_should_bypass_proxies_win_registry.<locals>.QueryValueExQ  sG    +]*!((*)!,--. z! / r5   r   r  https_proxy	ftp_proxyr   r   r  r  )winregr   r   setattrr   )
r   r   r  r   r  r  r  r  r  r  s
     `     @@r3   'test_should_bypass_proxies_win_registryr  /  s    ( I  +Kq#h" |R(}b){B'z2&z2&	73= d+x777r5   c                 @   ddl } G d d      } |       fd}fd}| j                  dd       | j                  d	d       | j                  d
d       | j                  dd       | j                  |d|       | j                  |d|       t        dd      du sJ y)zTests for function should_bypass_proxies to check if proxy
    can be bypassed or not with Windows invalid registry settings.
    r   Nc                       e Zd Zd Zy)Etest_should_bypass_proxies_win_registry_bad_values.<locals>.RegHandlec                      y rF   rB   rC   s    r3   r  zKtest_should_bypass_proxies_win_registry_bad_values.<locals>.RegHandle.Closel  r  r5   Nr  rB   r5   r3   r  r  k  r  r5   r  c                     S rF   rB   r  s     r3   r  zCtest_should_bypass_proxies_win_registry_bad_values.<locals>.OpenKeyq  r  r5   c                 0    | u r|dk(  rdgS |dk(  rdgS y y )Nr  r  r  r  rB   r   r  r  s     r3   r  zHtest_should_bypass_proxies_win_registry_bad_values.<locals>.QueryValueExt  s5    +]*t.NOO /	 r5   r   r  r  r   r   r  r  r   Fr  r   r  r   r   r  r  r  r  r  s        @r3   2test_should_bypass_proxies_win_registry_bad_valuesr  d  s    
   +KP |R(}b)z2&z2&	73= !5t<EEEr5   zenv_name, value))r   .192.168.0.0/24,127.0.0.1,localhost.localdomain)r   N)	a_new_keyr  )r  Nc                     t        j                  t        j                        }t	        | |      5  t        j                  j                  |       |k(  sJ 	 ddd       t        j                  |k(  sJ y# 1 sw Y   xY w)zGTests set_environ will set environ values and will restore the environ.N)copydeepcopyr   environr   get)env_namer2   environ_copys      r3   test_set_environr    s]     ==,L	Xu	%zz~~h'5000 
& ::%%% 
&	%s   %A44A=c                      t        j                  t              5 } t        dd      5  t        d      # 1 sw Y   nxY w	 ddd       n# 1 sw Y   nxY wdt	         j
                        v sJ y)zXTests set_environ will raise exceptions in context when the
    value parameter is None.test1NzExpected exception)r   r   	Exceptionr   rm   r2   )	exceptions    r3   !test_set_environ_raises_exceptionr    sY     
y	!Y$'011 ('' 
"	!	!  3y#7777s   A	3<	A		Ac                     ddl } G d d      } |       fd}fd}| j                  dd       | j                  d	d       | j                  |d
|       | j                  |d|       t        dd      du sJ y)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                       e Zd Zd Zy)Ntest_should_bypass_proxies_win_registry_ProxyOverride_value.<locals>.RegHandlec                      y rF   rB   rC   s    r3   r  zTtest_should_bypass_proxies_win_registry_ProxyOverride_value.<locals>.RegHandle.Close  r  r5   Nr  rB   r5   r3   r  r    r  r5   r  c                     S rF   rB   r  s     r3   r  zLtest_should_bypass_proxies_win_registry_ProxyOverride_value.<locals>.OpenKey  r  r5   c                 0    | u r|dk(  rdgS |dk(  rdgS y y )Nr  r&   r  zA192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;rB   r  s     r3   r  zQtest_should_bypass_proxies_win_registry_ProxyOverride_value.<locals>.QueryValueEx  s9    +]*s
.W  / r5   r   r  r   r  r  zhttp://example.com/Fr  r  s        @r3   ;test_should_bypass_proxies_win_registry_ProxyOverride_valuer    s    
   +K z2&z2&	73= !6=FFFr5   )br  r  r   rn   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  r  USERPASSWORDquoteENCODED_USERENCODED_PASSWORDr   r   r2  r7  r:  r@  http_proxiesall_proxiesmixed_proxiesrF  rK  rS  rU  r]  ra  rh  rl  rn  ry  r  	cookielib	CookieJarr  r  r  r   r   r  r  r  r  r  rB   r5   r3   <module>r     s     	        5 . 3       < (g( g(T& &$P P$>A >AB* *( ($F F1 1,2 2>P P@ 0  0F ) (xv||D"%6<<"-   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r5   