Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 52.14.43.204
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_urllib.cpython-310.pyc
o

abP�@sVdZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZddlmZddlZzddlZWneyKdZYnwddlZddlZddlmZmZddlmZddlZd	d
�Zdad7dd�Zd
d�Z d8dd�Z!Gdd�de"�Z#Gdd�de"�Z$Gdd�de
j%�Z&Gdd�de
j%�Z'Gdd�de
j%�Z(Gdd�de
j%e#e$�Z)Gdd�de
j%�Z*Gd d!�d!e
j%�Z+Gd"d#�d#e
j%e#�Z,Gd$d%�d%e
j%�Z-Gd&d'�d'e
j%�Z.Gd(d)�d)e
j%�Z/Gd*d+�d+e
j%�Z0Gd,d-�d-e
j%�Z1Gd.d/�d/e#e
j%�Z2Gd0d1�d1e
j%�Z3Gd2d3�d3e
j%�Z4Gd4d5�d5e
j%�Z5e6d6k�r)e
�7�dSdS)9z;Regression tests for what was in Python 2's "urllib" module�N)�patch)�support)�	os_helper)�warnings_helper)�url2pathname�pathname2url)�	b64encodecCs4tt|��dd���}t|�dkrd|}d|S)z!Escape char as RFC 2396 specifies�N�z0%s�%)�hex�ord�upper�len)�charZhex_repr�r�9/usr/local/python-3.10/lib/python3.10/test/test_urllib.py�	hexescapesrcCsJ|durtjj|d�}n
tst�}|ant}|dur|�|�S|�||�S)z.urlopen(url [, data]) -> open file-like objectN)�proxies)�urllib�request�FancyURLopener�
_urlopener�open)�url�datarZopenerrrr�urlopen&s
rcCs<t�dtf��
tj��Wd�S1swYdS)Nz8FancyURLopener style of invoking requests is deprecated.)r�check_warnings�DeprecationWarningrrrrrrrr6s��$�rFcs:G�fdd�dtj��G��fdd�dtjj��|�_�S)Ncs@eZdZdZ�fdd�Zdd�Zd
dd�Zd
d	d
�Zdd�ZdS)zfakehttp.<locals>.FakeSocketr
cs
|�_dS�N)�buf��selfr��FakeHTTPConnectionrr�sendallAs
z$fakehttp.<locals>.FakeSocket.sendallc_s|jd7_|S)Nr
)�io_refs)r"�args�kwdsrrr�makefileDsz%fakehttp.<locals>.FakeSocket.makefileNcS�|jrdStj�||�S�N�)�closed�io�BytesIO�read)r"Zamtrrrr0H�z!fakehttp.<locals>.FakeSocket.readcSr*r+)r-r.r/�readline)r"�lengthrrrr2Mr1z%fakehttp.<locals>.FakeSocket.readlinecSs,|jd8_|jdkrtj�|�dSdS)Nr
r)r&r.r/�close�r"rrrr4Rs
�z"fakehttp.<locals>.FakeSocket.closer)	�__name__�
__module__�__qualname__r&r%r)r0r2r4rr#rr�
FakeSocket>s

r9cs,eZdZdZ�fdd�Z�rdd�ZdSdS)z$fakehttp.<locals>.FakeHTTPConnectionNcs�|j�|_|jt|�_dSr)�fakedata�sock�typeZfakesockr5)r9rr�connect\sz,fakehttp.<locals>.FakeHTTPConnection.connectcS�dSrrr5rrrr4e�z*fakehttp.<locals>.FakeHTTPConnection.close)r6r7r8r r=r4r)r9�
mock_closerrr$Ws�r$)r.r/�http�client�HTTPConnectionr:)r:r@r)r$r9r@r�fakehttp=srDc@seZdZddd�Zdd�ZdS)�
FakeHTTPMixinFcCs"t||d�}tjj|_|tj_dS)N�r@)rDrArBrC�_connection_class)r"r:r@Zfake_http_classrrrrDms
zFakeHTTPMixin.fakehttpcC�|jtj_dSr)rGrArBrCr5rrr�
unfakehttpr�zFakeHTTPMixin.unfakehttpN�F)r6r7r8rDrIrrrrrEls
rEc@seZdZdd�Zdd�ZdS)�FakeFTPMixincCs&Gdd�dt�}tjj|_|tj_dS)Nc@s*eZdZ		d	dd�Zdd�Zdd�ZdS)
z,FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapperNTcSr>rr)r"�user�passwd�host�port�dirs�timeoutZ
persistentrrr�__init__ysz5FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapper.__init__cSst��dfS)Nr)r.r/)r"�filer<rrr�retrfile}�z5FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapper.retrfilecSr>rrr5rrrr4�r?z2FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapper.close)NT)r6r7r8rSrUr4rrrr�FakeFtpWrapperxs
�rW)�objectrr�
ftpwrapper�_ftpwrapper_class)r"rWrrr�fakeftpws
zFakeFTPMixin.fakeftpcCrHr)rZrrrYr5rrr�	unfakeftp�rJzFakeFTPMixin.unfakeftpN)r6r7r8r[r\rrrrrLvsrLc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"S)#�urlopen_FileTestsz�Test 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.

    cCsptd|jjd�|_ttjd�}z|�|j�W|��n|��wtj|_	t
j�|j	�|_
td|j
�|_dS)Nztest_urllib: %s
�ascii�wb�file:%s)�bytes�	__class__r6�textrr�TESTFN�writer4�pathnamer�parse�quote�quoted_pathnamer�returned_obj)r"�frrr�setUp�s�zurlopen_FileTests.setUpcCs|j��t�tj�dS)zShut down the open objectN)rjr4�os�removerrdr5rrr�tearDown�s
zurlopen_FileTests.tearDowncC�&dD]}|�t|j|�d|�qdS)N)	r0r2�	readlines�filenor4�info�geturl�getcode�__iter__�/object returned by urlopen() lacks %s attribute)�
assertTrue�hasattrrj�r"�attrrrr�test_interface�����z urlopen_FileTests.test_interfacecCs|�|j|j���dSr)�assertEqualrcrjr0r5rrr�	test_read��zurlopen_FileTests.test_readcCs,|�|j|j���|�d|j��d�dS)Nr,zKcalling readline() after exhausting the file did not return an empty string)r~rcrjr2r5rrr�
test_readline�s�zurlopen_FileTests.test_readlinecCs4|j��}|�t|�dd�|�|d|jd�dS)Nr
z.readlines() returned the wrong number of linesrz"readlines() returned improper text)rjrqr~rrc)r"Z
lines_listrrr�test_readlines�s
��z urlopen_FileTests.test_readlinescCs:|j��}|�|td�|�t�|t|j��|jd�dS)Nzfileno() did not return an intzTReading on the file descriptor returned by fileno() did not return the expected text)	rjrr�assertIsInstance�intr~rmr0rrc)r"Zfile_numrrr�test_fileno�s

