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.10/test/__pycache__/test_urllib2net.cpython-310.opt-2.pyc
o

�iD8�@sLddlZddlZddlmZddlmZddlmZddlmZddlm	Z	ddl
Z
ddlZddlZ
ddlZ
ddlZe�d�dd	�Zd
d�Ze�de
jvd
�Zee
jje
jj�ZGdd�de�Zeeejd�Zeeej d�Z!eeej d�Z"Gdd�dej#�Z$Gdd�dej#�Z%Gdd�dej#�Z&Gdd�dej#�Z'e(dkr�e�)�dSdS)�N)�support)�	os_helper)�
socket_helper)�ResourceDenied)�sanepathname2urlZnetworkcOsNtd�D] }z
||i|��WS|y$}z|}WYd}~qd}~ww|�)N�)�range)�func�exc�args�kwargs�i�e�last_exc�r�1/usr/local/lib/python3.10/test/test_urllib2net.py�
_retry_thrices��rcs��fdd�}|S)Ncst��g|�Ri|��S�N)r)rr�r
r	rr�wrappedsz(_wrap_with_retry_thrice.<locals>.wrappedr)r	r
rrrr�_wrap_with_retry_thricesrZTRAVISz%bpo-35411: skip FTP test on Travis CIc@s(eZdZ	dd�Zdd�Zddd�ZdS)	�TransientResourcecKs||_||_dSr)r
�attrs)�selfr
rrrr�__init__2s
zTransientResource.__init__cCs|Srr�rrrr�	__enter__6�zTransientResource.__enter__NcCs^	|dur+t|j|�r-|j��D]\}}t||�sdSt||�|kr&dSqtd��dSdS)Nz%an optional resource is not available)�
issubclassr
r�items�hasattr�getattrr)rZtype_�value�	traceback�attrZ
attr_valuerrr�__exit__9s
��zTransientResource.__exit__)NNN)�__name__�
__module__�__qualname__rrr%rrrrr-s
r)�errnoc@seZdZdS)�	AuthTestsN)r&r'r(rrrrr*Nsr*c@seZdZdd�ZdS)�CloseSocketTestcCsr|�tjj�tj}t�|�� t|�}|j	}|�
|j�|��|�
|j�Wd�dS1s2wYdSr)�
addCleanup�urllib�request�
urlcleanupr�
TEST_HTTP_URLr�transient_internet�_urlopen_with_retry�fp�assertFalse�closed�close�
assertTrue)r�url�response�sockrrr�
test_closews"�zCloseSocketTest.test_closeN)r&r'r(r;rrrrr+usr+c@sdeZdZdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	e
�d
�dd��Zddd�Z
dd�ZdS)�OtherNetworkTestscCsdSr)�logging�	getLogger�
addHandler�
StreamHandler)rr=�loggerrrr�setUp�rzOtherNetworkTests.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_ftp�s��zOtherNetworkTests.test_ftpc	Cs�tj}t|d�}z+|�d�|��dttj�|��ddt	j
jfg}|j||�
�dd�Wt�|�nt�|�w|�tt	jjd�dS)N�wz	hi there
zfile:zfile:///nonsensename/etc/passwdT)�retryz./relative_path/to/file)r�TESTFN�open�writer6r�os�path�abspathr-rCrDrErF�removeZassertRaises�
ValueErrorr.�urlopen)rrK�frGrrr�	test_file�s

��zOtherNetworkTests.test_filecCs\d}t�|��tj�|�}tj�|�}|�|��d�Wd�dS1s'wYdS)Nz)http://www.pythontest.net/index.html#frag�rr1r-r.�RequestrS�assertEqual�geturl)rZurlwith_frag�req�resrrr�test_urlwithfrag��
�"�z"OtherNetworkTests.test_urlwithfragcCs\d}t�|��tj�|�}tj�|�}|�|��d�Wd�dS1s'wYdS)Nz*http://www.pythontest.net/redir/with_frag/z)http://www.pythontest.net/elsewhere/#fragrV)rZredirect_url_with_fragrZr[rrr�test_redirect_url_withfrag�r]z,OtherNetworkTests.test_redirect_url_withfragcCs�tj}t�|��Ctj��}tj�|�}|�|�	��|�
|�|�|�	��|�|�d��|�
dd�|�
|�|�|�d�d�Wd�dS1sNwYdS)Nz
User-agentz
User-Agentz
Test-Agent)rr0rr1r-r.�build_openerrWr4Zheader_itemsrLr7Z
has_headerZ
add_headerrXZ
get_header)rr8�openerr.rrr�test_custom_headers�s


"�z%OtherNetworkTests.test_custom_headersz XXX: http://www.imdb.com is gonec	Cs�d}t�|��Dztj�|��}Wd�n1swYWnty.|�d�Ynw|�|�tj�|�}|��}|�|�Wd�dS1sNwYdS)Nzhttp://www.imdb.comzOurlopen failed for site not sending                            Connection:close)	rr1r-r.rSrRZfailr7�read)rZURLr[rZrrr�test_sites_no_connection_close�s���
"�z0OtherNetworkTests.test_sites_no_connection_closeTc
Cs�ddl}ddl}|�d�j}tjj|�j}|rt|tj	j
�}|D]�}|j|d���t|t
�r4|\}}	}
nd}	}
t�|���z	|||	tj�}Wn(tyo}z|
rdd|
||	t|�|f}
|�||
|
�n�WYd}~n`d}~wwzDt�8t�&t�|��}|dt|��Wd�n1s�wYWd�n1s�wYWd�n1s�wYWnty�td|tjd�Ynw|��Wd�n1s�wY|�d�Wd�n1s�wYq dS)	NrZtest_urllib2)r8z5Didn't get expected error(s) %s for %s %s, got %s: %sz
read %d bytesz
<timeout: %s>)�fileg�������?) �timer=r>�debugr-r.r_rLrrCrDZsubTest�
isinstance�tuplerr1rZINTERNET_TIMEOUT�OSError�typeZassertIsInstance�time_out�socket_peer_reset�ioerror_peer_resetrb�len�TimeoutError�print�sys�stderrr6�sleep)rrG�handlersrJrer=rfrSr8rZZexpected_errrT�err�msg�bufrrrrE�s`
����������������zOtherNetworkTests._test_urlscCs2g}tj��}|�|j�|�d�|�|�|S)N�)r-r.ZCacheFTPHandlerr,�clear_cacheZ
setTimeout�append)rrtZcfhrrrrFs


z!OtherNetworkTests._extra_handlersN)T)r&r'r(rB�skip_ftp_test_on_travisrHrUr\r^ra�unittest�skiprcrErFrrrrr<�s	
-

'r<c@sheZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdZe	dd
��Z
e	dd��Ze	dd��Ze	dd��Z
dS)�TimeoutTestcCs|�tjj�dSr)r,r-r.r/rrrrrB*szTimeoutTest.setUpcCsp|�t���tj}tj|dd��t|�}|�|j	�|�|j
jj�
��Wd�dS1s1wYdS�N��timeout)�assertIsNone�socket�getdefaulttimeoutrr0rr1r2r,r6r3�raw�_sock�
gettimeout�rr8�urrr�test_http_basic.s"�zTimeoutTest.test_http_basicc
Cs�|�t���tj}t�|��1t�d�zt|�}|�	|j
�Wt�d�nt�d�w|�|jj
j��d�Wd�dS1sCwYdS�N�<)r�r�r�rr0rr1�setdefaulttimeoutr2r,r6rXr3r�r�r�r�rrr�test_http_default_timeout6s
"�z%TimeoutTest.test_http_default_timeoutc
Cs�|�t���tj}t�|��2t�d�zt|dd�}|�	|j
�Wt�d�nt�d�w|�|jjj
���Wd�dS1sDwYdS�Nr�r�)r�r�r�rr0rr1r�r2r,r6r3r�r�r�r�rrr�test_http_no_timeoutBs
"�z TimeoutTest.test_http_no_timeoutcCsdtj}t�|�� t|dd�}|�|j�|�|jj	j
��d�Wd�dS1s+wYdS)N�xr�)rr0rr1r2r,r6rXr3r�r�r�r�rrr�test_http_timeoutNs"�zTimeoutTest.test_http_timeoutzftp://www.pythontest.net/cCsp|�t���tj|jdd��t|j�}|�|j�|�|j	j	j
j���Wd�dS1s1wYdSr)
r�r�r�rr1�FTP_HOSTr2r,r6r3r�r�r��rr�rrr�test_ftp_basicWs
"�zTimeoutTest.test_ftp_basicc
Cs�|�t���t�|j��3t�d�zt|j�}|�|j	�Wt�d�nt�d�w|�
|jjjj
��d�Wd�dS1sCwYdSr�)r�r�r�rr1r�r�r2r,r6rXr3r�r�r�r�rrr�test_ftp_default_timeout_s

"�z$TimeoutTest.test_ftp_default_timeoutc
Cs�|�t���t�|j��4t�d�zt|jdd�}|�|j	�Wt�d�nt�d�w|�|j
j
jj�
��Wd�dS1sDwYdSr�)r�r�r�rr1r�r�r2r,r6r3r�r�r�r�rrr�test_ftp_no_timeoutks
"�zTimeoutTest.test_ftp_no_timeoutcCsdt�|j��"t|jdd�}|�|j�|�|jjjj	�
�d�Wd�dS1s+wYdSr�)rr1r�r2r,r6rXr3r�r�r�r�rrr�test_ftp_timeoutws
"�zTimeoutTest.test_ftp_timeoutN)r&r'r(rBr�r�r�r�r�r{r�r�r�r�rrrrr~)s


r~�__main__)*r)r|�testrZtest.supportrrrZtest.test_urllib2rrNr�Zurllib.errorr-Zurllib.requestrqZrequiresrrZskipIf�environr{r.rSrCrDr2�objectrriZ	ETIMEDOUTrkZ
ECONNRESETrlrmZTestCaser*r+r<r~r&�mainrrrr�<module>sB
	��'%V