Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_urllibnet.cpython-35.opt-2.pyc



���]\#�@s�ddlZddlmZddlZddlZddlZddlZddlZddl	Z
ddlZejd�Gdd�dej
�ZGdd�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/python35/lib64/python3.5/test_urllibnet.py�setUpszURLTimeoutTest.setUpcCstjd�dS)N)rr)rrrr	�tearDownszURLTimeoutTest.tearDownc	Cs7tjd��!tjjd�}|j�WdQRXdS)Nzwww.example.comzhttp://www.example.com/)r�transient_internet�urllib�request�urlopen�read)r�frrr	�testURLreadszURLTimeoutTest.testURLreadN)�__name__�
__module__�__qualname__rr
rrrrrr	rsrc@sseZdZdZejdd��Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�ZdS)�urlopenNetworkTestszhttp://www.pythontest.net/cosQ|d}tj|��1tjj||�}z	|VWd|j�XWdQRXdS)Nr)rrr
rr�close)r�args�kwargs�resource�rrrr	r2s
	zurlopenNetworkTests.urlopencCsd|j|j��K}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_basiccCsR|j|j��9}|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_readlinesEs
z"urlopenNetworkTests.test_readlinescCs[|j|j��B}|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_infoMs
zurlopenNetworkTests.test_infoc
Cs?|j|j��&}|j�}|j||j�WdQRXdS)N)rr!r r.)rr$Z
gotten_urlrrr	�test_geturlVszurlopenNetworkTests.test_geturlcCs�|jd}tj|��b|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_getcodecCs}d}ytj|�Wntk
r+YnX|jd|�d}|jtd|��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://{}/)	r�
gethostbyname�OSErrorZskipTestZassertRaisesr
rr�format)rZbogus_domainZfailure_explanationrrr	�test_bad_addresshs
z$urlopenNetworkTests.test_bad_addressN)
rrrr!�
contextlib�contextmanagerrr&r*r/r0r4r9rrrr	r!s
		rc@sgeZdZejdd��Zdd�Zdd�Zdd�Zd	Z	d
d�Z
dd
�ZdS)�urlretrieveNetworkTestscos`|d}tj|��@tjj||�\}}z||fVWdtj|�XWdQRXdS)Nr)rrr
r�urlretrieve�unlink)rrrr�
file_locationrrrr	r=�s
z#urlretrieveNetworkTests.urlretrievecCsq|j|j��X\}}|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&�sz"urlretrieveNetworkTests.test_basiccCs�|j|jtj��h\}}|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_pathcCs?|j|j��&\}}|j|tjjd�WdQRXdS)Nz0info is not an instance of email.message.Message)r=rAr'r+r,r-)rr?rrrr	�test_header�sz#urlretrieveNetworkTests.test_headerzhttp://www.pythontest.net/cCsu|j|j��\\}}|jd�}d}ytj||�Wn#tk
ri|jd|�YnXWdQRXdS)NZDatez%a, %d %b %Y %H:%M:%S GMTzDate value not in %r format)r=rA�get�time�strptime�
ValueErrorZfail)rr?�fileheadersZ	datevalueZ
dateformatrrr	�test_data_header�s
z(urlretrieveNetworkTests.test_data_headerc
sLg��fdd�}|j|jd|��\}}t|d�}WdQRXt��}|jt��ddd�|j�ddd�|j�ddddd	|�|j�dd
|�|j�dd
|�dd��D�}|j�ddh|dd
|�|j�dd�dd|dd|�dS)Ncs�j|||f�dS)N)�append)Zblocks�
block_sizeZ
total_size)�recordsrr	�recording_reporthook�szEurlretrieveNetworkTests.test_reporthook.<locals>.recording_reporthookZ
reporthookzContent-Length�r5zKThere should always be two calls; the first one before the transfer starts.rzblock size can't be 0 in %s�cSsh|]\}}}|�qSrr)�.0�_rNrrr	�	<setcomp>�s	z:urlretrieveNetworkTests.test_reporthook.<locals>.<setcomp>zblock sizes in %s must be equalz9number of blocks * block size must be >= total size in %s���rV)r=rA�int�reprZ
assertGreater�lenr.ZassertGreaterEqual)rrPr?rKZ
expected_sizeZrecords_reprZblock_sizesr)rOr	�test_reporthook�s$	#z'urlretrieveNetworkTests.test_reporthookN)rrrr:r;r=r&rErFrArLrZrrrr	r<�s
			r<�__main__)ZunittestZtestrr:rZurllib.requestr
�sysrBZ
email.messager+rHZrequiresZTestCaserrr<r�mainrrrr	�<module>s
nK