�zurlopen_FileTests.test_filenocCs|j��dSr)rjr4r5rrr�
test_close��zurlopen_FileTests.test_closecCs|�|jjtjj�dSr)r�rjZheaders�email�message�Messager5rrr�test_headers�r�zurlopen_FileTests.test_headerscCs|�|jj|j�dSr)r~rjrrir5rrr�test_url��zurlopen_FileTests.test_urlcCs|�|jj�dSr)�assertIsNonerj�statusr5rrr�test_status��zurlopen_FileTests.test_statuscCs|�|j��tjj�dSr)r�rjrsr�r�r�r5rrr�	test_info�szurlopen_FileTests.test_infocC�|�|j��|j�dSr)r~rjrtrir5rrr�test_geturl�r�zurlopen_FileTests.test_geturlcCs|�|j���dSr)r�rjrur5rrr�test_getcode��zurlopen_FileTests.test_getcodecCs|jD]	}|�||j�qdSr)rjr~rc)r"�linerrr�	test_iter�s
�zurlopen_FileTests.test_itercCs|�ttjjd|j�dS)Nz./)�assertRaises�
ValueErrorrrrrfr5rrr�test_relativelocalfile�sz(urlopen_FileTests.test_relativelocalfileN)r6r7r8�__doc__rlror|rr�r�r�r�r�r�r�r�r�r�r�r�rrrrr]�s$
	r]c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�
