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.7/test/__pycache__/test_urllibnet.cpython-37.pyc
B

��g�#�@s�ddlZddlmZddlZddlZddlZddlZddlZddl	Z
ddlZe�d�Gdd�dej
�ZGdd�dej
�ZGdd	�d	ej
�Zed
kr�e��dS)�N)�supportZnetworkc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�URLTimeoutTestg>@cCst�|j�dS)N)�socket�setdefaulttimeout�TIMEOUT)�self�r�//usr/local/lib/python3.7/test/test_urllibnet.py�setUpszURLTimeoutTest.setUpcCst�d�dS)N)rr)rrrr	�tearDownszURLTimeoutTest.tearDownc	Cs@tj�tj�j}t�|��tj�tj�}|�	�WdQRXdS)N)
�urllib�parseZurlparserZ
TEST_HTTP_URLZnetloc�transient_internet�request�urlopen�read)r�domain�frrr	�testURLreadszURLTimeoutTest.testURLreadN)�__name__�
__module__�__qualname__rr
rrrrrr	rsrc@sReZdZdZdZejdd��Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dS)�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.

    zhttp://www.pythontest.net/c	osF|d}t�|��*tjj||�}z
|VWd|��XWdQRXdS)Nr)rrrrr�close)r�args�kwargs�resource�rrrr	r3s
zurlopenNetworkTests.urlopenc	CsP|�|j��:}x"dD]}|�t||�d|�qW|�|��d�WdQRXdS)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_basic=s

zurlopenNetworkTests.test_basicc	Cs@|�|j��*}|�|��td�|�|��td�WdQRXdS)Nz readline did not return a stringzreadlines did not return a list)rr#�assertIsInstancer�bytesr�list)rr&rrr	�test_readlinesFs
z"urlopenNetworkTests.test_readlinesc	CsF|�|j��0}|��}|�|tjjd�|�|��d�WdQRXdS)NzEobject returned by 'info' is not an instance of email.message.MessageZhtml)	rr#r!r)�email�message�Message�assertEqualZget_content_subtype)rr&Zinfo_objrrr	�	test_infoNs
zurlopenNetworkTests.test_infoc	Cs2|�|j��}|��}|�||j�WdQRXdS)N)rr#r"r0)rr&Z
gotten_urlrrr	�test_geturlWszurlopenNetworkTests.test_geturlc
Csn|jd}t�|��P|�t��tj���|�}WdQRXz|�	�}Wd|�
�X|�|d�WdQRXdS)NZ
XXXinvalidXXXi�)r#rrZassertWarns�DeprecationWarningrrZFancyURLopener�openZgetcoderr0)rZURLr&�coderrr	�test_getcode]s

z urlopenNetworkTests.test_getcodec	Csjd}yt�|�Wntk
r&YnX|�d|�d}|jt|d��tj�d�|��WdQRXdS)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assertRaisesrrr�format)rZbogus_domainZfailure_explanationrrr	�test_bad_addressisz$urlopenNetworkTests.test_bad_addressN)rrr�__doc__r#�
contextlib�contextmanagerrr(r,r1r2r6r:rrrr	r"s

		rc@sJeZdZdZejdd��Zdd�Zdd�Zdd	�Z	d
Z
dd�Zd
d�ZdS)�urlretrieveNetworkTestsz3Tests urllib.request.urlretrieve using the network.c
osP|d}t�|��4tjj||�\}}z||fVWdt�|�XWdQRXdS)Nr)rrrr�urlretrieve�unlink)rrrr�
file_locationr!rrr	r?�sz#urlretrieveNetworkTests.urlretrievec
CsZ|�|j��D\}}|�tj�|�d�t|d��}|�|��d�WdQRXWdQRXdS)Nz9file location returned by urlretrieve is not a valid path�rbz=reading from the file location returned by urlretrieve failed)r?�logor$�os�path�existsr4r)rrAr!rrrr	r(�sz"urlretrieveNetworkTests.test_basicc
Csj|�|jtj��P\}}|�|tj�|�tj�|��t	|d��}|�|�
�d�WdQRXWdQRXdS)NrBz"reading from temporary file failed)r?rCrZTESTFNr0r$rDrErFr4r)rrAr!rrrr	�test_specified_path�sz+urlretrieveNetworkTests.test_specified_pathc	Cs2|�|j��\}}|�|tjjd�WdQRXdS)Nz0info is not an instance of email.message.Message)r?rCr)r-r.r/)rrAr!rrr	�test_header�sz#urlretrieveNetworkTests.test_headerzhttp://www.pythontest.net/c	Csb|�|j��L\}}|�d�}d}yt�||�Wn"tk
rR|�d|�YnXWdQRXdS)NZDatez%a, %d %b %Y %H:%M:%S GMTzDate value not in %r format)r?rC�get�timeZstrptime�
ValueErrorZfail)rrA�fileheadersZ	datevalueZ
dateformatrrr	�test_data_header�s
z(urlretrieveNetworkTests.test_data_headerc	sg��fdd�}|j|j|d��\}}t|d�}WdQRXt��}|jt��ddd�|��ddd�|j�dddd	|d�|��dd
|�|��dd
|�dd
��D�}|j�ddh|d|d�|j�dd�dd|d|d�dS)Ncs��|||f�dS)N)�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.)r7rzblock size can't be 0 in %s����cSsh|]\}}}|�qSrr)�.0�_rOrrr	�	<setcomp>�sz:urlretrieveNetworkTests.test_reporthook.<locals>.<setcomp>zblock sizes in %s must be equalz9number of blocks * block size must be >= total size in %s)r?rC�int�reprZ
assertGreater�lenr0ZassertGreaterEqual)rrQrArLZ
expected_sizeZrecords_reprZblock_sizesr)rPr	�test_reporthook�s$z'urlretrieveNetworkTests.test_reporthookN)
rrrr;r<r=r?r(rGrHrCrMr[rrrr	r>�s
			r>�__main__)ZunittestZtestrr<rZurllib.parserZurllib.requestrDZ
email.messager-rJZrequiresZTestCaserrr>r�mainrrrr	�<module>s
nK