Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_urllibnet.cpython-39.opt-2.pyc

a

XC?h"%�@s�ddlZddlmZddlmZddlZddlZddlZddl	Zddl
Z
ddlZddl
Z
e�d�Gdd�dej�ZGdd�dej�ZGd	d
�d
ej�Zedkr�e��dS)�N)�support)�
socket_helperZnetworkc@s$eZdZdd�Zdd�Zdd�ZdS)�URLTimeoutTestcCst�tj�dS�N)�socket�setdefaulttimeoutrZINTERNET_TIMEOUT��self�r
�8/opt/alt/python39/lib64/python3.9/test/test_urllibnet.py�setUpszURLTimeoutTest.setUpcCst�d�dSr)rrrr
r
r�tearDownszURLTimeoutTest.tearDowncCsb|�tjj�tj�tj�j}t	�
|��&tj�tj�}|��Wd�n1sT0YdSr)
�
addCleanup�urllib�request�
urlcleanup�parseZurlparserZ
TEST_HTTP_URLZnetlocr�transient_internet�urlopen�read)r	Zdomain�fr
r
r�testURLreads
zURLTimeoutTest.testURLreadN)�__name__�
__module__�__qualname__rr
rr
r
r
rrsrc@sVeZdZdZdd�Zejdd��Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dS)�urlopenNetworkTests�http://www.pythontest.net/cCs|�tjj�dSr�rrrrrr
r
rr5szurlopenNetworkTests.setUpc	osf|d}t�|��@tjj|i|��}z|VW|��n
|��0Wd�n1sX0YdS�Nr)rrrrr�close)r	�args�kwargs�resource�rr
r
rr9szurlopenNetworkTests.urlopencCs`|�|j��@}dD]}|�t||�d|�q|�|��d�Wd�n1sR0YdS)N)r�readline�	readlines�filenor�info�geturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)r�url�
assertTrue�hasattrr)r	�open_url�attrr
r
r�
test_basicCs�zurlopenNetworkTests.test_basiccCsT|�|j��4}|�|��td�|�|��td�Wd�n1sF0YdS)Nz readline did not return a stringzreadlines did not return a list)rr)�assertIsInstancer$�bytesr%�list)r	r,r
r
r�test_readlinesLs��z"urlopenNetworkTests.test_readlinescCsZ|�|j��:}|��}|�|tjjd�|�|��d�Wd�n1sL0YdS)NzEobject returned by 'info' is not an instance of email.message.MessageZhtml)	rr)r'r/�email�message�Message�assertEqualZget_content_subtype)r	r,Zinfo_objr
r
r�	test_infoTs�zurlopenNetworkTests.test_infocCsF|�|j��&}|��}|�||j�Wd�n1s80YdSr)rr)r(r6)r	r,Z
gotten_urlr
r
r�test_geturl]szurlopenNetworkTests.test_geturlc	Cs�|jd}t�|��v|�t�� tj���|�}Wd�n1sF0Yz|�	�}W|�
�n
|�
�0|�|d�Wd�n1s�0YdS)NZ
XXXinvalidXXXi�)r)rrZassertWarns�DeprecationWarningrrZFancyURLopener�openZgetcoderr6)r	ZURLr,�coder
r
r�test_getcodecs
.
z urlopenNetworkTests.test_getcodecCs|d}zt�|�Wnty$Yn0|�d|�d}|jt|d��"tj�d�|��Wd�n1sn0YdS)Nzsadflkjsasf.i.nvali.d.z&%r should not resolve for test to workzuopening an invalid URL did not raise OSError; can be caused by a broken DNS server (e.g. returns 404 or hijacks page)��msgz
http://{}/)	rZ
gethostbyname�OSErrorZskipTestZassertRaisesrrr�format)r	Zbogus_domainZfailure_explanationr
r
r�test_bad_addressosz$urlopenNetworkTests.test_bad_addressN)rrrr)r�
contextlib�contextmanagerrr.r2r7r8r<rAr
r
r
rr$s
			rc@sNeZdZdd�Zejdd��Zdd�Zdd�Zd	d
�Z	dZ
dd
�Zdd�ZdS)�urlretrieveNetworkTestscCs|�tjj�dSrrrr
r
rr�szurlretrieveNetworkTests.setUpc
osr|d}t�|��Ltjj|i|��\}}z||fVWt�|�nt�|�0Wd�n1sd0YdSr)rrrr�urlretriever�unlink)r	r r!r"�
file_locationr'r
r
rrE�sz#urlretrieveNetworkTests.urlretrievec	Cs�|�|j��b\}}|�tj�|�d�t|d�� }|�|��d�Wd�n1sV0YWd�n1st0YdS)Nz9file location returned by urlretrieve is not a valid path�rbz=reading from the file location returned by urlretrieve failed)rE�logor*�os�path�existsr:r�r	rGr'rr
r
rr.�sz"urlretrieveNetworkTests.test_basicc	Cs�|�|jtj��n\}}|�|tj�|�tj�|��t	|d�� }|�|�
�d�Wd�n1sf0YWd�n1s�0YdS)NrHz"reading from temporary file failed)rErIrZTESTFNr6r*rJrKrLr:rrMr
r
r�test_specified_path�s�z+urlretrieveNetworkTests.test_specified_pathcCsF|�|j��&\}}|�|tjjd�Wd�n1s80YdS)Nz0info is not an instance of email.message.Message)rErIr/r3r4r5)r	rGr'r
r
r�test_header�s�z#urlretrieveNetworkTests.test_headerrc	Cst|�|j��T\}}|�d�}d}zt�||�Wn tyP|�d|�Yn0Wd�n1sf0YdS)NZDatez%a, %d %b %Y %H:%M:%S GMTzDate value not in %r format)rErI�get�time�strptime�
ValueErrorZfail)r	rG�fileheadersZ	datevalueZ
dateformatr
r
r�test_data_header�s
z(urlretrieveNetworkTests.test_data_headercsg��fdd�}|j|j|d�� \}}t|d�}Wd�n1sF0Yt��}|jt��ddd�|��ddd�|j�dddd	|d�|��dd
|�|��dd
|�dd
��D�}|j�ddh|d|d�|j�dd�dd|d|d�dS)Ncs��|||f�dSr)�append)Zblocks�
block_sizeZ
total_size�Zrecordsr
r�recording_reporthook�szEurlretrieveNetworkTests.test_reporthook.<locals>.recording_reporthook)Z
reporthookzContent-Length�zKThere should always be two calls; the first one before the transfer starts.r=rzblock size can't be 0 in %s����cSsh|]\}}}|�qSr
r
)�.0�_rWr
r
r�	<setcomp>��z:urlretrieveNetworkTests.test_reporthook.<locals>.<setcomp>zblock sizes in %s must be equalz9number of blocks * block size must be >= total size in %s)rErI�int�reprZ
assertGreater�lenr6ZassertGreaterEqual)r	rYrGrTZ
expected_sizeZrecords_reprZblock_sizesr
rXr�test_reporthook�s,*����z'urlretrieveNetworkTests.test_reporthookN)
rrrrrBrCrEr.rNrOrIrUrdr
r
r
rrD�s
				rD�__main__)Zunittest�testrZtest.supportrrBrZurllib.parserZurllib.requestrJZ
email.messager3rQZrequiresZTestCaserrrDr�mainr
r
r
r�<module>s
rO