ProxyTestscCs6t��|_ttj�D]}d|��vr|j�|�q
dS)N�proxy)rZEnvironmentVarGuard�env�listrm�environ�lower�unset)r"�krrrrl�s
��zProxyTests.setUpcCs|j��|`dSr)r��__exit__r5rrrro�s
zProxyTests.tearDowncCsp|j�dd�tj��}|�d|d�|j�dd�|�tj�d��|�tj�d��|�tj�d��dS)N�NO_PROXY�	localhost�no�0localhost, anotherdomain.com, newdomain.com:1234�anotherdomain.com�anotherdomain.com:8888�newdomain.com:1234)r��setrr�getproxies_environmentr~rx�proxy_bypass_environment�r"rrrr�+test_getproxies_environment_keep_no_proxies�s
z6ProxyTests.test_getproxies_environment_keep_no_proxiesc	Cs�z5|j�dd�tj��}|�d|d�|j�dd�tj��}|�d|�W|j�d�|j�d�dS|j�d�|j�d�w)N�
HTTP_PROXY�http://somewhere:3128rAZREQUEST_METHOD�GET)r�r�rrr�r~�assertNotInr�r�rrr�test_proxy_cgi_ignores

�z ProxyTests.test_proxy_cgi_ignorecCs�tjj}|j�dd�|�|d��|�|d��|�|d��|�|d��|�|d��|�|d��|�|d	��|�|d
��|�|d��|�|d��|�|d
��|�|d��|�|d��|�|d��dS)Nr�z8localhost, anotherdomain.com, newdomain.com:1234, .d.o.tr�Z	LocalHostZ	LOCALHOSTz
.localhostr�z.newdomain.com:1234z	foo.d.o.tzd.o.tr�z.anotherdomain.com:8888zwww.newdomain.com:1234Zprelocalhost�
newdomain.comznewdomain.com:1235�rrr�r�r�rx�assertFalse�r"Zbypassrrr�(test_proxy_bypass_environment_host_match
s$�z3ProxyTests.test_proxy_bypass_environment_host_matchcCsntjj}|j�dd�|�|d��|�|d��|j�dd�|�|d��|�|d��|�|d��dS)Nr��*r�r�z*, anotherdomain.comr�r�r�rrr�*test_proxy_bypass_environment_always_match sz5ProxyTests.test_proxy_bypass_environment_always_matchcCsDtjj}|j�dd�|�|d��|�|d��|�|d��dS)Nr�r�z
localhost
zanotherdomain.com:8888
znewdomain.com:1234
)rrr�r�r�r�r�rrr�%test_proxy_bypass_environment_newline*s�z0ProxyTests.test_proxy_bypass_environment_newlineN)
r6r7r8rlror�r�r�r�r�rrrrr��s
r�c@s$eZdZdd�Zdd�Zdd�ZdS)�ProxyTests_withOrderedEnvcCstj|_t��t_dSr)rmr��
_saved_env�collections�OrderedDictr5rrrrl5szProxyTests_withOrderedEnv.setUpcCs|jt_dSr)r�rmr�r5rrrro;rVz"ProxyTests_withOrderedEnv.tearDowncCsdtjd<dtjd<|�tj�d��|�tj�d��dtjd<dtjd<tj��}|�i|�d	tjd<d
tjd<|�tj�d��|�tj�d��|�tj�d��|�tj�d
��|�tj�d��dtjd<dtjd<tj��}|�d|d�dS)N�Zno_proxyr�ZNo_ProxyZ	arbitraryZ
http_proxyr�r�z%localhost, noproxy.com, my.proxy:1234zxyz.comznoproxy.com:5678z
my.proxy:1234zmy.proxyzhttp://somewhereelse:3128Z
Http_ProxyrA)	rmr�r�rrr�r�r~rxr�rrr�,test_getproxies_environment_prefer_lowercase>s&









zFProxyTests_withOrderedEnv.test_getproxies_environment_prefer_lowercaseN)r6r7r8rlror�rrrrr�3sr�c@seZdZdZdd�Zdd�Zdd�Ze�e	d�d	d
��Z
e�e	d�dd��Ze�e	d�d
d��Ze�e	d�dd��Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Ze�ejd'd(�d)d*��Zd+d,�Zd-d.�Zd/d0�Z e�e	d�d1d2��Z!d3S)4�urlopen_HttpTestsz.Test urlopen() opening a fake http connection.cCst|�d|d�z+td�}|�|��d�|�|��d�|�|��d�|�|��d�W|��dS|��w)NsHTTP/s 200 OK

Hello!�http://python.org/�Hello!r,���rDrr~r2rtrurI)r"�ver�fprrr�
check_readZszurlopen_HttpTests.check_readcCsDd}|�d�ztj�|�}|�|��|�W|��dS|��w)Nz-http://docs.python.org/library/urllib.html#OK�HTTP/1.1 200 OK

Hello!)rDrrrr~rtrI)r"rr�rrr�test_url_fragmentes
z#urlopen_HttpTests.test_url_fragmentcCs:|�d�ztd�}|�|jj�W|��dS|��w)Nr��http://www.python.org)rDrrxr�Z
will_closerI)r"�resprrr�test_willcloseos

z urlopen_HttpTests.test_willclosezssl module requiredc	Csttdd��dgD]{}t|�}d|�d�}|�d�zet|��dd�}tjj}|�	|d	|����t
j�d
|���Wd�n1sEwY|�	|d	|����t
j�d|���Wd�n1sgwYtd
|���}|�
||���W|��q
|��wdS)Nr�!�z//localhost:7777/test�/�HTTP/1.1 200 OK

Hello.�\�\\�contain control.*�http:�https:)r��range�chrrD�repr�replacerArB�
InvalidURL�assertRaisesRegexrrrr�rtrI)r"�char_nor�schemeless_url�escaped_char_reprr�r�rrr�(test_url_path_with_control_char_rejectedws*

��
���z:urlopen_HttpTests.test_url_path_with_control_char_rejectedcCs�|�d�d}d|d}zhtjj}|�|d��tj�d|���Wd�n1s,wY|�|d��tj�d|���Wd�n1sKwYtd|���}|�d	|�	��|�d
|�	��|�d|�	��W|�
�dS|�
�w)Nr�z:localhost:7777?a=1 HTTP/1.1
X-injected: header
TEST: 123�//�:8080/test/?test=az*contain control.*\\r.*(found at least . .)r��contain control.*\\nr�� �
�
)rDrArBr�r�rrrr�rtrI)r"rOr�r�r�rrr�4test_url_path_with_newline_header_injection_rejected�s$
���zFurlopen_HttpTests.test_url_path_with_newline_header_injection_rejectedc	Cs�ttdd��dgD]h}t|�}d|�d�}|�d�zRt|��dd�}tjj}|�	|d	|����t
d
|���Wd�n1sCwY|�	|d	|����t
d|���Wd�n1scwYW|��q
|��wdS)Nrr�r�z//localhostz/test/r�r�r�r�r�r�)r�r�r�rDr�r�rArBr�r�rrI)r"r�rr�r�r�rrr�(test_url_host_with_control_char_rejected�s$

�����z:urlopen_HttpTests.test_url_host_with_control_char_rejectedcCs�|�d�d}d|d}zLtjj}|�|d��td|���Wd�n1s*wY|�|d��td|���Wd�n1sGwYW|��dSW|��dS|��w)	Nr�zlocalhost
X-injected: header
r�r�zcontain control.*\\rr�r�r�)rDrArBr�r�rrI)r"rOr�r�rrr�4test_url_host_with_newline_header_injection_rejected�s 
����zFurlopen_HttpTests.test_url_host_with_newline_header_injection_rejectedcC�|�d�dS)Ns0.9�r�r5rrr�
test_read_0_9�r�zurlopen_HttpTests.test_read_0_9cCr�)Ns1.0r�r5rrr�
test_read_1_0�rJzurlopen_HttpTests.test_read_1_0cCr�)Ns1.1r�r5rrr�
test_read_1_1�rJzurlopen_HttpTests.test_read_1_1cCs6|jddd�z|�ttd�W|��dS|��w)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
TrFr��rDr��OSErrorrrIr5rrr�test_read_bogus�s�z!urlopen_HttpTests.test_read_boguscCsr|jddd�z,d}|�tjj|��td�Wd�n1s!wYW|��dSW|��dS|��w)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
TrFzRedirection to url 'file:r�)rDr�r�error�	HTTPErrorrrI)r"�msgrrr�test_invalid_redirect�s�
��z'urlopen_HttpTests.test_invalid_redirectc	CsLtt�j�D]}|jddd�z|�tjjtd�W|�	�q|�	�wdS)Ns_HTTP/1.1 302 Found
Location: file://guidocomputer.athome.com:/python/license
Connection: close
TrF�http://something)
r�rZmaxtriesrDr�rr�r�rrI)r"�irrr�test_redirect_limit_independent�s���z1urlopen_HttpTests.test_redirect_limit_independentcCs2|�d�z|�ttd�W|��dS|��w)Nr,r�r�r5rrr�test_empty_sockets
z#urlopen_HttpTests.test_empty_socketcCsV|�tjj��}td�Wd�n1swY|�|jj�|�|jj�dS)Nz/file://localhost/a/file/which/doesnot/exists.py)	r�rr��URLErrorrrx�	exception�filename�reason�r"�errr�test_missing_localfiles

�z(urlopen_HttpTests.test_missing_localfilec	Cs�t��\}}d|�tjjd�}z.|�tj�|��t|��
}|�|�Wd�n1s.wYWt�	|�t�
|�nt�	|�t�
|�w|�tj�|��|�t
jj��
t|�Wd�dS1sjwYdS)Nzfile://localhost/r�)�tempfile�mkstempr�rm�path�seprx�existsrr4�unlinkr�r�rr�r�)r"�fdZtmp_fileZtmp_fileurlZfobjrrr�test_file_notexistss 
��

�
"�z%urlopen_HttpTests.test_file_notexistscCsZd}|�tjj��}t|�Wd�n1swY|�|jj�|�|jj	�dS)Nzftp:///path�
r�rr�r�rr�r�rrxr)r"Ztest_ftp_urlrrrr�test_ftp_nohost s
�z!urlopen_HttpTests.test_ftp_nohostcCsV|�tjj��}td�Wd�n1swY|�|jj�|�|jj	�dS)Nz.ftp://localhost/a/file/which/doesnot/exists.pyr
rrrr�test_ftp_nonexisting's

�z&urlopen_HttpTests.test_ftp_nonexistingZMAXFTPCACHErcCsF|��ztj�ddddg�tjjd<td�W|��dS|��w)NrM�passr���testzftp://localhost)r[rrrYZftpcacherr\r5rrr�test_ftp_cache_pruning-s

z(urlopen_HttpTests.test_ftp_cache_pruningcCsl|�d�z+td�}|�|��d�|�|��d�|�|��d�|�|��d�W|��dS|��w)N�HTTP/1.0 200 OK

Hello!zhttp://user:pass@python.org/r�r,r�r�)r"r�rrr�test_userpass_inurl6s
z%urlopen_HttpTests.test_userpass_inurlcCs�|�d�zLd}d�|�}tjj}dt|�d���d�}t|�}|�	||j
�d��|�|��d�|�|��d�|�
|��|�|�|��d	�W|��dS|��w)
Nrza b:c dzhttp://{}@python.org/zAuthorization: Basic %s
�ASCIIzUTF-8r�r,r�)rD�formatrArBrCr�encode�decoder�assertInr r~r2ZassertNotEqualrtrurI)r"ZuserpassrZfakehttp_wrapperZ
authorizationr�rrr�test_userpass_inurl_w_spacesAs

�z.urlopen_HttpTests.test_userpass_inurl_w_spacescCs>t�dtf��tj��Wd�dS1swYdS�Nr�)rrrrr�	URLopenerr5rrr�test_URLopener_deprecationTs"�z,urlopen_HttpTests.test_URLopener_deprecationc	Cs�t��}t�dtf��/|�t��tjj	dd|d�Wd�n1s%wYWd�dSWd�dS1s=wYdS)Nr�zhttps://localhostz/nonexistent/path)Zcafile�context)
�sslZcreate_default_contextrrrr�r�rrr)r"rrrr�test_cafile_and_contextXs���"�z)urlopen_HttpTests.test_cafile_and_contextN)"r6r7r8r�r�r�r��unittest�
skipUnlessr r�r�r�r�r�r�r�r�r�r�r�rrrrrrXrrrrrrr!rrrrr�Ws>









	

r�c@�XeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�urlopen_DataTestsz"Test urlopen() opening a data URL.cCs`|�tjj�d|_d|_d|_d|_d|_tj�	|j�|_
tj�	|j�|_tj�	|j�|_dS)Nutest data URLs :;,%=& ö Ä sU�PNG


IHDR{@��sRGB���IDAT�c```���?�
o/IEND�B`�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%3Dz�data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAIAAAB7
QOjdAAAAAXNSR0IArs4c6QAAAA9JREFUCNdj%0AYGBg%2BP//PwAGAQL%2BCm8 vHgAAAABJRU5ErkJggg%3D%3D%0A%20)
�
addCleanuprr�
urlcleanuprc�image�text_url�text_url_base64�	image_urlr�
text_url_resp�text_url_base64_resp�image_url_respr5rrrrles�����zurlopen_DataTests.setUpcCrp)N)r0r2rqr4rsrtrurvrw)rxryr,rzrrrr|�r}z urlopen_DataTests.test_interfacecCst|�|j��tjj�|�|j����ddg�|�|j	��dt
t|j���|�t
j�d�����ddg�dS)N)z
text/plainr�)�charsetz
ISO-8859-1zcontent-lengthzdata:,)r/zUS-ASCII)r�r,rsr�r�r�r~r-�
get_paramsr.�strrr(rrrr5rrrr��s���zurlopen_DataTests.test_infocCs@|�|j��|j�|�|j��|j�|�|j��|j�dSr)r~r,rtr)r-r*r.r+r5rrrr��s
�zurlopen_DataTests.test_geturlcC�0|�|j���t|j�����d�|j�dS�Nr/)r~r,r0r�dictrsr0rcr5rrr�test_read_text�s
��z urlopen_DataTests.test_read_textcCr2r3)r~r-r0rr4rsr0rcr5rrr�test_read_text_base64�s
��z'urlopen_DataTests.test_read_text_base64cCr�r)r~r.r0r(r5rrr�test_read_image�r�z!urlopen_DataTests.test_read_imagecC�|�ttjjd�dS)Nzdata:text/plain�r�r�rrrr5rrr�test_missing_comma�r�z$urlopen_DataTests.test_missing_commacCr8)Nzdata:;base64,Cg=r9r5rrr�test_invalid_base64_data��z*urlopen_DataTests.test_invalid_base64_dataN)
r6r7r8r�rlr|r�r�r5r6r7r:r;rrrrr%bs	r%c@sjeZdZdZdd�Zdd�Zdd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�urlretrieve_FileTestsz(Test urllib.urlretrieve() on local filescCs~|�tjj�g|_|�tj�d|_zt	tjd�}|�
|j�|��Wz|��WdSYdSz|��WwYw)Nstesting urllib.urlretriever_)r&rrr'�	tempFiles�registerFileForCleanUprrdrcrrer4)r"�FILErrrrl�s	
�
zurlretrieve_FileTests.setUpcCs(|jD]}zt�|�WqYqdSr)r>rmrn)r"Zeachrrrro�s

�zurlretrieve_FileTests.tearDowncCsDtj�|�}z|�d�Wntyt�d��wdtj�	|�S)Nzutf-8z!filePath is not encodable to utf8z	file://%s)
rmr�abspathr�UnicodeEncodeErrorr"ZSkipTestrrr)r"ZfilePathrrr�constructLocalFileUrl�s
�z+urlretrieve_FileTests.constructLocalFileUrlr,cCslt��\}}z#|�|�t�|d�}|�|�|��Wz|��W|SY|Sz|��WwYw)z�Creates 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_)rrr?rm�fdopenrer4)r"rZnewFdZnewFilePathZnewFilerrr�createNewTempFile�s


��
z'urlretrieve_FileTests.createNewTempFilecCs|j�|�dSr)r>�append)r"ZfileNamerrrr?�sz,urlretrieve_FileTests.registerFileForCleanUpcCs>tj�dtj�}|�|dtj�|�|dtjj	d�dS)Nr`rr
zFdid not get an email.message.Message instance as second returned value)
rr�urlretrieverrdr~r�r�r�r�)r"�resultrrr�
test_basic�s
�z urlretrieve_FileTests.test_basiccCs�dtj}|�|�tj�|�tj�|�}|�||d�|�t	j
�|�d�t|d�}z|�
�}|��Wz|��WqNYqNz|��WwYw|�|j|�dS)N�%s.2rzcopy of the file was not made�rb)rrdr?rrrGrCr~rxrmrr	rr0r4rc)r"�second_temprHr@rcrrr�	test_copy�s$


��


�
zurlretrieve_FileTests.test_copycsBdgf�fdd�	}dtj}��|�tj���tj�||�dS)NrcsH��|t���|t���|t���||d�|dd|d<dS)Nrr
)r�r�r~)�block_count�block_read_size�	file_sizeZcount_holderr5rr�
hooktesters
z9urlretrieve_FileTests.test_reporthook.<locals>.hooktesterrJ)rrdr?rrrGrC)r"rQrLrr5r�test_reporthooks


�z%urlretrieve_FileTests.test_reporthookcCsXg}|fdd�}|��}tj�|�|�tj|�|�t|�d�|�|ddd�dS)NcS�|�|||f�dSr�rF�rNrOrPZ_reportrrrrQr�zAurlretrieve_FileTests.test_reporthook_0_bytes.<locals>.hooktesterr
rr	�	rErrrGrCrrdr~r�r"�reportrQZsrcFileNamerrr�test_reporthook_0_bytess�z-urlretrieve_FileTests.test_reporthook_0_bytescCsng}|fdd�}|�d�}tj�|�|�tj|�|�t|�d�|�|ddd�|�|ddd�dS)NcSrSrrTrUrrrrQ$r�zAurlretrieve_FileTests.test_reporthook_5_bytes.<locals>.hooktestersxxxxxr	r�r
rVrWrrr�test_reporthook_5_bytess
�z-urlretrieve_FileTests.test_reporthook_5_bytescCs�g}|fdd�}|�dd�}tj�|�|�tj|�|�t|�d�|�|ddd�|�|ddd	�|�|ddd	�|�|ddd	�dS)
NcSrSrrTrUrrrrQ2r�zDurlretrieve_FileTests.test_reporthook_8193_bytes.<locals>.hooktester�xi �rr	r
i rVrWrrr�test_reporthook_8193_bytes-s�z0urlretrieve_FileTests.test_reporthook_8193_bytesN)r,)r6r7r8r�rlrorCrEr?rIrMrRrYr[r^rrrrr=�s
	r=c@� eZdZdZdd�Zdd�ZdS)�urlretrieve_HttpTestsz5Test urllib.urlretrieve() using fake http connectionsc	Cs~|�tjj�|�d�dd�}|�tjj��ztjjt	j
|d�W|��n|��wWd�dS1s8wYdS)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
cSr>rr)Zpar1Zpar2Zpar3rrr�_reporthookNr?zYurlretrieve_HttpTests.test_short_content_raises_ContentTooShortError.<locals>._reporthook)Z
reporthook�r&rrr'rDr�r��ContentTooShortErrorrGrZ
TEST_HTTP_URLrI)r"rbrrr�.test_short_content_raises_ContentTooShortErrorAs


�"�zDurlretrieve_HttpTests.test_short_content_raises_ContentTooShortErrorc	Csr|�tjj�|�d�|�tjj��z
tj�t	j
�W|��n|��wWd�dS1s2wYdS)Nrarcr5rrr�Atest_short_content_raises_ContentTooShortError_without_reporthookXs
	"�zWurlretrieve_HttpTests.test_short_content_raises_ContentTooShortError_without_reporthookN)r6r7r8r�rerfrrrrr`>sr`c@r$)�QuotingTestsauTests 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

    cCsVd�gd��}tj�|�}|�||d||f�tj�|�}|�||d||f�dS)Nr�)�ABCDEFGHIJKLMNOPQRSTUVWXYZ�abcdefghijklmnopqrstuvwxyz�
0123456789z_.-~�using quote(): %r != %r�using quote_plus(): %r != %r)�joinrrgrhr~�
quote_plus)r"Zdo_not_quoterHrrr�test_never_quote�s
�
�zQuotingTests.test_never_quotecCs|�tjjjdd�dS)Nrr�)r~rrgrh�__defaults__r5rrr�test_default_safe�szQuotingTests.test_default_safecCs�d}tjj||d�}|�||d||f�tjj||d�}|�||d||f�tjj|dd�}|�||d||f�tjjdddd	�}tjjddd
d	�}|�||d||f�tjjdddd	�}tjjddd
d	�}|�||d||f�dS)Nz<>��saferkrls<>uaüb�latin-1�ü)�encodingrsr���)rrgrhr~rn)r"Zquote_by_defaultrH�expectrrr�	test_safe�s>
����
�����zQuotingTests.test_safec	Cs�dd�td�D�}|�d�|�td��d�|�}|D].}tj�|�}|�t|�|d|t|�|f�tj�	|�}|�t|�|d|t|�|f�q~d	}d
}tj�|�}|�||d||f�tj�	|�}|�||d||f�dS)
NcSsg|]}t|��qSr)r�)�.0�numrrr�
<listcomp>�sz5QuotingTests.test_default_quoting.<locals>.<listcomp>� z
<>#%"{}|\^[]`r�r�z1using quote(): %s should be escaped to %s, not %sz6using quote_plus(): %s should be escapes to %s, not %szab[]cdz
ab%5B%5Dcdrkrl)
r�rFr�rmrrgrhr~rrn)r"Zshould_quoterrHZ
partial_quote�expectedrrr�test_default_quoting�s8

