Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_urllib2net.cpython-39.pyc

a

��g�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)�sanepathname2url�networkcOs`td�D]N}z||i|��WS|yT}z|}WYd}~qWYd}~qd}~00q|�dS)N�)�range)�func�exc�args�kwargs�i�e�last_exc�r�0/usr/local/lib/python3.9/test/test_urllib2net.py�
_retry_thrices$rcs��fdd�}|S)Ncst��g|�Ri|��S�N)r)r
r�r	rrr�wrappedsz(_wrap_with_retry_thrice.<locals>.wrappedr)rr	rrrr�_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�url�response�sockrrr�
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�abspathrr0r1r2r3�removeZassertRaises�
ValueErrorr�urlopen)r(r8�fr4rrr�	test_filets

��zOtherNetworkTests.test_filecCsZd}t�|��8tj�|�}tj�|�}|�|��d�Wd�n1sL0YdS)Nz)http://www.pythontest.net/index.html#frag�rr!rr�Requestr@�assertEqual�geturl)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/#fragrC)r(Zredirect_url_with_fragrGrHrrr�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)rr rr!rr�build_openerrDr$Zheader_itemsr9r'Z
has_headerZ
add_headerrEZ
get_header)r(r)�openerrrrr�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(ZURLrHrGrrr�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�logging�	getLogger�debugrrrKr9rr0r1ZsubTest�
isinstance�tuplerr!rZINTERNET_TIMEOUT�OSError�typeZassertIsInstanceZtime_outZsocket_peer_resetZioerror_peer_resetrN�len�socket�timeout�print�sys�stderrr&�sleep)r(r4�handlersr7rQrRrTr@r)rGZexpected_errrA�err�msg�bufrrrr2�sB

���t(zOtherNetworkTests._test_urlscCs2g}tj��}|�|j�|�d�|�|�|S)N�)rrZCacheFTPHandlerr�clear_cacheZ
setTimeout�append)r(r`Zcfhrrrr3�s


z!OtherNetworkTests._extra_handlersN)T)rrrr/�skip_ftp_test_on_travisr5rBrIrJrM�unittest�skiprOr2r3rrrrr-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�r[)�assertIsNonerZ�getdefaulttimeoutrr rr!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�<)rmrZrnrr rr!�setdefaulttimeoutr"rr&rEr#rorprqrrrrr�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�Nrvrl)rmrZrnrr rr!rwr"rr&r#rorprqrrrrr�test_http_no_timeouts
z TimeoutTest.test_http_no_timeoutcCsbtj}t�|��>t|dd�}|�|j�|�|jj	j
��d�Wd�n1sT0YdS)N�xrl)rr rr!r"rr&rEr#rorprqrrrrr�test_http_timeout*s
zTimeoutTest.test_http_timeoutzftp://www.pythontest.net/cCsn|�t���tj|jdd��<t|j�}|�|j�|�|j	j	j
j���Wd�n1s`0YdSrk)
rmrZrnrr!�FTP_HOSTr"rr&r#rorprq�r(rsrrr�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�0YdSru)rmrZrnrr!r}rwr"rr&rEr#rorprqr~rrr�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�0YdSry)rmrZrnrr!r}rwr"rr&r#rorprqr~rrr�test_ftp_no_timeoutGs
zTimeoutTest.test_ftp_no_timeoutcCsbt�|j��Bt|jdd�}|�|j�|�|jjjj	�
�d�Wd�n1sT0YdSry)rr!r}r"rr&rEr#rorprqr~rrr�test_ftp_timeoutSszTimeoutTest.test_ftp_timeoutN)rrrr/rtrxrzr|r}rgrr�r�r�rrrrrjs


rj�__main__)rh�testrZtest.supportrZtest.test_urllib2rr;rZZurllib.errorrZurllib.requestr]ZrequiresrrZskipIf�environrgrr@r0r1r"ZTestCaserrr-rjr�mainrrrr�<module>s0
	��'%V

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists