Your IP : 216.73.216.85


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_urllib2net.cpython-39.pyc

a

XC?h�2�@s�ddlZddlmZddlmZddlmZddlZddlZddl	Z
ddlZ
ddlZe�
d�dd�Zdd	�Ze�d
ejvd�Zee
jje
jj�ZGdd
�d
ej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zedkr�e��dS)�N)�support)�
socket_helper)�sanepathname2urlZnetworkcOs`td�D]N}z||i|��WS|yT}z|}WYd}~qWYd}~qd}~00q|�dS)N�)�range)�func�exc�args�kwargs�i�e�last_exc�r�9/opt/alt/python39/lib64/python3.9/test/test_urllib2net.py�
_retry_thrices$rcs��fdd�}|S)Ncst��g|�Ri|��S�N)r)r	r
�rrrr�wrappedsz(_wrap_with_retry_thrice.<locals>.wrappedr)rrrrrr�_wrap_with_retry_thricesrZTRAVISz%bpo-35411: skip FTP test on Travis CIc@seZdZdZdS)�	AuthTestsz&Tests urllib2 authentication features.N)�__name__�
__module__�__qualname__�__doc__rrrrr*src@seZdZdd�ZdS)�CloseSocketTestcCsp|�tjj�tj}t�|��>t|�}|j	}|�
|j�|��|�
|j�Wd�n1sb0YdSr)�
addCleanup�urllib�request�
urlcleanupr�
TEST_HTTP_URLr�transient_internet�_urlopen_with_retry�fp�assertFalse�closed�close�
assertTrue)�self�urlZresponseZsockrrr�
test_closeSszCloseSocketTest.test_closeN)rrrr)rrrrrQsrc@sdeZdZdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	e
�d
�dd��Zddd�Z
dd�ZdS)�OtherNetworkTestscCsdSrr�r'rrr�setUpbszOtherNetworkTests.setUpcCs&dddtjjfg}|�||���dS)Nzftp://www.pythontest.net/READMEz*ftp://www.pythontest.net/non-existent-file)r�error�URLError�
_test_urls�_extra_handlers)r'�urlsrrr�test_ftpks��zOtherNetworkTests.test_ftpc	Cs�tj}t|d�}zV|�d�|��dttj�|��ddt	j
jfg}|j||�
�dd�Wt�|�nt�|�0|�tt	jjd�dS)N�wz	hi there
zfile:zfile:///nonsensename/etc/passwdT)�retryz./relative_path/to/file)r�TESTFN�open�writer%r�os�path�abspathrr-r.r/r0�removeZassertRaises�
ValueErrorr�urlopen)r'r5�fr1rrr�	test_filets

��zOtherNetworkTests.test_filecCsZd}t�|��8tj�|�}tj�|�}|�|��d�Wd�n1sL0YdS)Nz)http://www.pythontest.net/index.html#frag�rr rr�Requestr=�assertEqualZgeturl)r'Zurlwith_frag�req�resrrr�test_urlwithfrag�s
�z"OtherNetworkTests.test_urlwithfragcCsZd}t�|��8tj�|�}tj�|�}|�|��d�Wd�n1sL0YdS)Nz*http://www.pythontest.net/redir/with_frag/z)http://www.pythontest.net/elsewhere/#fragr@)r'Zredirect_url_with_fragrCrDrrr�test_redirect_url_withfrag�s
�z,OtherNetworkTests.test_redirect_url_withfragcCs�tj}t�|���tj��}tj�|�}|�|�	��|�
|�|�|�	��|�|�d��|�
dd�|�
|�|�|�d�d�Wd�n1s�0YdS)Nz
User-agentz
User-Agentz
Test-Agent)rrrr rr�build_openerrAr#Zheader_itemsr6r&Z
has_headerZ
add_headerrBZ
get_header)r'r(Zopenerrrrr�test_custom_headers�s


z%OtherNetworkTests.test_custom_headersz XXX: http://www.imdb.com is gonec	Cs�d}t�|���z0tj�|��}Wd�n1s40YWnty\|�d�Yn0|�|�tj�|�}|��}|�|�Wd�n1s�0YdS)Nzhttp://www.imdb.comzOurlopen failed for site not sending                            Connection:close)	rr rrr=r<Zfailr&�read)r'ZURLrDrCrrr�test_sites_no_connection_close�s"
z0OtherNetworkTests.test_sites_no_connection_closeTc
Cs�ddl}ddl}|�d�j}tjj|�j}|r<t|tj	j
�}|D�]�}|j|d����t|t
�rl|\}}	}
nd}	}
t�|���:z|||	tj�}WnPty�}z8|
r�d|
||	t|�|f}
|�||
|
�n�WYd}~n�d}~00z�tj�xtj�Ptj�(|��}|dt|��Wd�n1�s.0YWd�n1�sN0YWd�n1�sn0YWn(tj�y�td|tjd�Yn0|��Wd�n1�s�0Y|� d�Wd�q@1�s�0Yq@dS)	NrZtest_urllib2)r(z5Didn't get expected error(s) %s for %s %s, got %s: %sz
read %d bytesz
<timeout: %s>)�fileg�������?)!�time�loggingZ	getLogger�debugrrrGr6rr-r.ZsubTest�
isinstance�tuplerr rZINTERNET_TIMEOUT�OSError�typeZassertIsInstanceZtime_outZsocket_peer_resetZioerror_peer_resetrI�len�socket�timeout�print�sys�stderrr%�sleep)r'r1�handlersr4rLrMrNr=r(rCZexpected_errr>�err�msgZbufrrrr/�sB

���t(zOtherNetworkTests._test_urlscCs2g}tj��}|�|j�|�d�|�|�|S)N�)rrZCacheFTPHandlerrZclear_cacheZ
setTimeout�append)r'rZZcfhrrrr0�s


z!OtherNetworkTests._extra_handlersN)T)rrrr,�skip_ftp_test_on_travisr2r?rErFrH�unittest�skiprJr/r0rrrrr*as	
-


'r*c@sheZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdZe	dd
��Z
e	dd��Ze	dd��Ze	dd��Z
dS)�TimeoutTestcCs|�tjj�dSr)rrrrr+rrrr,szTimeoutTest.setUpcCsn|�t���tj}tj|dd��8t|�}|�|j	�|�|j
jj�
��Wd�n1s`0YdS�N�rU)�assertIsNonerT�getdefaulttimeoutrrrr r!rr%r"�raw�_sock�
gettimeout�r'r(�urrr�test_http_basic
szTimeoutTest.test_http_basicc
Cs�|�t���tj}t�|��`t�d�z"t|�}|�	|j
�Wt�d�nt�d�0|�|jj
j��d�Wd�n1s�0YdS�N�<)rerTrfrrrr �setdefaulttimeoutr!rr%rBr"rgrhrirjrrr�test_http_default_timeouts
z%TimeoutTest.test_http_default_timeoutc
Cs�|�t���tj}t�|��bt�d�z&t|dd�}|�	|j
�Wt�d�nt�d�0|�|jjj
���Wd�n1s�0YdS�Nrnrd)rerTrfrrrr ror!rr%r"rgrhrirjrrr�test_http_no_timeouts
z TimeoutTest.test_http_no_timeoutcCsbtj}t�|��>t|dd�}|�|j�|�|jj	j
��d�Wd�n1sT0YdS)N�xrd)rrrr r!rr%rBr"rgrhrirjrrr�test_http_timeout*s
zTimeoutTest.test_http_timeoutzftp://www.pythontest.net/cCsn|�t���tj|jdd��<t|j�}|�|j�|�|j	j	j
j���Wd�n1s`0YdSrc)
rerTrfrr �FTP_HOSTr!rr%r"rgrhri�r'rkrrr�test_ftp_basic3s

