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_urllibnet.cpython-310.pyc
o

�iK%�@s�ddlZddlmZddlmZddlmZddlZddlZddlZ	ddl
Z	ddlZddlZ
ddlZe�d�Gdd�dej�ZGdd	�d	ej�ZGd
d�dej�Zedkr\e��dSdS)
�N)�support)�	os_helper)�
socket_helperZnetworkc@s$eZdZdd�Zdd�Zdd�ZdS)�URLTimeoutTestcCst�tj�dS�N)�socket�setdefaulttimeoutrZINTERNET_TIMEOUT��self�r�0/usr/local/lib/python3.10/test/test_urllibnet.py�setUpszURLTimeoutTest.setUpcCst�d�dSr)rrr	rrr�tearDownszURLTimeoutTest.tearDowncCsd|�tjj�tj�tj�j}t	�
|��tj�tj�}|��Wd�dS1s+wYdSr)
�
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rsrc@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/cC�|�tjj�dSr�rrrrr	rrrr
6�zurlopenNetworkTests.setUpc	osj�|d}t�|��!tjj|i|��}z	|VW|��n|��wWd�dS1s.wYdS�Nr)rrrrr�close)r
�args�kwargs�resource�rrrrr:s�"�zurlopenNetworkTests.urlopencCsb|�|j��!}dD]
}|�t||�d|�q	|�|��d�Wd�dS1s*wYdS)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_basicDs�"�zurlopenNetworkTests.test_basiccCsV|�|j��}|�|��td�|�|��td�Wd�dS1s$wYdS)Nz readline did not return a stringzreadlines did not return a list)rr/�assertIsInstancer*�bytesr+�list)r
r2rrr�test_readlinesMs��"�z"urlopenNetworkTests.test_readlinescCs\|�|j��}|��}|�|tjjd�|�|��d�Wd�dS1s'wYdS)NzEobject returned by 'info' is not an instance of email.message.MessageZhtml)	rr/r-r5�email�message�Message�assertEqualZget_content_subtype)r
r2Zinfo_objrrr�	test_infoUs�"�zurlopenNetworkTests.test_infocCsH|�|j��}|��}|�||j�Wd�dS1swYdSr)rr/r.r<)r
r2Z
gotten_urlrrr�test_geturl^s"�zurlopenNetworkTests.test_geturlc	Cs�|jd}t�|��<|�t��tj���|�}Wd�n1s#wYz
|�	�}W|�
�n|�
�w|�|d�Wd�dS1sIwYdS)NZ
XXXinvalidXXXi�)r/rrZassertWarns�DeprecationWarningrrZFancyURLopener�openZgetcoder%r<)r
ZURLr2�coderrr�test_getcodeds
�
"�z urlopenNetworkTests.test_getcodecCs~d}zt�|�Wn	tyYnw|�d|�d}|jt|d��tj�d�|��Wd�dS1s8wYdS)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_addressps�"�z$urlopenNetworkTests.test_bad_addressN)rrr�__doc__r/r
�
contextlib�contextmanagerrr4r8r=r>rBrHrrrr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.cCr!rr"r	rrrr
�r#zurlretrieveNetworkTests.setUpc
osv�|d}t�|��'tjj|i|��\}}z||fVWt�|�nt�|�wWd�dS1s4wYdSr$)rrrr�urlretriever�unlink)r
r&r'r(�
file_locationr-rrrrM�s�"�z#urlretrieveNetworkTests.urlretrievec	Cs�|�|j��:\}}|�tj�|�d�t|d��}|�|��d�Wd�n1s+wYWd�dSWd�dS1sCwYdS)Nz9file location returned by urlretrieve is not a valid path�rbz=reading from the file location returned by urlretrieve failed)rM�logor0�os�path�existsr@r�r
rOr-rrrrr4�s��"�z"urlretrieveNetworkTests.test_basicc	Cs�|�|jtj��@\}}|�|tj�|�tj�|��t	|d��}|�|�
�d�Wd�n1s3wYWd�dSWd�dS1sKwYdS)NrPz"reading from temporary file failed)rMrQrZTESTFNr<r0rRrSrTr@rrUrrr�test_specified_path�s���"�z+urlretrieveNetworkTests.test_specified_pathcCsH|�|j��\}}|�|tjjd�Wd�dS1swYdS)Nz0info is not an instance of email.message.Message)rMrQr5r9r:r;)r
rOr-rrr�test_header�s
�"�z#urlretrieveNetworkTests.test_headerr c	Cs�|�|j��3\}}|�d�}d}zt�||�Wnty(|�d|�Yn	wWd�dSWd�dS1s<wYdS)NZDatez%a, %d %b %Y %H:%M:%S GMTzDate value not in %r format)rMrQ�get�time�strptime�
ValueErrorZfail)r
rO�fileheadersZ	datevalueZ
dateformatrrr�test_data_header�s
���"�z(urlretrieveNetworkTests.test_data_headercsg��fdd�}|j|j|d��\}}t|d�}Wd�n1s#wYt��}|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.rCrzblock size can't be 0 in %s����cSsh|]\}}}|�qSrr)�.0�_r_rrr�	<setcomp>�sz:urlretrieveNetworkTests.test_reporthook.<locals>.<setcomp>zblock sizes in %s must be equalz9number of blocks * block size must be >= total size in %s)rMrQ�int�reprZ
assertGreater�lenr<ZassertGreaterEqual)r
rbrOr\Z
expected_sizeZrecords_reprZblock_sizesrr`r�test_reporthook�s.����
�z'urlretrieveNetworkTests.test_reporthookN)rrrrIr
rJrKrMr4rVrWrQr]rlrrrrrL�s
				rL�__main__)Zunittest�testrZtest.supportrrrJr�urllib.parserZurllib.requestrRZ
email.messager9rYZrequiresZTestCaserrrLr�mainrrrr�<module>s$
rO