����
�
�z!QuotingTests.test_default_quotingcCs�tj�d�}|�|td�d|td�f�tj�d�}|�|dd|�d}|�dtd��}tj�|�}|�||d||f�|�dd�}tj�|�}|�||d||f�dS)Nr�rk�+zusing quote_plus(): %r != +z
a b cd e frl)rrgrhr~rrnr�)r"rH�givenrxrrr�test_quoting_space�s&��
�
�zQuotingTests.test_quoting_spacecCsX|�tj�d�d�|�tj�dd�d�|�tj�d�d�|�tj�dd�d�dS)Nzalpha+beta gammazalpha%2Bbeta+gammar�zalpha+beta+gammasalpha+beta gamma�+)r~rrgrnr5rrr�test_quoting_plus�s����zQuotingTests.test_quoting_pluscCsfd}d}tj�|�}|�||d||f�|jttjj|dd�tj�|�}|�||d||f�dS)N���ab��%A2%D8ab%FFrkrt�rvz"using quote_from_bytes(): %r != %r)rrgrhr~r��	TypeError�quote_from_bytes�r"r�rxrHrrr�test_quote_bytes�s
����zQuotingTests.test_quote_bytescCs(d}d}tj�|�}|�||d||f�tjj|ddd�}|�||d||f�d}d}tjj|dd�}|�||d||f�d}d	}tj�|�}|�||d||f�d}|jttjj|dd�d}d
}tjj|ddd�}|�||d||f�d}d}tjj|dd
d�}|�||d||f�dS)Nu¢Øabÿz%C2%A2%C3%98ab%C3%BFrk�rv�errorsr�rtr��漢字�%E6%BC%A2%E5%AD%97z%3F%3Fr�z%26%2328450%3B%26%2323383%3B�xmlcharrefreplace)rrgrhr~r�rBr�rrr�test_quote_with_unicode�sT
�
�
�
��
�
�
�
�z$QuotingTests.test_quote_with_unicodecCsbd}d}tjj|dd�}|�||d||f�d}d}tjj|ddd	�}|�||d||f�dS)
Nu¢Ø ÿz
%A2%D8+%FFrtr�rluab漢字 cdzab%3F%3F+cdr�r�)rrgrnr~r�rrr�test_quote_plus_with_unicode(s
�
�
�z)QuotingTests.test_quote_plus_with_unicodeN)
r6r7r8r�rorqryrr�r�r�r�r�rrrrrgks
*rgc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�UnquotingTestszwTests for unquote() and unquote_plus()

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

    cCs�g}td�D]3}tt|��}t|�}tj�|�}|�||d||f�tj�|�}|�||d||f�|�|�qd�	|�}~tj�|�}|�|�
d�dd|�|�tt
ftjjd�|�tt
ftjjd�dS)	N��using unquote(): %r != %r�using unquote_plus(): %r != %rr�rr
z/using unquote(): not all characters escaped: %sr)r�rr�rrg�unquoter~�unquote_plusrFrm�countr�r��AttributeError)r"Zescape_listr{r�rxrHZ
escape_stringrrr�test_unquoting?s2
���
��zUnquotingTests.test_unquotingcCs>d}|}tj�|�}|�||d||f�d}|}tj�|�}|�||d||f�d}|}tj�|�}|�||d||f�d}t|d�}tj�|�}|�||d||f�d}t|d�}tj�|�}|�||d||f�d}t|d�}tj�|�}|�||d||f�|�ttftjjd�|�ttftjjd�dS)Nz%xabr�z%xrr^�"using unquote_to_bytes(): %r != %rr)	rrgr�r~ra�unquote_to_bytesr�r�r�r�rrr�test_unquoting_badpercentVsL
�
�
�

�

�

�z(UnquotingTests.test_unquoting_badpercentcCs.d}d}tj�|�}|�||d||f�dS)Nz%Ab%eAs��r��rrgr�r~r�rrr�test_unquoting_mixed_casezs��z(UnquotingTests.test_unquoting_mixed_casecCsXdtd�}d}tj�|�}|�||d||f�tj�|�}|�||d||f�dS)Nzab%sd�cZabcdrkr�)rrrgr�r~r�r�rrr�test_unquoting_parts�s
�
�z#UnquotingTests.test_unquoting_partscCs\d}|}tj�|�}|�||d||f�|�dd�}tj�|�}|�||d||f�dS)Nzare+there+spaces...r�r�r�r�)rrgr�r~r�r�r�rrr�test_unquoting_plus�s
�
�z"UnquotingTests.test_unquoting_pluscCs�d}d}tj�|�}|�||d||f�tj�d�}d}|�||d||f�d}d}tj�|�}|�||d||f�d}d}tj�|�}|�||d||f�dS)	N�"br%C3%BCckner_sapporo_20050930.docsbrückner_sapporo_20050930.docr��	漢%C3%BCs漢üs%A2%D8ab%FFr�s	%A2�ab%FFr�r�rrr�test_unquote_to_bytes�s>��������z$UnquotingTests.test_unquote_to_bytescCsxd}d}tj�|�}|�||d||f�tjj|ddd�}|�||d||f�tjjddd�}d}|�||d||f�d}d	}tj�|�}|�||d||f�d
}d}tj�|�}|�||d||f�tjj|dd
�}|�||d||f�d
}d}tjj|dd
�}|�||d||f�tj�d�}d}|�||d||f�tjjddd�}d}|�||d||f�dS)Nr�ubrückner_sapporo_20050930.docr�r�zbr%FCckner_sapporo_20050930.docrtr�r�r�z%F3%B1u�r�)r�r��ignorer�u漢üu漢%FC�rrgr�r~r�rrr�test_unquote_with_unicode�sb
�
��
�
�
�
�
�
�
�z(UnquotingTests.test_unquote_with_unicodecCs�d}d}tj�|�}|�||d||f�d}d}tj�|�}|�||d||f�d}d}tj�|�}|�||d||f�dS)NsblueberryjamZblueberryjamr�sblåbærsyltetøyublåbærsyltetøysbl%c3%a5b%c3%a6rsyltet%c3%b8jublåbærsyltetøjr�r�rrr�test_unquoting_with_bytes_input�s$
�
�
�z.UnquotingTests.test_unquoting_with_bytes_inputN)r6r7r8r�r�r�r�r�r�r�r�r�rrrrr�8s$	:r�c@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�urlencode_TestszTests for urlencode()c		Cs�gd�}tj�|�}|D]}|�||d|||f�q|�|�d�dd||�d�f�|�d�}||d}||d}|�|��oF|��d||f�|�t	|�dd	|t	|�df�d
S)aHelper 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.

        )z1st=1z2nd=2z3rd=3ztesting %s: %s not found in %s�&r	z#testing %s: expected 2 '&'s; got %sr
