Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/test/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/__pycache__/test_urllibnet.cpython-36.opt-2.pyc

3

��2aQ#�@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�3/opt/alt/python36/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@sNeZdZdZejdd��Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�ZdS)�urlopenNetworkTestszhttp://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)
rrrr!�
contextlib�contextmanagerrr&r*r/r0r4r8rrrr	r s
		rc@sFeZdZejdd��Zdd�Zdd�Zdd�Zd	Z	d
d�Z
dd
�ZdS)�urlretrieveNetworkTestscosP|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<r@rZTESTFNr.r"rArBrCr2r)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<r@r'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<r@�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�_rLrrr	�	<setcomp>�sz:urlretrieveNetworkTests.test_reporthook.<locals>.<setcomp>zblock sizes in %s must be equalz9number of blocks * block size must be >= total size in %s���rT)r<r@�int�reprZ
assertGreater�lenr.ZassertGreaterEqual)rrNr>rIZ
expected_sizeZrecords_reprZblock_sizesr)rMr	�test_reporthook�s$z'urlretrieveNetworkTests.test_reporthookN)rrrr9r:r<r&rDrEr@rJrXrrrr	r;�s
			r;�__main__)ZunittestZtestrr9rZurllib.requestr
rAZ
email.messager+rGZrequiresZTestCaserrr;r�mainrrrr	�<module>s
nK