
    0hh                        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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r SSKrSSKrSSKrSS	KJr  SSKr\R:                  (       d  \
R<                  " S
5      eS rSq S0S jr!S r"S1S jr# " S S\$5      r% " S S\$5      r& " S S\
RN                  \5      r( " S S\
RN                  5      r) " S S\
RN                  5      r* " S S\
RN                  \%\&5      r+ " S S\
RN                  \5      r, " S S\
RN                  5      r- " S S \
RN                  \%5      r. " S! S"\
RN                  5      r/ " S# S$\
RN                  5      r0 " S% S&\
RN                  5      r1 " S' S(\
RN                  5      r2 " S) S*\
RN                  5      r3 " S+ S,\%\
RN                  5      r4 " S- S.\
RN                  5      r5\6S/:X  a  \
Rn                  " 5         gg! \ a    Sr GNf = f)2z;Regression tests for what was in Python 2's "urllib" module    N)patch)support)	os_helper)socket_helper)warnings_helper)ExtraAssertions)	b64encodeztest requires gethostname()c                 ~    [        [        U 5      5      SS R                  5       n[        U5      S:X  a  SU-  nSU-   $ )z!Escape char as RFC 2396 specifies   N   z0%s%)hexordupperlen)charhex_reprs     9/opt/python-3.13.8/usr/lib/python3.13/test/test_urllib.py	hexescaper       s?    3t9~ab!'')H
8}8#>    c                     Ub  [         R                  R                  US9nO[        (       d  [        5       nUqO[        nUc  UR	                  U 5      $ UR	                  X5      $ )z.urlopen(url [, data]) -> open file-like object)proxies)urllibrequestFancyURLopener
_urlopeneropen)urldatar   openers       r   urlopenr!   +   s[     ..w.?Z!
|{{3{{3%%r   c                      [         R                  " S[        45         [        R                  R                  5       sS S S 5        $ ! , (       d  f       g = f)Nz8FancyURLopener style of invoking requests is deprecated.)r   check_warningsDeprecationWarningr   r   r    r   r   r   r   ;   s=    		'	'G 
! ~~,,.
! 
! 
!s   A
Ac                    ^^^  " U4S jS[         R                  5      m " UU4S jS[        R                  R                  5      mU Tl        T$ )Nc                   F   > \ rS rSrSrU 4S jrS rS
S jrS
S jrS r	S	r
g)fakehttp.<locals>.FakeSocketC   r   c                    > UTl         g N)buf)selfr   FakeHTTPConnections     r   sendall$fakehttp.<locals>.FakeSocket.sendallF   s    %)"r   c                 0    U =R                   S-  sl         U $ )Nr   )io_refs)r-   argskwdss      r   makefile%fakehttp.<locals>.FakeSocket.makefileI   s    LLALKr   Nc                 d    U R                   (       a  g[        R                  R                  X5      $ Nr   )closedioBytesIOread)r-   amts     r   r<   !fakehttp.<locals>.FakeSocket.readM   s    {{::??4--r   c                 d    U R                   (       a  g[        R                  R                  X5      $ r8   )r9   r:   r;   readline)r-   lengths     r   r@   %fakehttp.<locals>.FakeSocket.readlineR   s!    {{::&&t44r   c                     U =R                   S-  sl         U R                   S:X  a   [        R                  R                  U 5        g g )Nr   r   )r2   r:   r;   closer-   s    r   rD   "fakehttp.<locals>.FakeSocket.closeW   s3    LLAL||q 

  & !r   r%   r+   )__name__
__module____qualname____firstlineno__r2   r/   r5   r<   r@   rD   __static_attributes__)r.   s   r   
FakeSocketr(   C   s!    	*		.
	5
	'r   rL   c                   B   > \ rS rSrSrU 4S jr Y(       a  S rSrgSrg)$fakehttp.<locals>.FakeHTTPConnection\   Nc                 h   > T" U R                   5      U l        U R                  [        U 5      l        g r+   )fakedatasocktypefakesock)r-   rL   s    r   connect,fakehttp.<locals>.FakeHTTPConnection.connecta   s#    "4==1DI"&))DJr   c                     g r+   r%   rE   s    r   rD   *fakehttp.<locals>.FakeHTTPConnection.closej       r   )rR   )rG   rH   rI   rJ   r,   rU   rD   rK   )rL   
mock_closes   r   r.   rN   \   s     	, 
 r   r.   )r:   r;   httpclientHTTPConnectionrQ   )rQ   rZ   r.   rL   s    `@@r   fakehttpr^   B   s?    'RZZ '2 T[[77   #+r   c                   $    \ rS rSrSS jrS rSrg)FakeHTTPMixinq   c                 ~    [        XS9n[        R                  R                  U l        U[        R                  l        g )NrZ   )r^   r[   r\   r]   _connection_class)r-   rQ   rZ   fake_http_classs       r   r^   FakeHTTPMixin.fakehttpr   s*    "8C!%!;!;%4"r   c                 B    U R                   [        R                  l        g r+   )rd   r[   r\   r]   rE   s    r   
unfakehttpFakeHTTPMixin.unfakehttpw   s    %)%;%;"r   )rd   NF)rG   rH   rI   rJ   r^   rh   rK   r%   r   r   r`   r`   q   s    5
<r   r`   c                        \ rS rSrS rS rSrg)FakeFTPMixin{   c                      " S S[         5      n[        R                  R                  U l        U[        R                  l        g )Nc                   .    \ rS rSr  SS jrS rS rSrg),FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapper}   Nc                     g r+   r%   )r-   userpasswdhostportdirstimeout
persistents           r   __init__5FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapper.__init__~   s    r   c                 0    [         R                  " 5       S4$ )Nr   )r:   r;   )r-   filerS   s      r   retrfile5FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapper.retrfile   s    zz|Q&r   c                     g r+   r%   rE   s    r   rD   2FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapper.close   rY   r   r%   )NT)rG   rH   rI   rJ   rz   r~   rD   rK   r%   r   r   FakeFtpWrapperrp   }   s    HL $'r   r   )objectr   r   
ftpwrapper_ftpwrapper_class)r-   r   s     r   fakeftpFakeFTPMixin.fakeftp|   s.    		V 		 "(!:!:$2!r   c                 B    U R                   [        R                  l        g r+   )r   r   r   r   rE   s    r   	unfakeftpFakeFTPMixin.unfakeftp   s    $($:$:!r   )r   N)rG   rH   rI   rJ   r   r   rK   r%   r   r   rl   rl   {   s    3;r   rl   c                   x    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rSrg)urlopen_FileTests   zTest urlopen() opening a temporary file.

Try to test as much functionality as possible so as to cut down on reliance
on connecting to the Net for testing.

c                    [        SU R                  R                  -  S5      U l        [	        [
        R                  S5      n UR                  U R                  5        UR                  5         [
        R                  U l	        [        R                  R                  [        R                  " U R                  5      5      U l        [!        SU R                  -  5      U l        g ! UR                  5         f = f)Nztest_urllib: %s
asciiwbfile:%s)bytes	__class__rG   textr   r   TESTFNwriterD   pathnamer   parsequoteosfsencodequoted_pathnamer!   returned_obj)r-   fs     r   setUpurlopen_FileTests.setUp   s    -0G0GG!#	!!4(	GGDIIGGI!((%||11"++dmm2LM#I0D0D$DE GGIs   C$ $C6c                     U R                   R                  5         [        R                  " [        R
                  5        g)zShut down the open objectN)r   rD   r   remover   r   rE   s    r   tearDownurlopen_FileTests.tearDown   s&    !
		)""#r   c                 N    S H  nU R                  U R                  U5        M!     g )N)	r<   r@   	readlinesfilenorD   infogeturlgetcode__iter__)assertHasAttrr   r-   attrs     r   test_interface urlopen_FileTests.test_interface   s&    GDt00$7Gr   c                 l    U R                  U R                  U R                  R                  5       5        g r+   )assertEqualr   r   r<   rE   s    r   	test_readurlopen_FileTests.test_read   s%    D$5$5$:$:$<=r   c                     U R                  U R                  U R                  R                  5       5        U R                  SU R                  R                  5       S5        g )Nr   zKcalling readline() after exhausting the file did not return an empty string)r   r   r   r@   rE   s    r   test_readlineurlopen_FileTests.test_readline   sK    D$5$5$>$>$@Ad//88:3	4r   c                     U R                   R                  5       nU R                  [        U5      SS5        U R                  US   U R                  S5        g )Nr   z.readlines() returned the wrong number of linesr   z"readlines() returned improper text)r   r   r   r   r   )r-   
lines_lists     r   test_readlines urlopen_FileTests.test_readlines   sM    &&002
Z!I	KA		=	?r   c                     U R                   R                  5       nU R                  U[        S5        U R	                  [
        R                  " U[        U R                  5      5      U R                  S5        g )Nzfileno() did not return an intzTReading on the file descriptor returned by fileno() did not return the expected text)	r   r   assertIsInstanceintr   r   r<   r   r   )r-   file_nums     r   test_filenourlopen_FileTests.test_fileno   sW    $$++-h-MN3tyy>:DII<	=r   c                 8    U R                   R                  5         g r+   )r   rD   rE   s    r   
test_closeurlopen_FileTests.test_close   s     	!r   c                     U R                  U R                  R                  [        R                  R
                  5        g r+   )r   r   headersemailmessageMessagerE   s    r   test_headersurlopen_FileTests.test_headers   s(    d//779N9NOr   c                 d    U R                  U R                  R                  U R                  5        g r+   )r   r   r   r   rE   s    r   test_urlurlopen_FileTests.test_url   s$    **..0D0DEr   c                 N    U R                  U R                  R                  5        g r+   )assertIsNoner   statusrE   s    r   test_statusurlopen_FileTests.test_status   s    $++223r   c                     U R                  U R                  R                  5       [        R                  R
                  5        g r+   )r   r   r   r   r   r   rE   s    r   	test_infourlopen_FileTests.test_info   s+    d//4468M8MNr   c                 l    U R                  U R                  R                  5       U R                  5        g r+   )r   r   r   r   rE   s    r   test_geturlurlopen_FileTests.test_geturl   s'    **113T5I5IJr   c                 V    U R                  U R                  R                  5       5        g r+   )r   r   r   rE   s    r   test_getcodeurlopen_FileTests.test_getcode   s    $++3356r   c                 `    U R                    H  nU R                  XR                  5        M      g r+   )r   r   r   )r-   lines     r   	test_iterurlopen_FileTests.test_iter   s&     %%DT99- &r   c                 |    U R                  [        [        R                  R                  SU R
                  -   5        g )Nz./)assertRaises
ValueErrorr   r   r!   r   rE   s    r   test_relativelocalfile(urlopen_FileTests.test_relativelocalfile   s'    *V^^%;%;D4==<PQr   )r   r   r   r   N)rG   rH   rI   rJ   __doc__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rK   r%   r   r   r   r      s]    F$
8>4?="
PF4OK7.Rr   r   c                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)

ProxyTests   c                     U R                  [        R                  " 5       5      U l        [	        [
        R                  5       H4  nSUR                  5       ;   d  M  U R                  R                  U5        M6     g )Nproxy)	enterContextr   EnvironmentVarGuardenvlistr   environlowerunset)r-   ks     r   r   ProxyTests.setUp   sN    $$Y%B%B%DEbjj!A!'')#q! "r   c                    U R                   R                  SS5        [        R                  R	                  5       nU R                  SUS   5        U R                   R                  SS5        U R                  [        R                  R                  S5      5        U R                  [        R                  R                  S5      5        U R                  [        R                  R                  S5      5        g )NNO_PROXY	localhostno0localhost, anotherdomain.com, newdomain.com:1234anotherdomain.comanotherdomain.com:8888newdomain.com:1234)r   setr   r   getproxies_environmentr   
assertTrueproxy_bypass_environmentr-   r   s     r   +test_getproxies_environment_keep_no_proxies6ProxyTests.test_getproxies_environment_keep_no_proxies   s    Z-..779gdm4Z!ST??@STU??@XYZ??@TUVr   c                     U R                   R                  SS5        [        R                  R	                  5       nU R                  SUS   5        U R                   R                  SS5        [        R                  R	                  5       nU R                  SU5        U R                   R                  S5        U R                   R                  S5        g ! U R                   R                  S5        U R                   R                  S5        f = f)N
HTTP_PROXYhttp://somewhere:3128r[   REQUEST_METHODGET)r   r   r   r   r   r   assertNotInr   r  s     r   test_proxy_cgi_ignore ProxyTests.test_proxy_cgi_ignore   s    		)HHLL'>?nn;;=G4gfoFHHLL)51nn;;=GVW-HHNN+,HHNN<( HHNN+,HHNN<(s   BC 8Dc                    [         R                  R                  nU R                  R	                  SS5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S	5      5        U R                  U" S
5      5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S5      5        g )Nr   z8localhost, anotherdomain.com, newdomain.com:1234, .d.o.tr   	LocalHost	LOCALHOSTz
.localhostr   z.newdomain.com:1234z	foo.d.o.tzd.o.tr   z.anotherdomain.com:8888zwww.newdomain.com:1234prelocalhostnewdomain.comznewdomain.com:1235r   r   r   r   r   r   assertFalser-   bypasss     r   (test_proxy_bypass_environment_host_match3ProxyTests.test_proxy_bypass_environment_host_match  s    88ZO	Q{+,{+,{+,|,-345456{+,w(78989:789/001 456r   c                    [         R                  R                  nU R                  R	                  SS5        U R                  U" S5      5        U R                  U" S5      5        U R                  R	                  SS5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S5      5        g )Nr   *r  r   z*, anotherdomain.comr   r  r  s     r   *test_proxy_bypass_environment_always_match5ProxyTests.test_proxy_bypass_environment_always_match  s    88Z%/0345Z!7823401 456r   c                     [         R                  R                  nU R                  R	                  SS5        U R                  U" S5      5        U R                  U" S5      5        U R                  U" S5      5        g )Nr   r   z
localhost
zanotherdomain.com:8888
znewdomain.com:1234
)r   r   r   r   r   r  r  s     r   %test_proxy_bypass_environment_newline0ProxyTests.test_proxy_bypass_environment_newline(  sb    88ZG	I./ :;< 678r   )r   N)rG   rH   rI   rJ   r   r  r
  r  r  r  rK   r%   r   r   r   r      s!    "	W
)7&79r   r   c                   &    \ rS rSrS rS rS rSrg)ProxyTests_withOrderedEnvi1  c                 j    [         R                  U l        [        R                  " 5       [         l        g r+   )r   r   
_saved_envcollectionsOrderedDictrE   s    r   r   ProxyTests_withOrderedEnv.setUp3  s    ** ,,.
r   c                 .    U R                   [        l        g r+   )r!  r   r   rE   s    r   r   "ProxyTests_withOrderedEnv.tearDown9  s    __
r   c                 ~   S[         R                  S'   S[         R                  S'   U R                  [        R                  R                  S5      5        U R                  [        R                  R                  S5      5        S[         R                  S'   S[         R                  S'   [        R                  R                  5       nU R                  0 U5        S	[         R                  S'   S
[         R                  S'   U R                  [        R                  R                  S5      5        U R                  [        R                  R                  S5      5        U R                  [        R                  R                  S5      5        U R                  [        R                  R                  S5      5        U R                  [        R                  R                  S5      5        S[         R                  S'   S[         R                  S'   [        R                  R                  5       nU R                  SUS   5        g )N no_proxyr   No_Proxy	arbitrary
http_proxyr  r  z%localhost, noproxy.com, my.proxy:1234zxyz.comznoproxy.com:5678zmy.proxy:1234zmy.proxyzhttp://somewhereelse:3128
Http_Proxyr[   )	r   r   r  r   r   r   r   r   r   r  s     r   ,test_getproxies_environment_prefer_lowercaseFProxyTests_withOrderedEnv.test_getproxies_environment_prefer_lowercase<  s   !#

:!,

:@@MN@@MN#%

< #:

< ..779W%!H

:!*

:??LM??@RST??PQ@@LM@@MN#:

< #>

< ..7790'&/Br   )r!  N)rG   rH   rI   rJ   r   r   r.  rK   r%   r   r   r  r  1  s    /%Cr   r  c                      \ rS rSrSrS rS rS r\R                  " \
S5      S 5       r\R                  " \
S5      S 5       r\R                  " \
S5      S	 5       r\R                  " \
S5      S
 5       rS rS rS rS rS rS rS rS rS rS rS r\R6                  " \R:                  SS5      S 5       rS rS r S r!Sr"g)urlopen_HttpTestsiU  z.Test urlopen() opening a fake http connection.c                    U R                  SU-   S-   5         [        S5      nU R                  UR                  5       S5        U R                  UR                  5       S5        U R                  UR	                  5       S5        U R                  UR                  5       S5        U R                  5         g ! U R                  5         f = f)Ns   HTTP/s    200 OK

Hello!http://python.org/   Hello!r      r^   r!   r   r@   r   r   rh   )r-   verfps      r   
check_readurlopen_HttpTests.check_readX  s    hn'??@	-.BR[[]I6R[[]C0RYY[*>?RZZ\3/OODOOs   BB5 5Cc                     SnU R                  S5         [        R                  R                  U5      nU R	                  UR                  5       U5        U R                  5         g ! U R                  5         f = f)Nz-http://docs.python.org/library/urllib.html#OK   HTTP/1.1 200 OK

Hello!)r^   r   r   r!   r   r   rh   )r-   r   r8  s      r   test_url_fragment#urlopen_HttpTests.test_url_fragmentc  sX    =67	'',BRYY[#.OODOOs   ?A% %A7c                     U R                  S5         [        S5      nU R                  UR                  R                  5        U R                  5         g ! U R                  5         f = f)Nr<  http://www.python.org)r^   r!   r   r8  
will_closerh   )r-   resps     r   test_willclose urlopen_HttpTests.test_willclosem  sJ    67	23DOODGG../OODOOs   0A A&zssl module requiredc                    [        [        SS5      5      S/-    GH  n[        U5      nSU S3nU R                  S5         [	        U5      R                  SS5      n[        R                  R                  nU R                  US	U 35         [        R                  R                  S
U 35        S S S 5        U R                  US	U 35         [        R                  R                  SU 35        S S S 5        [        S
U 35      nU R                  X&R                  5       5        U R                  5         GM     g ! , (       d  f       N= f! , (       d  f       Nb= f! U R                  5         f = f)Nr   !      z//localhost:7777/test/   HTTP/1.1 200 OK

Hello.\\\contain control.*http:https:)r   rangechrr^   reprreplacer[   r\   
InvalidURLassertRaisesRegexr   r   r!   r	  r   rh   )r-   char_nor   schemeless_urlescaped_char_reprrS  rB  s          r   (test_url_path_with_control_char_rejected:urlopen_HttpTests.test_url_path_with_control_char_rejectedu  sF   E!TN+tf4Gw<D4TF!<NMM:;" %)J$6$6tU$C!![[33
++"34E3F GINN**U>2B+CDI ++"34E3F GINN**VN3C+DEI ~&678  {{}5!/ 5I II I !s=   A
E#D9.E#E
.5E9
E	E

E	EE-c                    U R                  S5        SnSU-   S-   n [        R                  R                  nU R	                  US5         [
        R                  R                  SU 35        S S S 5        U R	                  US5         [
        R                  R                  SU 35        S S S 5        [        SU 35      nU R                  S	UR                  5       5        U R                  S
UR                  5       5        U R                  SUR                  5       5        U R                  5         g ! , (       d  f       N= f! , (       d  f       N= f! U R                  5         f = f)NrI  z:localhost:7777?a=1 HTTP/1.1
X-injected: header
TEST: 123//:8080/test/?test=az*contain control.*\\r.*(found at least . .)rM  contain control.*\\nrN   
)r^   r[   r\   rS  rT  r   r   r!   r	  r   rh   )r-   ru   rV  rS  rB  s        r   4test_url_path_with_newline_header_injection_rejectedFurlopen_HttpTests.test_url_path_with_newline_header_injection_rejected  s%   67O';;	 //J''IK&&~.>'?@K ''
4KL&&/?'@A M U>"234DS$++-0T4;;=1T4;;=1OOK K ML OOs<   ,E 	#D0,E #E)A6E 0
D>:E 
EE E$c                 2   [        [        SS5      5      S/-    H  n[        U5      nSU S3nU R                  S5         [	        U5      R                  SS5      n[        R                  R                  nU R                  US	U 35         [        S
U 35        S S S 5        U R                  US	U 35         [        SU 35        S S S 5        U R                  5         M     g ! , (       d  f       NO= f! , (       d  f       N4= f! U R                  5         f = f)Nr   rF  rG  z//localhostz/test/rI  rJ  rK  rL  rM  rN  )r   rO  rP  r^   rQ  rR  r[   r\   rS  rT  r!   rh   )r-   rU  r   rV  rW  rS  s         r   (test_url_host_with_control_char_rejected:urlopen_HttpTests.test_url_host_with_control_char_rejected  s   E!TN+tf4Gw<D*4&7NMM:;	"$(J$6$6tU$C!![[33
++"34E3F GIeN#345I ++J:KL]K^8_`f^$456 a ! 5I I a` !s=    A
D
C"D6C3D"
C0	,D3
D	=DDc                    U R                  S5        SnSU-   S-   n [        R                  R                  nU R	                  US5         [        SU 35        S S S 5        U R	                  US5         [        SU 35        S S S 5        U R                  5         g ! , (       d  f       NH= f! , (       d  f       N0= f! U R                  5         f = f)	NrI  zlocalhost
X-injected: header
r[  r\  zcontain control.*\\rrM  r]  rN  )r^   r[   r\   rS  rT  r!   rh   )r-   ru   rV  rS  s       r   4test_url_host_with_newline_header_injection_rejectedFurlopen_HttpTests.test_url_host_with_newline_header_injection_rejected  s    674';;	//J''35%/015 ''
4KL& 012 M OO5 5 ML OOs;   ,B< 	BB< 2B+B< 
B($B< +
B95B< <Cc                 &    U R                  S5        g )Ns   0.9r9  rE   s    r   test_read_0_9urlopen_HttpTests.test_read_0_9  s     	r   c                 &    U R                  S5        g )Ns   1.0rj  rE   s    r   test_read_1_0urlopen_HttpTests.test_read_1_0      r   c                 &    U R                  S5        g )Ns   1.1rj  rE   s    r   test_read_1_1urlopen_HttpTests.test_read_1_1  rp  r   c                 h   U R                  SSS9   U R                  [        R                  R                  5       n[        R
                  R                  S5        S S S 5        WR                  R                  5         U R                  5         g ! , (       d  f       N9= f! U R                  5         f = f)Ns   HTTP/1.1 401 Authentication Required
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Connection: close
Content-Type: text/html; charset=iso-8859-1
Trc   r3  )
r^   r   r   error	HTTPErrorr   r!   	exceptionrD   rh   )r-   cms     r   test_read_bogus!urlopen_HttpTests.test_read_bogus  s     
  	 		""6<<#9#9:b&&';< ;LL OO	 ;: OOs"   )B  B"B 
BB B1c                 n   U R                  SSS9   SnU R                  [        R                  R                  U5       n[        R
                  R                  S5        S S S 5        WR                  R                  5         U R                  5         g ! , (       d  f       N9= f! U R                  5         f = f)Ns   HTTP/1.1 302 Found
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Location: file://guidocomputer.athome.com:/python/license
Connection: close
Content-Type: text/html; charset=iso-8859-1
Trc   zRedirection to url 'file:r3  )
r^   rT  r   ru  rv  r   r!   rw  rD   rh   )r-   msgrx  s      r   test_invalid_redirect'urlopen_HttpTests.test_invalid_redirect  s       	 		-C''(>(>D&&';< ELL OO	 ED OOs"   ,B"  B"B" 
BB" "B4c                    [        [        5       R                  5       H  nU R                  SSS9   U R	                  [
        R                  R                  5       n[
        R                  R                  S5        S S S 5        WR                  R                  5         U R                  5         M     g ! , (       d  f       N== f! U R                  5         f = f)Ns_   HTTP/1.1 302 Found
Location: file://guidocomputer.athome.com:/python/license
Connection: close
Trc   http://something)rO  r   maxtriesr^   r   r   ru  rv  r   r!   rw  rD   rh   )r-   irx  s      r   test_redirect_limit_independent1urlopen_HttpTests.test_redirect_limit_independent  s     ~'001AMM    "&&v||'='=>"NN**+=> ?""$! 2 ?> !s#   )C B2;"C2
C 	<CCc                     U R                  S5         U R                  [        [        S5        U R	                  5         g ! U R	                  5         f = f)Nr   r  )r^   r   OSErrorr!   rh   rE   s    r   test_empty_socket#urlopen_HttpTests.test_empty_socket  s=     	c	gw0BCOODOOs	   ? Ac                 4   U R                  [        R                  R                  5       n[	        S5        S S S 5        U R                  WR                  R                  5        U R                  UR                  R                  5        g ! , (       d  f       NY= f)Nz/file://localhost/a/file/which/doesnot/exists.py)	r   r   ru  URLErrorr!   r   rw  filenamereasonr-   es     r   test_missing_localfile(urlopen_HttpTests.test_missing_localfile  s_    v||445EF 6,,-**+ 65   B		
Bc                    [         R                  " 5       u  pSUR                  [        R                  R
                  S5      -   n U R                  [        R                  R                  U5      5        [        U5       nU R                  U5        S S S 5        [        R                  " U5        [        R                  " U5        U R                  [        R                  R                  U5      5        U R                  [        R                  R                  5         [        U5        S S S 5        g ! , (       d  f       N= f! [        R                  " U5        [        R                  " U5        f = f! , (       d  f       g = f)Nzfile://localhost/rH  )tempfilemkstemprR  r   pathsepr   existsr!   rD   unlinkr  r   r   ru  r  )r-   fdtmp_filetmp_fileurlfobjs        r   test_file_notexists%urlopen_HttpTests.test_file_notexists  s    ''))H,<,<RWW[[#,NN	 OOBGGNN845%% & HHRLIIh12v||445K  65 &% HHRLIIh55s0   9E ?D1E E31
D?;E .E03
Fc                 8   SnU R                  [        R                  R                  5       n[	        U5        S S S 5        U R                  WR                  R                  5        U R                  UR                  R                  5        g ! , (       d  f       NY= f)Nzftp:///path
r   r   ru  r  r!   r  rw  r  r   r  )r-   test_ftp_urlr  s      r   test_ftp_nohost!urlopen_HttpTests.test_ftp_nohost"  se    $v||445L! 6--.**+ 65s   B
Bc                 4   U R                  [        R                  R                  5       n[	        S5        S S S 5        U R                  WR                  R                  5        U R                  UR                  R                  5        g ! , (       d  f       NY= f)Nz.ftp://localhost/a/file/which/doesnot/exists.pyr  r  s     r   test_ftp_nonexisting&urlopen_HttpTests.test_ftp_nonexisting)  sa    v||445DE 6--.**+ 65r  MAXFTPCACHEr   c                    U R                  5          [        R                  R                  SSSS/ 5      [        R                  R                  S'   [        S5        U R                  5         g ! U R                  5         f = f)Nrs   passr      testzftp://localhost)r   r   r   r   ftpcacher!   r   rE   s    r   test_ftp_cache_pruning(urlopen_HttpTests.test_ftp_cache_pruning/  s]    	.4nn.G.GPVXcegik.lFNN##F+%&NNDNNs   A	A, ,A>c                    U R                  S5         [        S5      nU R                  UR                  5       S5        U R                  UR                  5       S5        U R                  UR	                  5       S5        U R                  UR                  5       S5        U R                  5         g ! U R                  5         f = f)N   HTTP/1.0 200 OK

Hello!zhttp://user:pass@python.org/r4  r   r5  r6  )r-   r8  s     r   test_userpass_inurl%urlopen_HttpTests.test_userpass_inurl8  s    67	78BR[[]I6R[[]C0RYY[*HIRZZ\3/OODOOs   BB/ /Cc                    U R                  S5         SnSR                  U5      n[        R                  R                  nS[        UR                  S5      5      R                  S5      -  n[        U5      nU R                  XCR                  R                  S5      5        U R                  UR                  5       S5        U R                  UR                  5       S5        U R                  UR                  5       U5        U R                  UR                  5       S	5        U R!                  5         g ! U R!                  5         f = f)
Nr  za b:c dzhttp://{}@python.org/zAuthorization: Basic %s
ASCIIzUTF-8r4  r   r5  )r^   formatr[   r\   r]   r	   encodedecoder!   assertInr,   r   r@   assertNotEqualr   r   rh   )r-   userpassr   fakehttp_wrapperauthorizationr8  s         r   test_userpass_inurl_w_spaces.urlopen_HttpTests.test_userpass_inurl_w_spacesC  s    67	 H)00:C#{{99:&xw'?@GGPQMBMM-)=)=)D)DW)MNR[[]I6R[[]C0		S1RZZ\3/OODOOs   DD2 2Ec                     [         R                  " S[        45         [        R                  R                  5         S S S 5        g ! , (       d  f       g = fNr(  )r   r#   r$   r   r   	URLopenerrE   s    r   test_URLopener_deprecation,urlopen_HttpTests.test_URLopener_deprecationV  s3    ++R0B,CDNN$$& EDDs   A
Ar%   N)#rG   rH   rI   rJ   r   r9  r=  rC  unittest
skipUnlesssslrX  ra  rd  rg  rk  rn  rr  ry  r}  r  r  r  r  r  r  r   r   r   r   r  r  r  r  rK   r%   r   r   r1  r1  U  s   8	 34" 5"4 34 52 34" 5"  34 5 
  "",!,, \\&..-3 4	&'r   r1  c                   N    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rSrg)urlopen_DataTestsi[  z"Test urlopen() opening a data URL.c                 
   U R                  [        R                  R                  5        SU l        SU l        SU l        SU l        SU l        U R                  [        R                  R                  U R                  5      5      U l        U R                  [        R                  R                  U R                  5      5      U l        U R                  [        R                  R                  U R                  5      5      U l        g )Nu   test data URLs :;,%=& ö Ä sU   PNG

   IHDR         {@   sRGB    IDATc```? 
o/    IENDB`zZdata:text/plain;charset=UTF-8,test%20data%20URLs%20%3A%3B%2C%25%3D%26%20%C3%B6%20%C3%84%20zPdata:text/plain;charset=ISO-8859-1;base64,dGVzdCBkYXRhIFVSTHMgOjssJT0mIPYgxCA%3Dzdata:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAIAAAB7
QOjdAAAAAXNSR0IArs4c6QAAAA9JREFUCNdj%0AYGBg%2BP//PwAGAQL%2BCm8 vHgAAAABJRU5ErkJggg%3D%3D%0A%20)
addCleanupr   r   
urlcleanupr   imagetext_urltext_url_base64	image_urlr   r!   text_url_resptext_url_base64_respimage_url_resprE   s    r   r   urlopen_DataTests.setUp^  s    112 ;	F 	
( 	 	. 	
 "..NN""4==13$($5$5NN""4#7#78%:!"//0F0Ft~~0VWr   c                 N    S H  nU R                  U R                  U5        M!     g )N)r<   r@   r   rD   r   r   r   r   )r   r  r   s     r   r    urlopen_DataTests.test_interface~  s&    GDt1148Gr   c                 L   U R                  U R                  R                  5       [        R                  R
                  5        U R                  U R                  R                  5       R                  5       SS/5        U R                  U R                  R                  5       S   [        [        U R                  5      5      5        [        R                  R                  S5      nU R                  UR                  5       R                  5       SS/5        UR!                  5         g )N)z
text/plainr(  )charsetz
ISO-8859-1zcontent-lengthzdata:,)r  zUS-ASCII)r   r  r   r   r   r   r   r  
get_paramsr  strr   r  r   r   r!   rD   )r-   rs     r   r   urlopen_DataTests.test_info  s    d005579N9NO22779DDF!:;	=,,1134DEDJJ 	"NN""8,,,.!89	;		r   c                 <   U R                  U R                  R                  5       U R                  5        U R                  U R                  R                  5       U R
                  5        U R                  U R                  R                  5       U R                  5        g r+   )r   r  r   r  r  r  r  r  rE   s    r   r   urlopen_DataTests.test_geturl  sp    ++224dmmD2299;  	",,335t~~Fr   c                     U R                  U R                  R                  5       R                  [	        U R                  R                  5       R                  5       5      S   5      U R                  5        g Nr  )r   r  r<   r  dictr   r  r   rE   s    r   test_read_text urlopen_DataTests.test_read_text  sZ    ++00299##((*5578CEFJii	Qr   c                     U R                  U R                  R                  5       R                  [	        U R                  R                  5       R                  5       5      S   5      U R                  5        g r  )r   r  r<   r  r  r   r  r   rE   s    r   test_read_text_base64'urlopen_DataTests.test_read_text_base64  sY    22779@@**//1<<>?	JLII	r   c                 l    U R                  U R                  R                  5       U R                  5        g r+   )r   r  r<   r  rE   s    r   test_read_image!urlopen_DataTests.test_read_image  s%    ,,113TZZ@r   c                 b    U R                  [        [        R                  R                  S5        g )Nzdata:text/plainr   r   r   r   r!   rE   s    r   test_missing_comma$urlopen_DataTests.test_missing_comma  s    *V^^%;%;<MNr   c                 b    U R                  [        [        R                  R                  S5        g )Nzdata:;base64,Cg=r  rE   s    r   test_invalid_base64_data*urlopen_DataTests.test_invalid_base64_data  s    *V^^%;%;<NOr   )r  r  r  r   r  r  r  r  N)rG   rH   rI   rJ   r   r   r   r   r   r  r  r  r  r  rK   r%   r   r   r  r  [  s9    ,X@9	GQ
AOPr   r  c                   ^    \ rS rSrSrS rS rS rSS jrS r	S r
S	 rS
 rS rS rS rSrg)urlretrieve_FileTestsi  z(Test urllib.urlretrieve() on local filesc                    U R                  [        R                  R                  5        / U l        U R                  [        R                  5        SU l         [        [        R                  S5      nUR                  U R                  5        UR                  5         UR                  5         g !    g = f! WR                  5         f !    f = f= f)Ns   testing urllib.urlretriever   )r  r   r   r  	tempFilesregisterFileForCleanUpr   r   r   r   r   rD   )r-   FILEs     r   r   urlretrieve_FileTests.setUp  s    112  	##I$4$451			(($/DJJtyy!JJLD Ds1   AB5 B. .B25C6CCC	Cc                 f    U R                    H  n[        R                  " U5        M     g !    M#  = fr+   )r  r   r   )r-   eachs     r   r   urlretrieve_FileTests.tearDown  s"    NND4 #Ds   +0c                     [         R                  R                  U5      nS[        R                  R                  U5      -  $ )Nz	file://%s)r   r  abspathr   r   pathname2url)r-   filePaths     r   constructLocalFileUrl+urlretrieve_FileTests.constructLocalFileUrl  s.    77??8,V^^88BBBr   c                 0   [         R                  " 5       u  p# U R                  U5        [        R                  " US5      nUR                  U5        UR                  5         UR                  5         U$ !    U$ = f! WR                  5         f !    f = f= f)zCreates a new temporary file containing the specified data,
registers the file for deletion during the test fixture tear down, and
returns the absolute path of the file.r   )r  r  r  r   fdopenr   rD   )r-   r   newFdnewFilePathnewFiles        r   createNewTempFile'urlretrieve_FileTests.createNewTempFile  s}    
 &--/	''4iit,GMM$MMO D Ds0   A	A< "A4 4A9<B=BBBBc                 :    U R                   R                  U5        g r+   )r  append)r-   fileNames     r   r  ,urlretrieve_FileTests.registerFileForCleanUp  s    h'r   c                    [         R                  R                  S[        R                  -  5      nU R                  US   [        R                  5        U R                  US   [        R                  R                  S5        g )Nr   r   r   zFdid not get an email.message.Message instance as second returned value)
r   r   urlretriever   r   r   r   r   r   r   )r-   results     r   
test_basic urlretrieve_FileTests.test_basic  sb     ++I	8H8H,HII$4$45fQi)>)>9	:r   c                 D   S[         R                  -  nU R                  U5        [        R                  R                  U R                  [         R                  5      U5      nU R                  XS   5        U R                  [        R                  R                  U5      S5        [        US5      n UR                  5       nUR                  5         UR                  5         U R                  U R                  U5        g !    N!= f! UR                  5         f !    f = f= f)N%s.2r   zcopy of the file was not maderb)r   r   r  r   r   r  r  r   r   r   r  r  r   r<   rD   r   )r-   second_tempr  r  r   s        r   	test_copyurlretrieve_FileTests.test_copy  s    y///##K0++D,F,F-*,Qi0{3 69 	:K&	99;DJJLD) D Ds0   2 D C? ?DDDDDDc                    ^  S/4U 4S jjnS[         R                  -  nT R                  U5        [        R                  R                  T R                  [         R                  5      X!5        g )Nr   c                    > TR                  U [        5        TR                  U[        5        TR                  U[        5        TR                  XS   5        US   S-   US'   g )Nr   r   )r   r   r   )block_countblock_read_size	file_sizecount_holderr-   s       r   
hooktester9urlretrieve_FileTests.test_reporthook.<locals>.hooktester  sW    !!+s3!!/37!!)S1[q/:*1o1LOr   r  )r   r   r  r   r   r  r  )r-   r  r  s   `  r   test_reporthook%urlretrieve_FileTests.test_reporthook  sV    NOS 	2 y///##K0""&&y'7'78	%r   c                    / nU4S jnU R                  5       n[        R                  R                  U R	                  U5      [
        R                  U5        U R                  [        U5      S5        U R                  US   S   S5        g )Nc                 *    UR                  XU45        g r+   r  r  r  r  _reports       r   r  Aurlretrieve_FileTests.test_reporthook_0_bytes.<locals>.hooktester      NNK)DEr   r   r   r   	r  r   r   r  r  r   r   r   r   r-   reportr  srcFileNames       r   test_reporthook_0_bytes-urlretrieve_FileTests.test_reporthook_0_bytes
  st    HN 	F,,.""4#=#=k#Jj	*Va(1q)r   c                 H   / nU4S jnU R                  S5      n[        R                  R                  U R	                  U5      [
        R                  U5        U R                  [        U5      S5        U R                  US   S   S5        U R                  US   S   S5        g )Nc                 *    UR                  XU45        g r+   r"  r#  s       r   r  Aurlretrieve_FileTests.test_reporthook_5_bytes.<locals>.hooktester  r&  r   s   xxxxxr   r      r   r'  r(  s       r   test_reporthook_5_bytes-urlretrieve_FileTests.test_reporthook_5_bytes  s     HN 	F,,X6""4#=#=k#Jj	*Va(1q)1q)r   c                    / nU4S jnU R                  SS-  5      n[        R                  R                  U R	                  U5      [
        R                  U5        U R                  [        U5      S5        U R                  US   S   S5        U R                  US   S   S5        U R                  US   S   S5        U R                  US   S   S5        g )	Nc                 *    UR                  XU45        g r+   r"  r#  s       r   r  Durlretrieve_FileTests.test_reporthook_8193_bytes.<locals>.hooktester(  r&  r      xi      r   r   r   i    r'  r(  s       r   test_reporthook_8193_bytes0urlretrieve_FileTests.test_reporthook_8193_bytes#  s     HN 	F,,TD[9""4#=#=k#Jj	*Va(1t,1t,1t,1t,r   )r  r   N)r   )rG   rH   rI   rJ   r   r   r   r  r  r  r  r  r  r+  r1  r8  rK   r%   r   r   r  r    s=    20C (:*$%	**-r   r  c                   $    \ rS rSrSrS rS rSrg)urlretrieve_HttpTestsi4  z5Test urllib.urlretrieve() using fake http connectionsc                    U R                  [        R                  R                  5        U R	                  S5        S nU R                  [        R                  R                  5          [        R                  R                  [        R                  US9  U R                  5          S S S 5        g ! U R                  5         f = f! , (       d  f       g = f)N   HTTP/1.1 200 OK
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Connection: close
Content-Length: 100
Content-Type: text/html; charset=iso-8859-1

FF
c                     g r+   r%   )par1par2par3s      r   _reporthookYurlretrieve_HttpTests.test_short_content_raises_ContentTooShortError.<locals>._reporthookD  s    r   )
reporthookr  r   r   r  r^   r   ru  ContentTooShortErrorr  r   TEST_HTTP_URLrh   )r-   rB  s     r   .test_short_content_raises_ContentTooShortErrorDurlretrieve_HttpTests.test_short_content_raises_ContentTooShortError7  s    112  		 v||@@A"**7+@+@6A + C ! BA
 ! BAs$   'C),B/C/CC
Cc                    U R                  [        R                  R                  5        U R	                  S5        U R                  [        R                  R                  5          [        R                  R                  [        R                  5        U R                  5          S S S 5        g ! U R                  5         f = f! , (       d  f       g = f)Nr=  rE  rE   s    r   Atest_short_content_raises_ContentTooShortError_without_reporthookWurlretrieve_HttpTests.test_short_content_raises_ContentTooShortError_without_reporthookN  s    112  	 v||@@A"**7+@+@A!	 BA !	 BAs$   $C&-B-C-B??C
Cr%   N)rG   rH   rI   rJ   r   rH  rK  rK   r%   r   r   r;  r;  4  s    ?"."r   r;  c                   N    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rSrg)QuotingTestsia  a)  Tests for urllib.quote() and urllib.quote_plus()

According to RFC 3986 (Uniform Resource Identifiers), to escape a
character you write it as '%' + <2 character US-ASCII hex value>.
The Python code of ``'%' + hex(ord(<character>))[2:]`` escapes a
character properly. Case does not matter on the hex letters.

The various character sets specified are:

Reserved characters : ";/?:@&=+$,"
    Have special meaning in URIs and must be escaped if not being used for
    their special meaning
Data characters : letters, digits, and "-_.!~*'()"
    Unreserved and do not need to be escaped; can be, though, if desired
Control characters : 0x00 - 0x1F, 0x7F
    Have no use in URIs so must be escaped
space : 0x20
    Must be escaped
Delimiters : '<>#%"'
    Must be escaped
Unwise : "{}|\^[]`"
    Must be escaped

c                    SR                  / SQ5      n[        R                  R                  U5      nU R	                  XSU< SU< 35        [        R                  R                  U5      nU R	                  XSU< SU< 35        g )Nr(  )ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
0123456789z_.-~using quote():  != using quote_plus(): )joinr   r   r   r   
quote_plus)r-   do_not_quoter  s      r   test_never_quoteQuotingTests.test_never_quote{  su    xx !) * ##L1v6BFK	M((6v:FO	Qr   c                 r    U R                  [        R                  R                  R                  S   S5        g )Nr   rH  )r   r   r   r   __defaults__rE   s    r   test_default_safeQuotingTests.test_default_safe  s'    ++88;SAr   c                    Sn[         R                  R                  XS9nU R                  XSU< SU< 35        [         R                  R	                  UUS9nU R                  XSU< SU< 35        [         R                  R                  USS9nU R                  XSU< SU< 35        [         R                  R                  SSS	S
9n[         R                  R                  SSSS
9nU R                  X2SU< SU< 35        [         R                  R                  SSSS
9n[         R                  R                  SSSS
9nU R                  X2SU< SU< 35        g )Nz<>saferS  rT  rU  s   <>u   aüblatin-1   ü)encodingra  r(     )r   r   r   r   rW  )r-   quote_by_defaultr  expects       r   	test_safeQuotingTests.test_safe  sY   ##$4#L)66FO	Q(()9.> ) @)6*F4	5 ##$45#A)66FO	Q ##Hyv#N##Hyr#J &*	+ ##Hyw#O##Hyr#J &*	+r   c                    [        S5       Vs/ s H  n[        U5      PM     nnUR                  S5        UR                  [        S5      5        SR                  U5      nU H  n[        R
                  R                  U5      nU R                  [        U5      USU< S[        U5      < SU< 35        [        R
                  R                  U5      nU R                  [        U5      USU< S	[        U5      < SU< 35        M     AS
nSn[        R
                  R                  U5      nU R                  XdSU< SU< 35        [        R
                  R                  U5      nU R                  XdSU< SU< 35        g s  snf )N    z<>#%"{}|\^[]`rG  r(  rS  z should be escaped to z, not rU  z should be escapes to zab[]cdz
ab%5B%5DcdrT  )
rO  rP  r  rV  r   r   r   r   r   rW  )r-   numshould_quoter   r  partial_quoteexpecteds          r   test_default_quoting!QuotingTests.test_default_quoting  sE    -2"I6ISCI6,-CH%ww|, D\\''-FYt_f #IdOV=> \\,,T2FYt_f #IdOV=> !  ##M266>G	I((76;CVL	N- 7s   Fc           
      H   [         R                  R                  S5      nU R                  U[	        S5      SU< S[	        S5      < 35        [         R                  R                  S5      nU R                  USSU-  5        SnUR                  S[	        S5      5      n[         R                  R                  U5      nU R                  X1SU< SU< 35        UR                  SS5      n[         R                  R                  U5      nU R                  X1SU< SU< 35        g )Nr^  rS  rT  +zusing quote_plus(): %r != +z
a b cd e frU  )r   r   r   r   r   rW  rR  )r-   r  givenrg  s       r   test_quoting_spaceQuotingTests.test_quoting_space  s     ##C(36<inM	O((-6?	AsIcN3##E*6<fE	GsC(((/;A6J	Lr   c                    U R                  [        R                  R                  S5      S5        U R                  [        R                  R                  SS5      S5        U R                  [        R                  R                  S5      S5        U R                  [        R                  R                  SS5      S5        g )Nzalpha+beta gammazalpha%2Bbeta+gammars  zalpha+beta+gammas   alpha+beta gamma   +)r   r   r   rW  rE   s    r   test_quoting_plusQuotingTests.test_quoting_plus  s    001CD-	/001CSI+	- 	001DE-	/ 	001CTJ+	-r   c                 L   SnSn[         R                  R                  U5      nU R                  X#SU< SU< 35        U R	                  [
        [         R                  R                  USS9  [         R                  R                  U5      nU R                  X#SU< SU< 35        g )N   ab%A2%D8ab%FFrS  rT  rb  rd  zusing quote_from_bytes(): )r   r   r   r   r   	TypeErrorquote_from_bytesr-   rt  rg  r  s       r   test_quote_bytesQuotingTests.test_quote_bytes  s    !##E*6<fE	G 	)V\\%7%7%. 	 	0 ..u5"F,	-r   c                 6   SnSn[         R                  R                  U5      nU R                  X#SU< SU< 35        [         R                  R                  US S S9nU R                  X#SU< SU< 35        SnSn[         R                  R                  USS9nU R                  X#SU< SU< 35        S	nS
n[         R                  R                  U5      nU R                  X#SU< SU< 35        S	nU R	                  [
        [         R                  R                  USS9  S	nSn[         R                  R                  USSS9nU R                  X#SU< SU< 35        S	nSn[         R                  R                  USSS9nU R                  X#SU< SU< 35        g )Nu   ¢Øabÿz%C2%A2%C3%98ab%C3%BFrS  rT  rd  errorsr}  rb  r~     漢字%E6%BC%A2%E5%AD%97z%3F%3FrR  z%26%2328450%3B%26%2323383%3Bxmlcharrefreplace)r   r   r   r   r   UnicodeEncodeErrorr  s       r   test_quote_with_unicode$QuotingTests.test_quote_with_unicode  s    '##E*6<fE	G ##ED#F6<fE	G !##EI#>6<fE	G %##E*6<fE	G ,fll.@.@%-6 	 	8 ##EI+4 $ 66<fE	G /##EI+> $ @6<fE	Gr   c                     SnSn[         R                  R                  USS9nU R                  X#SU< SU< 35        SnSn[         R                  R                  USS	S
9nU R                  X#SU< SU< 35        g )Nu   ¢Ø ÿz
%A2%D8+%FFrb  r~  rU  rT  u   ab漢字 cdzab%3F%3F+cdrR  r  )r   r   rW  r   r  s       r   test_quote_plus_with_unicode)QuotingTests.test_quote_plus_with_unicode  s    (((C;A6J	L $((09 ) ;;A6J	Lr   r%   N)rG   rH   rI   rJ   r   rY  r]  rh  rp  ru  ry  r  r  r  rK   r%   r   r   rN  rN  a  s;    2QB+:N8L&
-- (GTLr   rN  c                   N    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rSrg)UnquotingTestsi.  zoTests for unquote() and unquote_plus()

See the doc string for quoting_Tests for details on quoting and such.

c           	         / n[        S5       H  n[        [        U5      5      n[        U5      n[        R                  R                  U5      nU R                  XESU< SU< 35        [        R                  R                  U5      nU R                  XESU< SU< 35        UR                  U5        M     SR                  U5      nA[        R                  R                  U5      nU R                  UR                  S5      SSU-  5        g )	N   using unquote(): rT  using unquote_plus(): r(  r   r   z/using unquote(): not all characters escaped: %s)rO  r   rP  r   r   unquoter   unquote_plusr  rV  count)r-   escape_listrl  rt  rg  r  escape_strings          r   test_unquotingUnquotingTests.test_unquoting5  s    :Cc#h'EXF\\))%0FVV<BFKM\\..u5FVV$f./ u%  ,%%m4c*A &'	(r   c                     U R                  [        [        4[        R                  R
                  S 5        U R                  [        [        4[        R                  R
                  S5        g )Nr%   )r   r  AttributeErrorr   r   r  rE   s    r   #test_unquote_rejects_none_and_tuple2UnquotingTests.test_unquote_rejects_none_and_tupleJ  sD    9n5v||7K7KTR9n5v||7K7KRPr   c                    SnUn[         R                  R                  U5      nU R                  X#SU< SU< 35        SnUn[         R                  R                  U5      nU R                  X#SU< SU< 35        SnUn[         R                  R                  U5      nU R                  X#SU< SU< 35        Sn[	        US5      n[         R                  R                  U5      nU R                  X#SU< SU< 35        Sn[	        US5      n[         R                  R                  U5      nU R                  X#SU< SU< 35        Sn[	        US5      n[         R                  R                  U5      nU R                  X#SU< SU< 35        U R                  [        [        4[         R                  R
                  S 5        U R                  [        [        4[         R                  R
                  S5        g )	Nz%xabr  rT  z%xr   r   using unquote_to_bytes(): r%   )	r   r   r  r   r   unquote_to_bytesr   r  r  r  s       r   test_unquoting_badpercent(UnquotingTests.test_unquoting_badpercentN  s   %%e,"F*, 	-%%e,"F*, 	-%%e,"F*, 	- ug&..u5"F*, 	-ug&..u5"F*, 	-ug&..u5"F*, 	-9n5v||7T7TVZ[9n5v||7T7TVXYr   c                 ~    SnSn[         R                  R                  U5      nU R                  X#SU< SU< 35        g )Nz%Ab%eAs   r  rT  r   r   r  r   r  s       r   test_unquoting_mixed_case(UnquotingTests.test_unquoting_mixed_caser  s<    ..u5"F,	-r   c                    S[        S5      -  nSn[        R                  R                  U5      nU R	                  X#SU< SU< 35        [        R                  R                  U5      nU R	                  X#SU< SU< 35        g )Nzab%sdcabcdrS  rT  r  )r   r   r   r  r   r  r  s       r   test_unquoting_parts#UnquotingTests.test_unquoting_parts{  su     )C.(%%e,6<fE	G**51=CVL	Nr   c                    SnUn[         R                  R                  U5      nU R                  X#SU< SU< 35        UR	                  SS5      n[         R                  R                  U5      nU R                  X#SU< SU< 35        g )Nzare+there+spaces...r  rT  rs  r^  r  )r   r   r  r   rR  r  r  s       r   test_unquoting_plus"UnquotingTests.test_unquoting_plus  sz    %%%e,8>G	IsC(**51=CVL	Nr   c                    SnSn[         R                  R                  U5      nU R                  X#SU< SU< 35        [         R                  R                  S5      nSnU R                  X#SU< SU< 35        SnSn[         R                  R                  U5      nU R                  X#SU< SU< 35        S	nSn[         R                  R                  U5      nU R                  X#SU< SU< 35        g )
N"br%C3%BCckner_sapporo_20050930.docs   brückner_sapporo_20050930.docr  rT  	   漢%C3%BCs   漢üs   %A2%D8ab%FFr|  s	   %A2ab%FFr  r  s       r   test_unquote_to_bytes$UnquotingTests.test_unquote_to_bytes  s    48..u5"F,	- ..~>("F,	- "..u5"F,	-
  "..u5"F,	-r   c                 *   SnSn[         R                  R                  U5      nU R                  X#SU< SU< 35        [         R                  R                  US S S9nU R                  X#SU< SU< 35        [         R                  R                  SSS9nSnU R                  X#SU< SU< 35        S	nS
n[         R                  R                  U5      nU R                  X#SU< SU< 35        SnSn[         R                  R                  U5      nU R                  X#SU< SU< 35        [         R                  R                  USS9nU R                  X#SU< SU< 35        SnSn[         R                  R                  USS9nU R                  X#SU< SU< 35        [         R                  R                  S5      nSnU R                  X#SU< SU< 35        [         R                  R                  SSS9nSnU R                  X#SU< SU< 35        g )Nr  u   brückner_sapporo_20050930.docr  rT  r  zbr%FCckner_sapporo_20050930.docrb  r~  r  r  z%F3%B1u   �rR  )r  r(  ignorer  u   漢üu   漢%FCr   r   r  r   r  s       r   test_unquote_with_unicode(UnquotingTests.test_unquote_with_unicode  s   45%%e,8>G	I %%ed4%H8>G	I %%&G/8 & :58>G	I %%%e,8>G	I %%e,8>G	I %%eI%>8>G	I %%eH%=8>G	I %%n58>G	I
 %%kI%F8>G	Ir   c                 r   SnSn[         R                  R                  U5      nU R                  X#SU< SU< 35        SnSn[         R                  R                  U5      nU R                  X#SU< SU< 35        SnSn[         R                  R                  U5      nU R                  X#SU< SU< 35        g )	Ns   blueberryjamblueberryjamr  rT  s   blåbærsyltetøyu   blåbærsyltetøys   bl%c3%a5b%c3%a6rsyltet%c3%b8ju   blåbærsyltetøjr  r  s       r   test_unquoting_with_bytes_input.UnquotingTests.test_unquoting_with_bytes_input  s    %%e,8>G	I 70%%e,8>G	I 10%%e,8>G	Ir   r%   N)rG   rH   rI   rJ   r   r  r  r  r  r  r  r  r  r  rK   r%   r   r   r  r  .  s<    (*Q"ZH-
N
N->8ItIr   r  c                   `    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rSrg)urlencode_Testsi  zTests for urlencode()c                 (   / SQn[         R                  R                  U5      nU H!  nU R                  XTSU< SU< SU< 35        M#     U R	                  UR                  S5      SSU< SUR                  S5      < 35        UR                  S5      nXFS-
     nXFS-      nU R                  UR                  5       =(       a    UR                  5       SU< S	U< 35        U R	                  [        U5      S
SU< S[        U5      < SS
< 35        g)zHelper method for testing different input types.

'given' must lead to only the pairs:
    * 1st, 1
    * 2nd, 2
    * 3rd, 3

Test cannot assume anything about order.  Docs make no guarantee and
have possible dictionary input.

)z1st=1z2nd=2z3rd=3ztesting z: z not found in &r   z: expected 2 '&'s; got r   z%: '&' not located in proper place in    z#: unexpected number of characters: rT  N)
r   r   	urlencoder  r   r  indexr   isdigitr   )	r-   rt  	test_typeexpect_somewherer  ro  amp_locationon_amp_lefton_amp_rights	            r   help_inputtypeurlencode_Tests.help_inputtype  s     7''.(HMM(F#Xv78 ) 	c*A#V\\#%68	9 ||C(A-.Q./++-H,2F2F2H)	* 	Vk $S[+?	@r   c                 0    U R                  SSSS.S5        g )N123)1st2nd3rdzusing dict as input typer  rE   s    r   test_using_mapping"urlencode_Tests.test_using_mapping&  s    3c=6	8r   c                 ,    U R                  / SQS5        g )N))r  r  )r  r  )r  r  z*using sequence of two-item tuples as inputr  rE   s    r   test_using_sequence#urlencode_Tests.test_using_sequence+  s    FH	Jr   c                    SS0n[        S5      < S[        S5      < 3n[        R                  R                  U5      nU R	                  X#5        SS0nSn[        R                  R                  U5      nU R	                  X#5        g )Nr  =zkey namezA bunch of pluseszkey+name=A+bunch+of+pluses)r   r   r   r  r   r  s       r   test_quotingurlencode_Tests.test_quoting0  sq    S	%cNIcN;''.(/0-''.(r   c                    S/ SQ0nS[         R                  R                  [        / SQ5      5      -  n[         R                  R	                  U5      nU R                  X#5        [         R                  R	                  US5      nUS    H  nSU-  nU R                  X#5        M     U R                  UR                  S5      SSUR                  S5      -  5        g )Nsequence)r  r  r  zsequence=%sTr  r   zExpected 2 '&'s, got %s)r   r   rW  r  r  r   r  r  )r-   rt  rg  r  values        r   
test_dosequrlencode_Tests.test_doseq;  s    O,!8!8_9M!NN''.(''t4:&E"U*FMM&) ' 	c*A2V\\#5FF	Hr   c                     U R                  S[        R                  R                  0 5      5        U R                  S[        R                  R                  / 5      5        g r  r   r   r   r  rE   s    r   test_empty_sequence#urlencode_Tests.test_empty_sequenceH  s@    V\\33B78V\\33B78r   c                     U R                  S[        R                  R                  SS05      5        U R                  S[        R                  R                  SS 05      5        g )Nza=1ar   za=Noner  rE   s    r   test_nonstring_values%urlencode_Tests.test_nonstring_valuesL  sH     6 6Qx @A6<<#9#93+#FGr   c                 h   U R                  S[        R                  R                  SSS/0S5      5        U R                  S[        R                  R                  SS S/0S5      5        [        R
                  " SS/5      nU R                  S	[        R                  R                  SU0S5      5        g )
Nza=1&a=2r  r   r   Tz
a=None&a=a)r  r   )br   za=a&a=b)r   r   r   r  r"  r#  )r-   r   s     r   test_nonstring_seq_values)urlencode_Tests.test_nonstring_seq_valuesP  s    FLL$:$:C!Q=$$OP//tSk0BDI	K&&(';<//dTB	Dr   c                 :   SnSn[         R                  R                  USSS9nU R                  X#5        SnSn[         R                  R                  U5      nU R                  X#5        SnSn[         R                  R                  USS	9nU R                  X#5        g )
N)       Á%3F=%3Fr  rR  r  %C2%A0=%C3%81%A0=%C1rb  r~  r   r   r  r   r  s       r   test_urlencode_encoding'urlencode_Tests.test_urlencode_encodingX  s    '''	'R( ( ''.( (''	'B(r   c                 |   SnSn[         R                  R                  USSSS9nU R                  X#5        SnSn[         R                  R                  USSSS	9nU R                  X#5        SnS
n[         R                  R                  US5      nU R                  X#5        SnSn[         R                  R                  US5      nU R                  X#5        SnSn[         R                  R                  USSS9nU R                  X#5        SnSn[         R                  R                  USSS9nU R                  X#5        g )Nr  r  Tr  rR  )doseqrd  r  ))r  )r   r  z%3F=1&%3F=%3Fr  r  ))r  )*   r  z%C2%A0=42&%C2%A0=%C3%81r  rb  r~  z%A0=42&%A0=%C1r  r  s       r   test_urlencode_encoding_doseq-urlencode_Tests.test_urlencode_encoding_doseqk  s@   '''T18 ( L( - ''t18 ( L( ( ''t4(-*''t4( (''ti'H(-!''ti'H(r   c                 8   SnSn[         R                  R                  U5      nU R                  X#5        [         R                  R                  US5      nU R                  X#5        SnSn[         R                  R                  US5      nU R                  X#5        g )N)   $   $z%A0%24=%C1%24T))r  )r  r  z%A0%24=42&%A0%24=%C1%24r  r  s       r   test_urlencode_bytes$urlencode_Tests.test_urlencode_bytes  s    - ''.(''t4( 4*''t4(r   c                 T   Sn[         R                  R                  USS9nSnU R                  X25        Sn[         R                  R                  USSS9nSnU R                  X25        SnSn[         R                  R                  USSS9nU R                  X25        Sn[         R                  R                  USS	S
9nSnU R                  X25        SnSn[         R                  R                  USSS	S9nSnSn[         R                  R                  USSS	S
9nU R                  X25        g )Nr  z:$r`  z	%A0$=%C1$T)r  ra  ))r  )r     r  z%A0$=%C1$&%A0$=13&%A0$=42rb  )ra  rd  )r  ra  rd  r  )r-   rt  r  rg  s       r   &test_urlencode_encoding_safe_parameter6urlencode_Tests.test_urlencode_encoding_safe_parameter  s?   
 .''D'9(-''T'E( 9,''t$'?( .''D1: ( <(-''T1: ( < 9,''t$1: ( <(r   r%   N)rG   rH   rI   rJ   r   r  r  r  r  r  r  r  r  r  r  r  r  rK   r%   r   r   r  r    sH    @@8
J
	)H9HD)&#)J)&)r   r  c                      \ rS rSrSrS rS r\R                  " \	R                  S:H  S5      S 5       r\R                  " \	R                  S:H  S5      S	 5       r\R                  " \R                  S
5      S 5       r\R                  " \	R                  S:H  S5      S 5       r\R                  " \	R                  S:H  S5      S 5       r\R                  " \R                  S
5      S 5       rSrg)Pathname_Testsi  z&Test pathname2url() and url2pathname()c                 0   [         R                  R                  SSSS5      nSn[        R                  R                  U5      nU R                  X#SU< SU< 35        [        R                  R                  U5      nU R                  XSU< SU< 35        g )	Npartsofr  r  zparts/of/a/pathpathname2url() failed; rT  zurl2pathame() failed; )r   r  rV  r   r   r  r   url2pathname)r-   expected_pathexpected_urlr  s       r   r  Pathname_Tests.test_basic  s    WdC@(,,];v ,0	1 ,,\: -1	2r   c                    [         R                  R                  SSS5      nS[        R                  R                  S5      -  n[        R                  R                  U5      nU R                  X#SU< SU< 35        Un[        R                  R                  U5      nU R                  X#SU< SU< 35        [         R                  R                  SS	5      nS
[        R                  R                  S5      -  n[        R                  R                  U5      nU R                  X#SU< SU< 35        Sn[         R                  R                  SS5      n[        R                  R                  U5      nU R                  X#SU< SU< 35        g )Nneedszquot=ingherezneeds/%s/herer  rT  zurl2pathname() failed; z	make sureusing_quotez%s/using_quotezmake+sure/using_unquotez	make+sureusing_unquote)
r   r  rV  r   r   r   r   r  r   r  r  s       r   r  Pathname_Tests.test_quoting  sD    Wj&9 6<<#5#5j#AA,,U3 &*	+ ,,V4 &*	+ [-8!FLL$6$6{$CC,,U3 &*	+ *k?;,,U3 &*	+r   win32z#test specific to Windows pathnames.c                    [         R                  R                  nU R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S	5      S
5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R	                  [
        US5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S 5      S!5        U R                  U" S"5      S
5        U R                  U" S5      S5        U R                  U" S#5      S5        U R                  U" S$5      S5        / S%QnU H8  nU R                  U" [         R                  R                  U5      5      U5        M:     g )&Nz
\\?\C:\dirz	///C:/dirz\\?\unc\server\share\dirz//server/share/dirC:///C:C:\///C:/zC:\a\b.cz///C:/a/b.cz	C:\a\b.c\z///C:/a/b.c/z	C:\a\\b.cz///C:/a//b.cz	C:\a\b%#cz///C:/a/b%25%23cu   C:\a\béz///C:/a/b%C3%A9C:\foo\bar\spam.foo///C:/foo/bar/spam.foozXX:\z\folder\test\/folder/test/z\\folder\test\z//folder/test/z\\\folder\test\z///folder/test/z\\some\share\z//some/share/z\\some\share\a\b.cz//some/share/a/b.cu   \\some\share\a\b%#céz//some/share/a/b%25%23c%C3%A9zC:/a/b.cz
//?/C:/dirz//?/unc/server/share/dir)r  r"  r!  )r   r   r  r   r   IOErrorr  )r-   fnurlsr   s       r   test_pathname2url_win$Pathname_Tests.test_pathname2url_win  s    ^^((,-{;<=?STD7+FX.L)=9N+^<N+^<M*,>?N+->?457OP'2w/./A013CD235FG/0/B568LM:;=\]J7013GHL);7679MN* CR ; ;C @A3G r   z test specific to POSIX pathnamesc                 X   [         R                  R                  nU R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S	5        g )
NrH  z/a/b.cz//a/b.cz	////a/b.cz///a/b.cz
/////a/b.cz//////a/b.cz/a/b%#cz/a/b%25%23c)r   r   r  r   r-   r$  s     r   test_pathname2url_posix&Pathname_Tests.test_pathname2url_posix  s     ^^((C#&Hx0I4J6K-8I6r   zneed os_helper.FS_NONASCIIc                 *   [         R                  " 5       n[         R                  " 5       n[        R                  R                  [        R                  XS9nU R                  [        R                  R                  [        R                  5      U5        g Nr  )sysgetfilesystemencodinggetfilesystemencodeerrorsr   r   r   r   FS_NONASCIIr   r   r  r-   rd  r  r   s       r   test_pathname2url_nonascii)Pathname_Tests.test_pathname2url_nonascii   sb    ,,...0ll  !6!6 Y44Y5J5JKSQr   c                 j   [         R                  R                  nU R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S	5      S
5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R	                  [
        US5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S 5      S5        U R                  U" S!5      S"5        U R                  U" S#5      S5        U R                  U" S$5      S%5        U R                  U" S&5      S'5        / S(QnU H8  nU R                  U" [         R                  R                  U5      5      U5        M:     g ))Nz/C:/r  z///C|r  r  r  z/C|//zC:\\z
///C|/pathzC:\pathz
///C/test/z\C\test\z////C/test/z	\\C\test\zC:/path/to/filezC:\path\to\filezC:/path/to/file/zC:\path\to\file\zC:/path/to//filezC:\path\to\\filezC|/path/to/filez/C|/path/to/filez///C|/path/to/filez///C|/foo/bar/spam.foor   u   ///è|/z//server/path/to/filez\\server\path\to\filez////server/path/to/filez/////server/path/to/filez//localhost/C:/path/to/filez//localhost/C|/path/to/filez//localhost/path/to/filez\path\to\filez //localhost//server/path/to/filezC:/foo%2fbarz
C:\foo/barz//server/share/foo%2fbarz\\server\share\foo/bar)r  z	\C\test\\r   )r   r   r  r   r   r#  r  )r-   r$  pathsr  s       r   test_url2pathname_win$Pathname_Tests.test_url2pathname_win'  sm    ^^((FV,Gd+Gd+Hv.Gh/L):6L)=9M*O<-.0DE./1GH./1GH-.0DE./1EF013GH457OP'2}5346RS568TU679UV9:<PQ9:<PQ679KL>?A]^N+];679UV) DR ; ;D ABDI r   c                 (   [         R                  R                  nU R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        g )Nz/foo/barz	//foo/barz
///foo/barz////foo/barz//localhost/foo/bar)r   r   r  r   r)  s     r   test_url2pathname_posix&Pathname_Tests.test_url2pathname_posixQ  s{     ^^((J4K+6L):6M*K812J?r   c                    [         R                  " 5       n[         R                  " 5       n[        R                  nU R                  [        R                  R                  U5      [        R                  5        [        R                  R                  X1US9nU R                  [        R                  R                  U5      [        R                  5        g r-  )r.  r/  r0  r   r1  r   r   r   r  r   r   r2  s       r   test_url2pathname_nonascii)Pathname_Tests.test_url2pathname_nonascii[  s    ,,...0##44S99;P;PQll   G44S99;P;PQr   r%   N)rG   rH   rI   rJ   r   r  r  r  r  r.  platformr&  skipIfr*  r   r1  r3  r7  r:  r=  rK   r%   r   r   r  r    s!   02+6 0>@ H@ HD __S\\W,79797 ..0LMR NR 0>@&J@&JP __S\\W,79@9@ ..0LMR NRr   r  c                       \ rS rSrSrS rSrg)Utility_Testsid  z=Testcase to test the various utility functions in the urllib.c                 h    U R                  [        R                  R                  5       [        5        g)zATest the urllib.request.thishost utility function returns a tupleN)r   r   r   thishosttuplerE   s    r   test_thishostUtility_Tests.test_thishostg  s    fnn557?r   r%   N)rG   rH   rI   rJ   r   rF  rK   r%   r   r   rB  rB  d  s    G@r   rB  c                       \ rS rSrSrS r\R                  " \S9S 5       r	\R                  " \S9S 5       r
\R                  " \S9S 5       rSrg	)
URLopener_Testsil  z4Testcase to test the open method of URLopener class.c                 N    " S S[         R                  R                  5      n[        R                  " S[
        45         U R                  U" 5       R                  S5      S5        U R                  U" 5       R                  S5      S5        S S S 5        g ! , (       d  f       g = f)Nc                       \ rS rSrS rSrg)8URLopener_Tests.test_quoted_open.<locals>.DummyURLopenerip  c                     U$ r+   r%   r-   r   s     r   	open_spamBURLopener_Tests.test_quoted_open.<locals>.DummyURLopener.open_spamq      
r   r%   N)rG   rH   rI   rJ   rO  rK   r%   r   r   DummyURLopenerrL  p      r   rR  z8DummyURLopener style of invoking requests is deprecated.zspam://example/ /z//example/%20/z,spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/z'//c:|windows%/:=&?~#+!$,;'@()*[]|/path/)r   r   r  r   r#   r$   r   r   )r-   rR  s     r   test_quoted_open URLopener_Tests.test_quoted_openo  s    	V^^55 	 ++K"$% ^-22#%%57 ^-22>@9;% % %s    AB
B$)categoryc                    [         R                  " 5        n[        R                  " US9u  p#[        R
                  " U5        S[        R                  R                  U5      -   n[        R                  R                  5       R                  U5      u  pVU R                  [        R                  R                  U5      [        R                  R                  U5      5        S S S 5        g ! , (       d  f       g = f)N)dirzfile:)r   temp_dirr  r  r   rD   r   r   r  r  retriever   r  normcase)r-   tmpdirr  tmpfilefileurlr  _s          r   test_urlopener_retrieve_file,URLopener_Tests.test_urlopener_retrieve_file~  s    !V"**v6KBHHRL ; ;G DDG ..224==gFKHRWW--h79I9I'9RS "!!s   C
C))
C7c                 "   SnU R                  S5        U R                  U R                  5        [        R                  R                  5       R                  U5      u  p#U R                  [        R                  R                  U5      S   S5        g )Nzhttp://www.python.org/file.txtr<  r   z.txt)r^   r  rh   r   r   r  rZ  r   r   r  splitext)r-   r   r  r_  s       r   test_urlopener_retrieve_remote.URLopener_Tests.test_urlopener_retrieve_remote  sg    .67(nn..099#>))(3A6?r   c                 F    " S S[         R                  R                  5      nS H  nU R                  [        [         R                  R
                  U5        U R                  [        [         R                  R                  5       R                  U5        U R                  [        [         R                  R                  5       R                  U5        U R                  [        U" 5       R                  U5        U R                  [        U" 5       R                  U5        M     g )Nc                       \ rS rSrS rSrg)<URLopener_Tests.test_local_file_open.<locals>.DummyURLopeneri  c                     U$ r+   r%   rN  s     r   open_local_fileLURLopener_Tests.test_local_file_open.<locals>.DummyURLopener.open_local_file  rQ  r   r%   N)rG   rH   rI   rJ   rj  rK   r%   r   r   rR  rh    rS  r   rR  )zlocal_file://examplezlocal-file://example)r   r   r  r   r  r!   r   rZ  )r-   rR  r   s      r   test_local_file_open$URLopener_Tests.test_local_file_open  s    	V^^55 	 DCgv~~'='=sCgv~~'?'?'A'F'FLgv~~'?'?'A'J'JCPg~'7'<'<cBg~'7'@'@#F Dr   r%   N)rG   rH   rI   rJ   r   rT  r   ignore_warningsr$   r`  rd  rl  rK   r%   r   r   rI  rI  l  ss    >; $$.@AT BT $$.@A@ B@ $$.@A
G B
Gr   rI  c                   $    \ rS rSrSrS rS rSrg)RequestTestsi  z&Unit tests for urllib.request.Request.c                     [         R                  R                  nU" S5      nU R                  UR	                  5       S5        U" S0 5      nU R                  UR	                  5       S5        g )Nr@  r  POST)r   r   Requestr   
get_methodr-   rs  r   s      r   test_default_values RequestTests.test_default_values  s[    ..((12++-u5126++-v6r   c                    [         R                  R                  nU" SSS9nU R                  UR                  S5        U R                  UR                  5       S5        U" S0 SS9nU R                  UR                  S5        U R                  UR                  5       S5        U" SSS9nU R                  UR                  5       S5        SUl        U R                  UR                  5       S5        g )Nr@  HEAD)methodr  )r   r   rs  r   rz  rt  ru  s      r   test_with_method_arg!RequestTests.test_with_method_arg  s    ..((1&A0++-v612fE0++-v61%@++-u5++-v6r   r%   N)rG   rH   rI   rJ   r   rv  r{  rK   r%   r   r   rp  rp    s    077r   rp  __main__)NNrj   )8r   urllib.parser   urllib.requesturllib.errorhttp.clientr[   email.messager   r:   r  unittest.mockr   r  r   test.supportr   r   r   test.support.testcaser   r   r  ImportErrorr.  r  base64r	   r"  has_gethostnameSkipTestr   r   r!   r   r^   r   r`   rl   TestCaser   r   r  r1  r  r  r;  rN  r  r  r  rB  rI  rp  rG   mainr%   r   r   <module>r     s   A      	    " & ( 1 	     $$


9
:: 
& /,^<F <;6 ;(XR))? XRvD9"" D9N!C 1 1 !CHC'))=, C'LKP))? KP\H-H-- H-V*"H--} *"ZJL8$$ JLZRIX&& RIjA)h'' A)F\RX&& \R|@H%% @/GmX%6%6 /Gd78$$ 70 zMMO G5  
Cs   G. .G:9G: