Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_urllib2net.cpython-310.pyc

o

0�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�;/opt/alt/python310/lib64/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*eZdZdZdd�Zdd�Zd	dd�ZdS)
�TransientResourcez�Raise ResourceDenied if an exception is raised while the context manager
    is in effect that matches the specified exception and attributes.cKs||_||_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)z�If type_ is a subclass of self.exc and value has attributes matching
        self.attrs, raise ResourceDenied.  Otherwise let the exception
        propagate (if any).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__�__doc__rrr%rrrrr-s
r)�errnoc@seZdZdZdS)�	AuthTestsz&Tests urllib2 authentication features.N)r&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�urlZresponseZsockrrr�
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�	getLoggerZ
addHandlerZ
StreamHandler)rr<Zloggerrrr�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�writer7r�os�path�abspathr.r?r@rArB�removeZassertRaises�
ValueErrorr/�urlopen)rrG�frCrrr�	test_file�s

��zOtherNetworkTests.test_filecCs\d}t�|��tj�|�}tj�|�}|�|��d�Wd�dS1s'wYdS)Nz)http://www.pythontest.net/index.html#frag�rr2r.r/�RequestrO�assertEqualZgeturl)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/#fragrR)rZredirect_url_with_fragrUrVrrr�test_redirect_url_withfrag�rXz,OtherNetworkTests.test_redirect_url_withfragcCs�tj}t�|��Ctj��}tj�|�}|�|�	��|�
|�|�|�	��|�|�d��|�
dd�|�
|�|�|�d�d�Wd�dS1sNwYdS)Nz
User-agentz
User-Agentz
Test-Agent)rr1rr2r.r/�build_openerrSr5Zheader_itemsrHr8Z
has_headerZ
add_headerrTZ
get_header)rr9Zopenerr/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)	rr2r.r/rOrNZfailr8�read)rZURLrVrUrrr�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)r9z5Didn't get expected error(s) %s for %s %s, got %s: %sz
read %d bytesz
<timeout: %s>)�fileg�������?) �timer<r=�debugr.r/rZrHrr?r@ZsubTest�
isinstance�tuplerr2rZINTERNET_TIMEOUT�OSError�typeZassertIsInstance�time_out�socket_peer_reset�ioerror_peer_resetr\�len�TimeoutError�print�sys�stderrr7�sleep)rrC�handlersrFr_r<r`rOr9rUZexpected_errrP�err�msgZbufrrrrA�s`
����������������zOtherNetworkTests._test_urlscCs2g}tj��}|�|j�|�d�|�|�|S)N�)r.r/ZCacheFTPHandlerr-Zclear_cacheZ
setTimeout�append)rrnZcfhrrrrBs


z!OtherNetworkTests._extra_handlersN)T)r&r'r(r>�skip_ftp_test_on_travisrDrQrWrYr[�unittest�skipr]rArBrrrrr;�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/r0rrrrr>*szTimeoutTest.setUpcCsp|�t���tj}tj|dd��t|�}|�|j	�|�|j
jj�
��Wd�dS1s1wYdS�N�Ztimeout)�assertIsNone�socket�getdefaulttimeoutrr1rr2r3r-r7r4�raw�_sock�
gettimeout�rr9�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�<)ryrzr{rr1rr2�setdefaulttimeoutr3r-r7rTr4r|r}r~rrrr�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�rx)ryrzr{rr1rr2r�r3r-r7r4r|r}r~rrrr�test_http_no_timeoutBs
"�z TimeoutTest.test_http_no_timeoutcCsdtj}t�|�� t|dd�}|�|j�|�|jj	j
��d�Wd�dS1s+wYdS)N�xrx)rr1rr2r3r-r7rTr4r|r}r~rrrr�test_http_timeoutNs"�zTimeoutTest.test_http_timeoutzftp://www.pythontest.net/cCsp|�t���tj|jdd��t|j�}|�|j�|�|j	j	j
j���Wd�dS1s1wYdSrw)
ryrzr{rr2�FTP_HOSTr3r-r7r4r|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�)ryrzr{rr2r�r�r3r-r7rTr4r|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�)ryrzr{rr2r�r�r3r-r7r4r|r}r~r�rrr�test_ftp_no_timeoutks
"�zTimeoutTest.test_ftp_no_timeoutcCsdt�|j��"t|jdd�}|�|j�|�|jjjj	�
�d�Wd�dS1s+wYdSr�)rr2r�r3r-r7rTr4r|r}r~r�rrr�test_ftp_timeoutws
"�zTimeoutTest.test_ftp_timeoutN)r&r'r(r>r�r�r�r�r�rsr�r�r�r�rrrrrv)s


rv�__main__)*r*rt�testrZtest.supportrrrZtest.test_urllib2rrJrzZurllib.errorr.Zurllib.requestrkZrequiresrrZskipIf�environrsr/rOr?r@r3�objectrrcZ	ETIMEDOUTreZ
ECONNRESETrfrgZTestCaser+r,r;rvr&�mainrrrr�<module>sB
	��'%V