z1testing %s: '&' not located in proper place in %s�z5testing %s: unexpected number of characters: %s != %sN)
rrg�	urlencoderr~r��indexrx�isdigitr)	r"r�Z	test_typeZexpect_somewhererHr~Zamp_locationZon_amp_leftZon_amp_rightrrr�help_inputtypes4����
����zurlencode_Tests.help_inputtypecCs|�dddd�d�dS)N�1�2�3)�1st�2nd�3rdzusing dict as input type�r�r5rrr�test_using_mapping.s�z"urlencode_Tests.test_using_mappingcCs|�gd�d�dS)N))r�r�)r�r�)r�r�z*using sequence of two-item tuples as inputr�r5rrr�test_using_sequence3s
�z#urlencode_Tests.test_using_sequencecCs\ddi}dtd�td�f}tj�|�}|�||�ddi}d}tj�|�}|�||�dS)Nr��=z%s=%szkey namezA bunch of pluseszkey+name=A+bunch+of+pluses)rrrgr�r~r�rrr�test_quoting8szurlencode_Tests.test_quotingcCs�dgd�i}dtj�tgd���}tj�|�}|�||�tj�|d�}|dD]}d|}|�||�q)|�|�d�dd|�d��dS)NZsequence)r�r�r�zsequence=%sTr�r	zExpected 2 '&'s, got %s)rrgrnr1r�r~rr�)r"r�rxrH�valuerrr�
test_doseqCs�zurlencode_Tests.test_doseqcCs,|�dtj�i��|�dtj�g��dSr�r~rrgr�r5rrr�test_empty_sequencePsz#urlencode_Tests.test_empty_sequencecCs4|�dtj�ddi��|�dtj�ddi��dS)Nza=1�ar
za=Noner�r5rrr�test_nonstring_valuesTsz%urlencode_Tests.test_nonstring_valuescCsh|�dtj�dddgid��|�dtj�dddgid��t�ddg�}|�d	tj�d|id��dS)
Nza=1&a=2r�r
r	Tz
a=None&a=a)r�r
)�br
za=a&a=b)r~rrgr�r�r�r!rrr�test_nonstring_seq_valuesXs��z)urlencode_Tests.test_nonstring_seq_valuescCsnd}d}tjj|ddd�}|�||�d}d}tj�|�}|�||�d}d}tjj|dd	�}|�||�dS)
N�)� �Á�%3F=%3Frr�r��
%C2%A0=%C3%81�%A0=%C1rtr��rrgr�r~r�rrr�test_urlencode_encoding`sz'urlencode_Tests.test_urlencode_encodingcCs�d}d}tjj|dddd�}|�||�d}d}tjj|dddd	�}|�||�d}d
}tj�|d�}|�||�d}d}tj�|d�}|�||�d}d
}tjj|ddd�}|�||�d}d}tjj|ddd�}|�||�dS)Nr�r�Trr�)�doseqrvr�))r�)r
r�z
%3F=1&%3F=%3Fr�r�))r�)�*r�z%C2%A0=42&%C2%A0=%C3%81r�rtr�z%A0=42&%A0=%C1r�r�rrr�test_urlencode_encoding_doseqss8
�
�z-urlencode_Tests.test_urlencode_encoding_doseqcCs`d}d}tj�|�}|�||�tj�|d�}|�||�d}d}tj�|d�}|�||�dS)N�)��$��$z
%A0%24=%C1%24T))r�)r�r�z%A0%24=42&%A0%24=%C1%24r�r�rrr�test_urlencode_bytes�sz$urlencode_Tests.test_urlencode_bytescCs�d}tjj|dd�}d}|�||�d}tjj|ddd�}d}|�||�d}d}tjj|ddd�}|�||�d}tjj|dd	d
�}d}|�||�d}d}tjj|ddd	d�}d}d}tjj|ddd	d
�}|�||�dS)Nr�z:$rrz	%A0$=%C1$T)r�rs))r�)r��
r�z%A0$=%C1$&%A0$=13&%A0$=42rt)rsrv)r�rsrvr�)r"r�rHrxrrr�&test_urlencode_encoding_safe_parameter�s:
���z6urlencode_Tests.test_urlencode_encoding_safe_parameterN)r6r7r8r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s 
%r�c@sTeZdZdZdd�Zdd�Ze�ej	dkd�dd	��Z
e�ej	dkd
�dd��Zd
S)�Pathname_Testsz&Test pathname2url() and url2pathname()cCs^tj�dddd�}d}tj�|�}|�||d||f�tj�|�}|�||d||f�dS)N�partsZofr�rzparts/of/a/path�pathname2url() failed; %s != %szurl2pathame() failed; %s != %s)rmrrmrrrr~r)r"Z
expected_pathZexpected_urlrHrrrrI�s����zPathname_Tests.test_basiccCs�tj�ddd�}dtj�d�}tj�|�}|�||d||f�|}tj�	|�}|�||d||f�tj�dd�}d	tj�d�}tj�|�}|�||d||f�d
}tj�dd�}tj�	|�}|�||d||f�dS)
NZneedszquot=ing�herez
needs/%s/herer�zurl2pathname() failed; %s != %sz	make sureZusing_quotez%s/using_quotezmake+sure/using_unquotez	make+sureZ
using_unquote)
rmrrmrrgrhrrr~rr�rrrr��s>��������zPathname_Tests.test_quoting�win32z*test specific to the nturl2path functions.cCsXd}d}tj�|�}|�||d||f�d}d}tj�|�}|�||d||f�dS)Nz
\\?\C:\dirz	///C:/dirr�z\\?\unc\server\share\dirz/server/share/dir)rrrr~r�rrr�
test_prefixes�s ����zPathname_Tests.test_prefixesz.test specific to the urllib.url2path function.cCsbd}d}|D]}tj�|�}|�||d||f�qd}d}tj�|�}|�||d||f�dS)N)z/C:/z///C:/z/C|//�C:\z/urllib.request..url2pathname() failed; %s != %sz
///C|/pathzC:\pathz.urllib.request.url2pathname() failed; %s != %s)rrrr~)r"r�rxrrHrrr�test_ntpaths"����zPathname_Tests.test_ntpathN)r6r7r8r�rIr�r"r#�sys�platformr�r�rrrrr��s
�
�r�c@seZdZdZdd�ZdS)�
Utility_Testsz=Testcase to test the various utility functions in the urllib.cCs|�tj��t�dS)zATest the urllib.request.thishost utility function returns a tupleN)r�rrZthishost�tupler5rrr�
test_thishostr<zUtility_Tests.test_thishostN)r6r7r8r�r�rrrrr�sr�c@sTeZdZdZdd�Zejed�dd��Zejed�dd��Z	ejed�d	d
��Z
dS)�URLopener_Testsz4Testcase to test the open method of URLopener class.cCspGdd�dtjj�}t�dtf��|�|��d�d�|�|��d�d�Wd�dS1s1wYdS)Nc@�eZdZdd�ZdS)z8URLopener_Tests.test_quoted_open.<locals>.DummyURLopenercS�|Srr�r"rrrr�	open_spam)r?zBURLopener_Tests.test_quoted_open.<locals>.DummyURLopener.open_spamN)r6r7r8r�rrrr�DummyURLopener(�r�z8DummyURLopener style of invoking requests is deprecated.zspam://example/ /z//example/%20/z,spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/z'//c:|windows%/:=&?~#+!$,;'@()*[]|/path/)rrrrrrr~r)r"r�rrr�test_quoted_open's"��
��
��"�z URLopener_Tests.test_quoted_open)�categorycCs�t���6}tj|d�\}}t�|�dtj�|�}tj�	��
|�\}}|�tj�
|�tj�
|��Wd�dS1s=wYdS)N)�dirzfile:)rZtemp_dirrrrmr4rrrr�retriever~r�normcase)r"ZtmpdirrZtmpfileZfileurlr�_rrr�test_urlopener_retrieve_file6s