zTimeoutTest.test_ftp_basicc
Cs�|�t���t�|j��dt�d�z$t|j�}|�|j	�Wt�d�nt�d�0|�
|jjjj
��d�Wd�n1s�0YdSrm)rerTrfrr ruror!rr%rBr"rgrhrirvrrr�test_ftp_default_timeout;s

z$TimeoutTest.test_ftp_default_timeoutc
Cs�|�t���t�|j��ft�d�z(t|jdd�}|�|j	�Wt�d�nt�d�0|�|j
j
jj�
��Wd�n1s�0YdSrq)rerTrfrr ruror!rr%r"rgrhrirvrrr�test_ftp_no_timeoutGs
zTimeoutTest.test_ftp_no_timeoutcCsbt�|j��Bt|jdd�}|�|j�|�|jjjj	�
�d�Wd�n1sT0YdSrq)rr rur!rr%rBr"rgrhrirvrrr�test_ftp_timeoutSszTimeoutTest.test_ftp_timeoutN)rrrr,rlrprrrtrur_rwrxryrzrrrrrbs


rb�__main__)r`�testrZtest.supportrZtest.test_urllib2rr8rTZurllib.errorrZurllib.requestrWZrequiresrrZskipIf�environr_rr=r-r.r!ZTestCaserrr*rbr�mainrrrr�<module>s0
	��'%V