HEX
Server: Apache
System: Linux opal14.opalstack.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User: curbgloabal_opal (1234)
PHP: 8.1.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/test/__pycache__/test_urllibnet.cpython-36.pyc
3


 \Q#�@s�ddlZddlmZddlZddlZddlZddlZddlZ	ddl
Z
ejd�Gdd�dej�Z
Gdd�dej�ZGdd	�d	ej�Zed
kr�ej�dS)�N)�supportZnetworkc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�URLTimeoutTestg>@cCstj|j�dS)N)�socket�setdefaulttimeout�TIMEOUT)�self�r�&/usr/lib64/python3.6/test_urllibnet.py�setUpszURLTimeoutTest.setUpcCstjd�dS)N)rr)rrrr	�tearDownszURLTimeoutTest.tearDownc	Cs.tjd��tjjd�}|j�WdQRXdS)Nzwww.example.comzhttp://www.example.com/)r�transient_internet�urllib�request�urlopen�read)r�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/cosF|d}tj|��*tjj||�}z
|VWd|j�XWdQRXdS)Nr)rrr
rr�close)r�args�kwargs�resource�rrrr	r1s
zurlopenNetworkTests.urlopencCsP|j|j��:}x"d
D]}|jt||�d|�qW|j|j�d	�WdQRXdS)Nr�readline�	readlines�filenor�info�geturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)rrrrrrr )r�url�
assertTrue�hasattrr)r�open_url�attrrrr	�
test_basic;szurlopenNetworkTests.test_basiccCs@|j|j��*}|j|j�td�|j|j�td�WdQRXdS)Nz readline did not return a stringzreadlines did not return a list)rr!�assertIsInstancer�bytesr�list)rr$rrr	�test_readlinesDs
z"urlopenNetworkTests.test_readlinescCsF|j|j��0}|j�}|j|tjjd�|j|j�d�WdQRXdS)NzEobject returned by 'info' is not an instance of email.message.MessageZhtml)	rr!rr'�email�message�Message�assertEqualZget_content_subtype)rr$Zinfo_objrrr	�	test_infoLs
zurlopenNetworkTests.test_infoc
Cs2|j|j��}|j�}|j||j�WdQRXdS)N)rr!r r.)rr$Z
gotten_urlrrr	�test_geturlUszurlopenNetworkTests.test_geturlcCsn|jd}tj|��P|jt��tjj�j|�}WdQRXz|j	�}Wd|j
�X|j|d�WdQRXdS)NZ
XXXinvalidXXXi�)r!rrZassertWarns�DeprecationWarningr
rZFancyURLopener�openZgetcoderr.)rZURLr$�coderrr	�test_getcode[s

z urlopenNetworkTests.test_getcodecCsjd}ytj|�Wntk
r&YnX|jd|�d}|jt|d��tjjdj|��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_addressgsz$urlopenNetworkTests.test_bad_addressN)rrr�__doc__r!�
contextlib�contextmanagerrr&r*r/r0r4r8rrrr	r s

		rc@sJeZdZdZejdd��Zdd�Zdd�Zdd	�Z	d
Z
dd�Zd
d�ZdS)�urlretrieveNetworkTestsz3Tests urllib.request.urlretrieve using the network.cosP|d}tj|��4tjj||�\}}z||fVWdtj|�XWdQRXdS)Nr)rrr
r�urlretrieve�unlink)rrrr�
file_locationrrrr	r=�sz#urlretrieveNetworkTests.urlretrievecCsZ|j|j��D\}}|jtjj|�d�t|d��}|j|j�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�existsr2r)rr?rrrrr	r&�sz"urlretrieveNetworkTests.test_basiccCsj|j|jtj��P\}}|j|tj�|jtjj|��t	|d��}|j|j
�d�WdQRXWdQRXdS)Nr@z"reading from temporary file failed)r=rArZTESTFNr.r"rBrCrDr2r)rr?rrrrr	�test_specified_path�sz+urlretrieveNetworkTests.test_specified_pathcCs2|j|j��\}}|j|tjjd�WdQRXdS)Nz0info is not an instance of email.message.Message)r=rAr'r+r,r-)rr?rrrr	�test_header�sz#urlretrieveNetworkTests.test_headerzhttp://www.pythontest.net/cCsb|j|j��L\}}|jd�}d}ytj||�Wn"tk
rR|jd|�YnXWdQRXdS)NZDatez%a, %d %b %Y %H:%M:%S GMTzDate value not in %r format)r=rA�get�timeZstrptime�
ValueErrorZfail)rr?�fileheadersZ	datevalueZ
dateformatrrr	�test_data_header�s
z(urlretrieveNetworkTests.test_data_headercsg��fdd�}|j|j|d��\}}t|d�}WdQRXt��}|jt��ddd�|j�ddd�|j�dddd	|d�|j�dd
|�|j�dd
|�dd��D�}|j�ddh|d
|d�|j�dd�dd|d|d�dS)Ncs�j|||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.)r5rzblock size can't be 0 in %s�cSsh|]\}}}|�qSrr)�.0�_rMrrr	�	<setcomp>�sz:urlretrieveNetworkTests.test_reporthook.<locals>.<setcomp>zblock sizes in %s must be equalz9number of blocks * block size must be >= total size in %s���rU)r=rA�int�reprZ
assertGreater�lenr.ZassertGreaterEqual)rrOr?rJZ
expected_sizeZrecords_reprZblock_sizesr)rNr	�test_reporthook�s$z'urlretrieveNetworkTests.test_reporthookN)
rrrr9r:r;r=r&rErFrArKrYrrrr	r<�s
			r<�__main__)ZunittestZtestrr:rZurllib.requestr
rBZ
email.messager+rHZrequiresZTestCaserrr<r�mainrrrr	�<module>s
nK