"�z,URLopener_Tests.test_urlopener_retrieve_filecCsJd}|�d�|�|j�tj���|�\}}|�tj	�
|�dd�dS)Nzhttp://www.python.org/file.txtr�r
z.txt)rDr&rIrrrr�r~rmr�splitext)r"rrr�rrr�test_urlopener_retrieve_remote@s

z.URLopener_Tests.test_urlopener_retrieve_remotecCs�Gdd�dtjj�}dD]3}|�ttjj|�|�ttj��j|�|�ttj��j|�|�t|�j|�|�t|�j|�qdS)Nc@r�)z<URLopener_Tests.test_local_file_open.<locals>.DummyURLopenercSr�rrr�rrr�open_local_fileLr?zLURLopener_Tests.test_local_file_open.<locals>.DummyURLopener.open_local_fileN)r6r7r8r�rrrrr�Kr�r�)zlocal_file://examplezlocal-file://example)rrrr�r�rrr�)r"r�rrrr�test_local_file_openHs�z$URLopener_Tests.test_local_file_openN)r6r7r8r�r�rZignore_warningsrr�r�r�rrrrr�$s


	

r�c@r_)�RequestTestsz&Unit tests for urllib.request.Request.cCs>tjj}|d�}|�|��d�|di�}|�|��d�dS)Nr�r�ZPOST)rr�Requestr~�
get_method�r"r�rrrr�test_default_valuesYs

z RequestTests.test_default_valuescCs�tjj}|ddd�}|�|jd�|�|��d�|didd�}|�|jd�|�|��d�|ddd�}|�|��d�d|_|�|��d�dS)Nr�ZHEAD)�methodr�)rrr�r~r�r�r�rrr�test_with_method_arg`sz!RequestTests.test_with_method_argN)r6r7r8r�r�r�rrrrr�Vsr�c@�4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�URL2PathNameTestscCs4|�td�d�|�td�d�|�td�d�dS)Nz///C|�C:�///C:z///C|/r��r~rr5rrr�test_converting_drive_letterpsz.URL2PathNameTests.test_converting_drive_lettercCs$|�td�d�|�td�d�dS)Nz
///C/test/z
\\\C\test\z////C/test/z	\\C\test\rr5rrr�$test_converting_when_no_drive_letterusz6URL2PathNameTests.test_converting_when_no_drive_lettercC�|�td�d�dS)Nz///C|/foo/bar/spam.foo�C:\foo\bar\spam.foorr5rrr�test_simple_comparez�
�z%URL2PathNameTests.test_simple_comparecC�|�ttd�dS)Nu///è|/)r��IOErrorrr5rrr�test_non_ascii_drive_letter~r�z-URL2PathNameTests.test_non_ascii_drive_lettercC�*gd�}|D]}|�tt|��|�qdS)N)r�z\\\C\test\\r)r~rr�r"Z
list_of_pathsrrrr�test_roundtrip_url2pathname�s�z-URL2PathNameTests.test_roundtrip_url2pathnameN)r6r7r8rrrr	rrrrrr�nsr�c@r�)�PathName2URLTestscCs$|�td�d�|�td�d�dS)Nr�r�r��r~rr5rrrr�sz.PathName2URLTests.test_converting_drive_lettercCs4|�td�d�|�td�d�|�td�d�dS)Nz\\\folder\test\�/////folder/test/z\\folder\test\z////folder/test/z
\folder\test\z
/folder/test/rr5rrrr�s
�
�
�z6PathName2URLTests.test_converting_when_no_drive_lettercCr)Nr�///C:/foo/bar/spam.foorr5rrrr�rz%PathName2URLTests.test_simple_comparecCr)NzXX:\)r�rrr5rrr�test_long_drive_letter�r�z(PathName2URLTests.test_long_drive_lettercCr
)N)r�rr)r~rrrrrr�test_roundtrip_pathname2url�s�z-PathName2URLTests.test_roundtrip_pathname2urlN)r6r7r8rrrrrrrrrr
�sr
�__main__)NNrK)8r��urllib.parserZurllib.requestZurllib.errorZhttp.clientrAZ
email.messager�r.r"Z
unittest.mockrrrZtest.supportrrrmr �ImportErrorr�rZ
nturl2pathrr�base64rr�rrrrrDrXrErLZTestCaser]r�r�r�r%r=r`rgr�r�r�r�r�r�r�r
r6�mainrrrr�<module>sn�

/
]L$
M-NTDN2
�
© 2025 GrazzMean