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: //usr/local/lib/python3.7/test/__pycache__/test_urllib2net.cpython-37.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@seZdZdZdS)�	AuthTestsz&Tests urllib2 authentication features.N)�__name__�
__module__�__qualname__�__doc__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&r7�Requestr8�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&r7r;r8r<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&r7�build_openerr;rZheader_itemsr0r Z
has_headerZ
add_headerr<Z
get_header)r!r"�openerr7rrr�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&r7r8r6Zfailr �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&r7rBr0rr'r(ZsubTest�
isinstance�tuplerr�TIMEOUT�OSError�typeZassertIsInstanceZtime_outZsocket_peer_resetZioerror_peer_resetrE�len�socket�timeout�print�sys�stderrrZsleep)r!r+�handlersr.rHrIrJr8r"r>Zexpected_errr9�err�msg�bufrrrr)�s<
2zOtherNetworkTests._test_urlscCs2g}tj��}|�|j�|�d�|�|�|S)N�)r&r7ZCacheFTPHandler�
addCleanupZclear_cacheZ
setTimeout�append)r!rVZcfhrrrr*�s


z!OtherNetworkTests._extra_handlersN)T)rrrr%�skip_ftp_test_on_travisr,r:r@rArD�unittest�skiprFr)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)rR)
�assertIsNonerQ�getdefaulttimeoutrrrrr[rr�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)rarQrbrrr�setdefaulttimeoutrr[rr<rrcrdre)r!r"rfrrr�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)rR)rarQrbrrrrhrr[rrrcrdre)r!r"rfrrr�test_http_no_timeouts
z TimeoutTest.test_http_no_timeoutc	CsNtj}t�|��4t|dd�}|�|j�|�|jjj	�
�d�WdQRXdS)N�x)rR)rrrrr[rr<rrcrdre)r!r"rfrrr�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)rR)
rarQrbrr�FTP_HOSTrr[rrrcrdre)r!rfrrr�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)rarQrbrrrmrhrr[rr<rrcrdre)r!rfrrr�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)rR)rarQrbrrrmrhrr[rrrcrdre)r!rfrrr�test_ftp_no_timeoutAs
zTimeoutTest.test_ftp_no_timeoutc	CsNt�|j��8t|jdd�}|�|j�|�|jjjj	�
�d�WdQRXdS)Nr)rR)rrrmrr[rr<rrcrdre)r!rfrrr�test_ftp_timeoutMszTimeoutTest.test_ftp_timeoutN)
rrrrgrirjrlrmr]rnrorprqrrrrr`sr`�__main__)r^ZtestrZtest.test_urllib2rr2rQZurllib.errorr&Zurllib.requestrTZrequiresrMrrZskipIf�environr]r7r8r'r(rZTestCaserrr$r`r�mainrrrr�<module>s,
	
'
%R