Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_urllib2net.cpython-34.pyc

�
f f�/�@s/ddlZddlmZddlmZddlZddlZddlZddl	Zddl
Z
ejd�dZdd�Z
dd	�Zeejjejj�ZGd
d�dej�ZGdd
�d
ej�ZGdd�dej�ZGdd�dej�Zedkr+ej�ndS)�N)�support)�sanepathname2urlZnetwork�<cOsmx`td�D]R}y|||�SWq
|k
rT}z|}w
WYdd}~Xq
�Yq
Xq
W|�dS)N�)�range)�func�exc�args�kwargs�i�e�last_exc�r�9/opt/alt/python34/lib64/python3.4/test/test_urllib2net.py�
_retry_thricesrcs��fdd�}|S)Ncst��||�S)N)r)r	r
)rrrr�wrappedsz(_wrap_with_retry_thrice.<locals>.wrappedr)rrrr)rrr�_wrap_with_retry_thricesrc@seZdZdZdS)�	AuthTestsz&Tests urllib2 authentication features.N)�__name__�
__module__�__qualname__�__doc__rrrrr&src@seZdZdd�ZdS)�CloseSocketTestc	Cs_d}tj|��Dt|�}|j}|j|j�|j�|j|j�WdQXdS)Nzhttp://www.example.com/)r�transient_internet�_urlopen_with_retry�fp�assertFalse�closed�close�
assertTrue)�self�urlZresponseZsockrrr�
test_closeOs	
zCloseSocketTest.test_closeN)rrrr"rrrrrMsrc@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	ddd�Z
dd�ZdS)�OtherNetworkTestscCsdS)Nr)r rrr�setUp[szOtherNetworkTests.setUpcCs5dddtjjfg}|j||j��dS)Nz"ftp://ftp.debian.org/debian/READMEz-ftp://ftp.debian.org/debian/non-existent-file)�urllib�error�URLError�
_test_urls�_extra_handlers)r �urlsrrr�test_ftpdszOtherNetworkTests.test_ftpcCs�tj}t|d�}zh|jd�|j�dttjj|��ddt	j
jfg}|j||j
�dd�Wdtj|�X|jtt	jjd�dS)N�wz	hi there
zfile:zfile:///nonsensename/etc/passwd�retryTz./relative_path/to/file)r�TESTFN�open�writerr�os�path�abspathr%r&r'r(r)�removeZassertRaises�
ValueError�request�urlopen)r r.�fr*rrr�	test_filels	

 zOtherNetworkTests.test_filec
CsZd}tj|��?tjj|�}tjj|�}|j|j�d�WdQXdS)Nz)http://www.pythontest.net/index.html#frag)rrr%r6�Requestr7�assertEqual�geturl)r Zurlwith_frag�req�resrrr�test_urlwithfrag�sz"OtherNetworkTests.test_urlwithfragc
CsZd}tj|��?tjj|�}tjj|�}|j|j�d�WdQXdS)Nz*http://www.pythontest.net/redir/with_frag/z)http://www.pythontest.net/elsewhere/#frag)rrr%r6r:r7r;r<)r Zredirect_url_with_fragr=r>rrr�test_redirect_url_withfrag�sz,OtherNetworkTests.test_redirect_url_withfragc
Cs�d}tj|���tjj�}tjj|�}|j|j��|j|�|j	|j��|j	|j
d��|jdd�|j|�|j|j
d�d�WdQXdS)Nzhttp://www.example.comz
User-agentz
User-Agentz
Test-Agent)rrr%r6�build_openerr:rZheader_itemsr/rZ
has_headerZ
add_headerr;Z
get_header)r r!Zopenerr6rrr�test_custom_headers�s

z%OtherNetworkTests.test_custom_headerscCs�d}tj|���ytjj|��}WdQXWn2tk
ri}z|jd�WYdd}~XnX|j|�tjj|�}|j�}|j|�WdQXdS)Nzhttp://www.imdb.comzOurlopen failed for site not sending                            Connection:close)	rrr%r6r7r5Zfailr�read)r ZURLr>rr=rrr�test_sites_no_connection_close�s

z0OtherNetworkTests.test_sites_no_connection_closeTc6Cs�ddl}ddl}|jd�j}tjj|�j}|r]t|tj	j
�}nx~|D]v}|jd|��\t|t
�r�|\}}	}
n
d}	}
tj|��y|||	t�}Wnctk
r3}zC|
rd|
||	t|�|f}
|j||
|
�n�WYdd}~Xn�XyTtj�Etj�5tj�%|j�}|dt|��WdQXWdQXWdQXWn,tjk
r�td|dtj�YnX|j�WdQX|jd�WdQXqdWdS)	NrZtest_urllib2r!z5Didn't get expected error(s) %s for %s %s, got %s: %sz
read %d bytesz
<timeout: %s>�fileg�������?) �time�loggingZ	getLogger�debugr%r6rAr/rr&r'ZsubTest�
isinstance�tuplerr�TIMEOUT�OSError�typeZassertIsInstanceZtime_outZsocket_peer_resetZioerror_peer_resetrC�len�socket�timeout�print�sys�stderrrZsleep)r r*�handlersr-rFrGrHr7r!r=Zexpected_errr8�err�msgZbufrrrr(�s<




*zOtherNetworkTests._test_urlscCsCg}tjj�}|j|j�|jd�|j|�|S)N�)r%r6ZCacheFTPHandler�
addCleanupZclear_cacheZ
setTimeout�append)r rTZcfhrrrr)�s

z!OtherNetworkTests._extra_handlersN)rrrr$r+r9r?r@rBrDr(r)rrrrr#Zs	-
'r#c@sveZdZdd�Zdd�Zdd�Zdd�Zd	Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�TimeoutTestc	Csq|jtj��d}tj|dd��=t|�}|j|j�|j|jj	j
j��WdQXdS)Nzhttp://www.example.comrP)�assertIsNonerO�getdefaulttimeoutrrrrXrr�raw�_sock�
gettimeout)r r!�urrr�test_http_basic�szTimeoutTest.test_http_basiccCs�|jtj��d}tj|��btjd�z t|�}|j|j�Wdtjd�X|j	|j
jjj
�d�WdQXdS)Nzhttp://www.example.comr)r[rOr\rr�setdefaulttimeoutrrXrr;rr]r^r_)r r!r`rrr�test_http_default_timeouts
z%TimeoutTest.test_http_default_timeoutcCs�|jtj��d}tj|��etjd�z&t|dd�}|j|j�Wdtjd�X|j|j	j
jj��WdQXdS)Nzhttp://www.example.comrrP)
r[rOr\rrrbrrXrrr]r^r_)r r!r`rrr�test_http_no_timeouts
z TimeoutTest.test_http_no_timeoutcCsad}tj|��Ft|dd�}|j|j�|j|jjjj	�d�WdQXdS)Nzhttp://www.example.comrP�x)
rrrrXrr;rr]r^r_)r r!r`rrr�test_http_timeouts
zTimeoutTest.test_http_timeoutzftp://ftp.debian.org/debian/c	Cst|jtj��tj|jdd��Ct|j�}|j|j�|j|j	j	j
jj��WdQXdS)NrP)
r[rOr\rr�FTP_HOSTrrXrrr]r^r_)r r`rrr�test_ftp_basic&s
zTimeoutTest.test_ftp_basiccCs�|jtj��tj|j��htjd�z#t|j�}|j|j	�Wdtjd�X|j
|jjjj
j�d�WdQXdS)Nr)r[rOr\rrrgrbrrXrr;rr]r^r_)r r`rrr�test_ftp_default_timeout-s
z$TimeoutTest.test_ftp_default_timeoutcCs�|jtj��tj|j��ktjd�z)t|jdd�}|j|j	�Wdtjd�X|j|j
j
jjj
��WdQXdS)NrrP)r[rOr\rrrgrbrrXrrr]r^r_)r r`rrr�test_ftp_no_timeout8s
zTimeoutTest.test_ftp_no_timeoutcCsdtj|j��Lt|jdd�}|j|j�|j|jjjj	j
�d�WdQXdS)NrPr)rrrgrrXrr;rr]r^r_)r r`rrr�test_ftp_timeoutCszTimeoutTest.test_ftp_timeoutN)rrrrarcrdrfrgrhrirjrkrrrrrZ�srZ�__main__)ZunittestZtestrZtest.test_urllib2rr1rOZurllib.errorr%Zurllib.requestrRZrequiresrKrrr6r7r&r'rZTestCaserrr#rZr�mainrrrr�<module>s&
'
�N