Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_urllibnet.cpython-39.opt-1.pyc

a

��g"%�@s�ddlZddlmZddlmZddlZddlZddlZddl	Zddl
Z
ddlZddl
Z
e�d�Gdd�dej�ZGdd�dej�ZGd	d
�d
ej�Zedkr�e��dS)�N)�support)�
socket_helper�networkc@s$eZdZdd�Zdd�Zdd�ZdS)�URLTimeoutTestcCst�tj�dS�N)�socket�setdefaulttimeoutrZINTERNET_TIMEOUT��self�r�//usr/local/lib/python3.9/test/test_urllibnet.py�setUpszURLTimeoutTest.setUpcCst�d�dSr)rrr	rrr�tearDownszURLTimeoutTest.tearDowncCsb|�tjj�tj�tj�j}t	�
|��&tj�tj�}|��Wd�n1sT0YdSr)
�
addCleanup�urllib�request�
urlcleanup�parse�urlparserZ
TEST_HTTP_URL�netlocr�transient_internet�urlopen�read)r
�domain�frrr�testURLreads
zURLTimeoutTest.testURLreadN)�__name__�
__module__�__qualname__r
rrrrrrrsrc@sZeZdZdZdZdd�Zejdd��Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZdS)�urlopenNetworkTestsaATests urllib.request.urlopen using the network.

    These tests are not exhaustive.  Assuming that testing using files does a
    good job overall of some of the basic interface features.  There are no
    tests exercising the optional 'data' and 'proxies' arguments.  No tests
    for transparent redirection have been written.

    setUp is not used for always constructing a connection to
    http://www.pythontest.net/ since there a few tests that don't use that address
    and making a connection is expensive enough to warrant minimizing unneeded
    connections.

    �http://www.pythontest.net/cCs|�tjj�dSr�rrrrr	rrrr
5szurlopenNetworkTests.setUpc	osf|d}t�|��@tjj|i|��}z|VW|��n
|��0Wd�n1sX0YdS�Nr)rrrrr�close)r
�args�kwargs�resource�rrrrr9s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�attrrrr�
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
r0rrr�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+r3�email�message�Message�assertEqualZget_content_subtype)r
r0Zinfo_objrrr�	test_infoTs�zurlopenNetworkTests.test_infocCsF|�|j��&}|��}|�||j�Wd�n1s80YdSr)rr-r,r:)r
r0Z
gotten_urlrrr�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�openZgetcoder#r:)r
ZURLr0�coderrr�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://{}/)	r�
gethostbyname�OSErrorZskipTestZassertRaisesrrr�format)r
Zbogus_domainZfailure_explanationrrr�test_bad_addressosz$urlopenNetworkTests.test_bad_addressN)rrr�__doc__r-r
�
contextlib�contextmanagerrr2r6r;r<r@rFrrrrr$s
			rc@sReZdZdZdd�Zejdd��Zdd�Zdd	�Z	d
d�Z
dZd
d�Zdd�Z
dS)�urlretrieveNetworkTestsz3Tests urllib.request.urlretrieve using the network.cCs|�tjj�dSrr!r	rrrr
�szurlretrieveNetworkTests.setUpc
osr|d}t�|��Ltjj|i|��\}}z||fVWt�|�nt�|�0Wd�n1sd0YdSr")rrrr�urlretriever�unlink)r
r$r%r&�
file_locationr+rrrrK�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)rK�logor.�os�path�existsr>r�r
rMr+rrrrr2�sz"urlretrieveNetworkTests.test_basicc	Cs�|�|jtj��n\}}|�|tj�|�tj�|��t	|d�� }|�|�
�d�Wd�n1sf0YWd�n1s�0YdS)NrNz"reading from temporary file failed)rKrOrZTESTFNr:r.rPrQrRr>rrSrrr�test_specified_path�s�z+urlretrieveNetworkTests.test_specified_pathcCsF|�|j��&\}}|�|tjjd�Wd�n1s80YdS)Nz0info is not an instance of email.message.Message)rKrOr3r7r8r9)r
rMr+rrr�test_header�s�z#urlretrieveNetworkTests.test_headerr c	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)rKrO�get�time�strptime�
ValueErrorZfail)r
rM�fileheadersZ	datevalueZ
dateformatrrr�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��recordsrr�recording_reporthook�szEurlretrieveNetworkTests.test_reporthook.<locals>.recording_reporthook)Z
reporthookzContent-Length�zKThere should always be two calls; the first one before the transfer starts.rArzblock size can't be 0 in %s����cSsh|]\}}}|�qSrr)�.0�_r]rrr�	<setcomp>��z:urlretrieveNetworkTests.test_reporthook.<locals>.<setcomp>zblock sizes in %s must be equalz9number of blocks * block size must be >= total size in %s)rKrO�int�reprZ
assertGreater�lenr:ZassertGreaterEqual)r
r`rMrZZ
expected_sizeZrecords_reprZblock_sizesrr^r�test_reporthook�s,*����z'urlretrieveNetworkTests.test_reporthookN)rrrrGr
rHrIrKr2rTrUrOr[rkrrrrrJ�s
				rJ�__main__)Zunittest�testrZtest.supportrrHr�urllib.parserZurllib.requestrPZ
email.messager7rWZrequiresZTestCaserrrJr�mainrrrr�<module>s
rO

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists