Your IP : 216.73.216.85


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_urllib2net.cpython-35.opt-1.pyc



��Yfo1�@sGddlZddlmZddlmZddlZddlZddlZddl	Zddl
Z
ejd�dZdd�Z
dd	�Zejd
ejkd�Zeejjejj�ZGdd
�d
ej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZedkrCej�dS)�N)�support)�sanepathname2urlZnetwork�<cOscxVtd�D]H}y|||�SWq
|k
rT}z|}w
WYdd}~Xq
Xq
W|�dS)N�)�range)�func�exc�args�kwargs�i�e�last_exc�r�9/opt/alt/python35/lib64/python3.5/test/test_urllib2net.py�
_retry_thricesrcs��fdd�}|S)Ncst��||�S)N)r)r	r
)rrrr�wrappedsz(_wrap_with_retry_thrice.<locals>.wrappedr)rrrr)rrr�_wrap_with_retry_thricesrZTRAVISz%bpo-35411: skip FTP test on Travis CIc@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�WdQRXdS)Nzhttp://www.example.com/)r�transient_internet�_urlopen_with_retry�fp�assertFalse�closed�close�
assertTrue)�self�urlZresponseZsockrrr�
test_closeTs	
zCloseSocketTest.test_closeN)rrrr"rrrrrRsrc@s�eZdZdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
ddd�Zdd�ZdS)�OtherNetworkTestscCsdS)Nr)r rrr�setUp`szOtherNetworkTests.setUpcCs5dddtjjfg}|j||j��dS)Nzftp://www.pythontest.net/READMEz*ftp://www.pythontest.net/non-existent-file)�urllib�error�URLError�
_test_urls�_extra_handlers)r �urlsrrr�test_ftpiszOtherNetworkTests.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_filers	

 zOtherNetworkTests.test_filec
Cs[d}tj|��?tjj|�}tjj|�}|j|j�d�WdQRXdS)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
Cs[d}tj|��?tjj|�}tjj|�}|j|j�d�WdQRXdS)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�WdQRXdS)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|���y tjj|��}WdQRXWn2tk
rj}z|jd�WYdd}~XnX|j|�tjj|�}|j�}|j|�WdQRXdS)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}|rZt|tj	j
�}x�|D]{}|jd|��`t|t
�r�|\}}	}
n
d}	}
tj|��y|||	t�}Wnctk
r0}zC|
rd|
||	t|�|f}
|j||
|
�n�WYdd}~Xn�XyWtj�Gtj�6tj�%|j�}|dt|��WdQRXWdQRXWdQRXWn,tjk
r�td|dtj�YnX|j�WdQRX|jd�WdQRXqaWdS)	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$�skip_ftp_test_on_travisr+r9r?r@rBrDr(r)rrrrr#_s		-
'r#c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	Zed
d��Z	edd
��Z
edd��Zedd��ZdS)�TimeoutTestc	Csr|jtj��d}tj|dd��=t|�}|j|j�|j|jj	j
j��WdQRXdS)Nzhttp://www.example.comrP)�assertIsNonerO�getdefaulttimeoutrrrrXrr�raw�_sock�
gettimeout)r r!�urrr�test_http_basicszTimeoutTest.test_http_basiccCs�|jtj��d}tj|��btjd�z t|�}|j|j�Wdtjd�X|j	|j
jjj
�d�WdQRXdS)Nzhttp://www.example.comr)r\rOr]rr�setdefaulttimeoutrrXrr;rr^r_r`)r r!rarrr�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��WdQRXdS)Nzhttp://www.example.comrrP)
r\rOr]rrrcrrXrrr^r_r`)r r!rarrr�test_http_no_timeouts
z TimeoutTest.test_http_no_timeoutcCsbd}tj|��Ft|dd�}|j|j�|j|jjjj	�d�WdQRXdS)Nzhttp://www.example.comrP�x)
rrrrXrr;rr^r_r`)r r!rarrr�test_http_timeout#s
zTimeoutTest.test_http_timeoutzftp://www.pythontest.net/c	Csu|jtj��tj|jdd��Ct|j�}|j|j�|j|j	j	j
jj��WdQRXdS)NrP)
r\rOr]rr�FTP_HOSTrrXrrr^r_r`)r rarrr�test_ftp_basic,s
zTimeoutTest.test_ftp_basiccCs�|jtj��tj|j��htjd�z#t|j�}|j|j	�Wdtjd�X|j
|jjjj
j�d�WdQRXdS)Nr)r\rOr]rrrhrcrrXrr;rr^r_r`)r rarrr�test_ftp_default_timeout4s
z$TimeoutTest.test_ftp_default_timeoutcCs�|jtj��tj|j��ktjd�z)t|jdd�}|j|j	�Wdtjd�X|j|j
j
jjj
��WdQRXdS)NrrP)r\rOr]rrrhrcrrXrrr^r_r`)r rarrr�test_ftp_no_timeout@s
zTimeoutTest.test_ftp_no_timeoutcCsetj|j��Lt|jdd�}|j|j�|j|jjjj	j
�d�WdQRXdS)NrPr)rrrhrrXrr;rr^r_r`)r rarrr�test_ftp_timeoutLszTimeoutTest.test_ftp_timeoutN)
rrrrbrdrergrhrZrirjrkrlrrrrr[sr[�__main__)ZunittestZtestrZtest.test_urllib2rr1rOZurllib.errorr%Zurllib.requestrRZrequiresrKrrZskipIf�environrZr6r7r&r'rZTestCaserrr#r[r�mainrrrr�<module>s*
		'
�R