HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //proc/self/root/usr/local/lib/python3.7/test/__pycache__/test_urllib2net.cpython-37.opt-2.pyc
B

��g�1�@s�ddlZddlmZddlmZddlZddlZddlZddl	Zddl
Z
e�d�dZdd�Z
dd	�Ze�d
ejkd�Zeejjejj�ZGdd
�d
ej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zedkr�e��dS)�N)�support)�sanepathname2urlZnetwork�<cOsNxDtd�D]8}y
|||�S|k
r@}z
|}w
Wdd}~XYq
Xq
W|�dS)N�)�range)�func�exc�args�kwargs�i�e�last_exc�r�0/usr/local/lib/python3.7/test/test_urllib2net.py�
_retry_thrices
rcs��fdd�}|S)Ncst��f|�|�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@seZdZdS)�	AuthTestsN)�__name__�
__module__�__qualname__rrrrr+src@seZdZdd�ZdS)�CloseSocketTestc	CsNtj}t�|��4t|�}|j}|�|j�|��|�|j�WdQRXdS)N)	r�
TEST_HTTP_URL�transient_internet�_urlopen_with_retry�fp�assertFalse�closed�close�
assertTrue)�self�urlZresponseZsockrrr�
test_closeTszCloseSocketTest.test_closeN)rrrr"rrrrrRsrc@sdeZdZdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	e
�d
�dd��Zddd�Z
dd�ZdS)�OtherNetworkTestscCsdS)Nr)r rrr�setUp`szOtherNetworkTests.setUpcCs&dddtjjfg}|�||���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�}zL|�d�|��dttj�|��ddt	j
jfg}|j||�
�dd�Wdt�|�X|�tt	jjd�dS)N�wz	hi there
zfile:zfile:///nonsensename/etc/passwdT)�retryz./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	CsFd}t�|��.tj�|�}tj�|�}|�|��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	CsFd}t�|��.tj�|�}tj�|�}|�|��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�tj}t�|��ztj��}tj�|�}|�|���|�	|�|�
|���|�
|�d��|�dd�|�	|�|�
|�d�d�WdQRXdS)Nz
User-agentz
User-Agentz
Test-Agent)rrrr%r6�build_openerr:rZheader_itemsr/rZ
has_headerZ
add_headerr;Z
get_header)r r!�openerr6rrr�test_custom_headers�s


z%OtherNetworkTests.test_custom_headersz XXX: http://www.imdb.com is gonecCs�d}t�|��xytj�|��}WdQRXWn,tk
rX}z|�d�Wdd}~XYnX|�|�tj�|�}|��}|�|�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_closeTcCs�ddl}ddl}|�d�j}tjj|�j}|r<t|tj	j
�}�xL|D�]B}|j|d���*t|t
�rp|\}}	}
nd}	}
t�|���y|||	t�}WnNtk
r�}z0|
r�d|
||	t|�|f}
|�||
|
�n�Wdd}~XYn�XyRtj�Btj�0tj�|��}|dt|��WdQRXWdQRXWdQRXWn*tjk
�r`td|tjd�YnX|��WdQRX|�d�WdQRXqDWdS)	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�debugr%r6rAr/rr&r'ZsubTest�
isinstance�tuplerr�TIMEOUT�OSError�typeZassertIsInstanceZtime_outZsocket_peer_resetZioerror_peer_resetrD�len�socket�timeout�print�sys�stderrrZsleep)r r*�handlersr-rGrHrIr7r!r=Zexpected_errr8�err�msg�bufrrrr(�s<
2zOtherNetworkTests._test_urlscCs2g}tj��}|�|j�|�d�|�|�|S)N�)r%r6ZCacheFTPHandler�
addCleanupZclear_cacheZ
setTimeout�append)r rUZcfhrrrr)�s


z!OtherNetworkTests._extra_handlersN)T)rrrr$�skip_ftp_test_on_travisr+r9r?r@rC�unittest�skiprEr(r)rrrrr#_s		-

'r#c@s`eZdZdd�Zdd�Zdd�Zdd�Zd	Zed
d��Z	edd
��Z
edd��Zedd��ZdS)�TimeoutTestc	CsZ|�t���tj}tj|dd��.t|�}|�|j�|�|j	j
j���WdQRXdS)N)rQ)
�assertIsNonerP�getdefaulttimeoutrrrrrZrr�raw�_sock�
gettimeout)r r!�urrr�test_http_basicszTimeoutTest.test_http_basicc
Cst|�t���tj}t�|��Lt�d�zt|�}|�|j	�Wdt�d�X|�
|jjj
��d�WdQRXdS)Nr)r`rPrarrr�setdefaulttimeoutrrZrr;rrbrcrd)r r!rerrr�test_http_default_timeouts
z%TimeoutTest.test_http_default_timeoutc
Csv|�t���tj}t�|��Nt�d�zt|dd�}|�|j	�Wdt�d�X|�|j
jj�
��WdQRXdS)Nr)rQ)r`rPrarrrrgrrZrrrbrcrd)r r!rerrr�test_http_no_timeouts
z TimeoutTest.test_http_no_timeoutc	CsNtj}t�|��4t|dd�}|�|j�|�|jjj	�
�d�WdQRXdS)N�x)rQ)rrrrrZrr;rrbrcrd)r r!rerrr�test_http_timeout$s
zTimeoutTest.test_http_timeoutzftp://www.pythontest.net/c	CsZ|�t���tj|jdd��2t|j�}|�|j�|�|j	j	j
j���WdQRXdS)N)rQ)
r`rPrarr�FTP_HOSTrrZrrrbrcrd)r rerrr�test_ftp_basic-s

zTimeoutTest.test_ftp_basicc
Cst|�t���t�|j��Pt�d�zt|j�}|�|j	�Wdt�d�X|�
|jjjj
��d�WdQRXdS)Nr)r`rPrarrrlrgrrZrr;rrbrcrd)r rerrr�test_ftp_default_timeout5s

z$TimeoutTest.test_ftp_default_timeoutc
Csv|�t���t�|j��Rt�d�zt|jdd�}|�|j	�Wdt�d�X|�|j
j
jj�
��WdQRXdS)Nr)rQ)r`rPrarrrlrgrrZrrrbrcrd)r rerrr�test_ftp_no_timeoutAs
zTimeoutTest.test_ftp_no_timeoutc	CsNt�|j��8t|jdd�}|�|j�|�|jjjj	�
�d�WdQRXdS)Nr)rQ)rrrlrrZrr;rrbrcrd)r rerrr�test_ftp_timeoutMszTimeoutTest.test_ftp_timeoutN)
rrrrfrhrirkrlr\rmrnrorprrrrr_sr_�__main__)r]ZtestrZtest.test_urllib2rr1rPZurllib.errorr%Zurllib.requestrSZrequiresrLrrZskipIf�environr\r6r7r&r'rZTestCaserrr#r_r�mainrrrr�<module>s,
	
'
%R