Your IP : 216.73.216.213


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-2.pyc



���]o1�@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�4/opt/alt/python35/lib64/python3.5/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@seZdZdS)�	AuthTestsN)�__name__�
__module__�__qualname__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�url�response�sockrrr�
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)rrrr�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)rr/�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&r7�Requestr8�assertEqual�geturl)rZ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&r7r;r8r<r=)rZredirect_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&r7�build_openerr;rZheader_itemsr0rZ
has_headerZ
add_headerr<Z
get_header)rr Zopenerr7rrr�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&r7r8r6Zfailr�read)rZURLr?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�logging�	getLogger�debugr&r7rBr0rr'r(ZsubTest�
isinstance�tuplerr�TIMEOUT�OSError�typeZassertIsInstanceZtime_outZsocket_peer_resetZioerror_peer_resetrD�len�socket�timeout�print�sys�stderrr�sleep)rr+�handlersr.rGrHrJr8r r>Zexpected_errr9�err�msg�bufrrrr)�s<




-zOtherNetworkTests._test_urlscCsCg}tjj�}|j|j�|jd�|j|�|S)N�)r&r7ZCacheFTPHandler�
addCleanupZclear_cacheZ
setTimeout�append)rrWZcfhrrrr*�s

z!OtherNetworkTests._extra_handlersN)
rrrr%�skip_ftp_test_on_travisr,r:r@rArCrEr)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.comrR)�assertIsNonerQ�getdefaulttimeoutrrrr\rr�raw�_sock�
gettimeout)rr �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`rQrarr�setdefaulttimeoutrr\rr<rrbrcrd)rr rerrr�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.comrrR)
r`rQrarrrgrr\rrrbrcrd)rr rerrr�test_http_no_timeouts
z TimeoutTest.test_http_no_timeoutcCsbd}tj|��Ft|dd�}|j|j�|j|jjjj	�d�WdQRXdS)Nzhttp://www.example.comrR�x)
rrrr\rr<rrbrcrd)rr rerrr�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)NrR)
r`rQrarr�FTP_HOSTrr\rrrbrcrd)rrerrr�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`rQrarrrlrgrr\rr<rrbrcrd)rrerrr�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)NrrR)r`rQrarrrlrgrr\rrrbrcrd)rrerrr�test_ftp_no_timeout@s
zTimeoutTest.test_ftp_no_timeoutcCsetj|j��Lt|jdd�}|j|j�|j|jjjj	j
�d�WdQRXdS)NrRr)rrrlrr\rr<rrbrcrd)rrerrr�test_ftp_timeoutLszTimeoutTest.test_ftp_timeoutN)
rrrrfrhrirkrlr^rmrnrorprrrrr_sr_�__main__)ZunittestZtestrZtest.test_urllib2rr2rQZurllib.errorr&Zurllib.requestrTZrequiresrMrrZskipIf�environr^r7r8r'r(rZTestCaserrr$r_r�mainrrrr�<module>s*
		'
�R