Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_urllibnet.cpython-34.pyo

�
f f##�@s�ddlZddlmZddlZddlZddlZddlZddlZddl	Z
ddlZejd�Gdd�dej
�ZGdd�dej
�ZGdd	�d	ej
�Zed
kr�ej�ndS)�N)�supportZnetworkc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�URLTimeoutTestg>@cCstj|j�dS)N)�socket�setdefaulttimeout�TIMEOUT)�self�r�8/opt/alt/python34/lib64/python3.4/test/test_urllibnet.py�setUpszURLTimeoutTest.setUpcCstjd�dS)N)rr)rrrr	�tearDownszURLTimeoutTest.tearDownc	Cs8tjd��#tjjd�}|j�}WdQXdS)Nzwww.example.comzhttp://www.example.com/)r�transient_internet�urllib�request�urlopen�read)r�f�xrrr	�testURLreadszURLTimeoutTest.testURLreadN)�__name__�
__module__�__qualname__rr
rrrrrr	rsrc@s�eZdZdZejdd��Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zej
ejdkd�dd��Zdd�ZdS)�urlopenNetworkTestsa=Tests urllib.reqest.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.example.com/ since there a few tests that don't use that address
    and making a connection is expensive enough to warrant minimizing unneeded
    connections.

    cosP|d}tj|��1tjj||�}z	|VWd|j�XWdQXdS)Nr)rrr
rr�close)r�args�kwargs�resource�rrrr	r/s
	zurlopenNetworkTests.urlopencCs`|jd��K}x+dD]#}|jt||�d	|�qW|j|j�d
�WdQXdS)Nzhttp://www.example.com/r�readline�	readlines�filenor�info�geturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)zreadzreadlinez	readlineszfilenozclosezinfozgeturl)r�
assertTrue�hasattrr)r�open_url�attrrrr	�
test_basic9s
zurlopenNetworkTests.test_basiccCsN|jd��9}|j|j�td�|j|j�td�WdQXdS)Nzhttp://www.example.com/z readline did not return a stringzreadlines did not return a list)r�assertIsInstancer�bytesr�list)rr$rrr	�test_readlinesBs
z"urlopenNetworkTests.test_readlinescCsW|jd��B}|j�}|j|tjjd�|j|j�d�WdQXdS)Nzhttp://www.example.com/zEobject returned by 'info' is not an instance of email.message.MessageZhtml)rr r'�email�message�Message�assertEqualZget_content_subtype)rr$Zinfo_objrrr	�	test_infoJs
zurlopenNetworkTests.test_infoc
Cs>d}|j|��#}|j�}|j||�WdQXdS)Nzhttp://www.example.com/)rr!r.)r�URLr$Z
gotten_urlrrr	�test_geturlSszurlopenNetworkTests.test_geturlcCs|d}tj|��a|jt��tjj�j|�}WdQXz|j�}Wd|j	�X|j
|d�WdQXdS)Nz'http://www.pythontest.net/XXXinvalidXXXi�)rrZassertWarns�DeprecationWarningr
rZFancyURLopener�openZgetcoderr.)rr0r$�coderrr	�test_getcodeZsz urlopenNetworkTests.test_getcode�win32znot appropriate for WindowscCs_|jddd��D}|j�}tj|d��}|j|j�d�WdQXWdQXdS)Nzhttp://www.google.com/Ztimeout�rbz<reading from file created using fd returned by fileno failed)rr�os�fdopenr"r)rr$�fdrrrr	�test_filenohszurlopenNetworkTests.test_filenocCssd}ytj|�Wntk
r+YnX|jd|�d}|jtd|��tjjd�WdQXdS)Nzsadflkjsasf.i.nvali.dz&%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)�msgzhttp://sadflkjsasf.i.nvali.d/)rZ
gethostbyname�OSErrorZskipTestZassertRaisesr
rr)rZbogus_domainZfailure_explanationrrr	�test_bad_addressqs
z$urlopenNetworkTests.test_bad_addressN)zwin32)rrr�__doc__�
contextlib�contextmanagerrr&r*r/r1r5�unittestZskipIf�sys�platformr;r>rrrr	r s

		'	rc@smeZdZdZejdd��Zdd�Zdd�Zdd	�Z	d
Z
dd�Zd
d�ZdS)�urlretrieveNetworkTestsz3Tests urllib.request.urlretrieve using the network.cos_|d}tj|��@tjj||�\}}z||fVWdtj|�XWdQXdS)Nr)rrr
r�urlretrieve�unlink)rrrr�
file_locationr rrr	rF�s
z#urlretrieveNetworkTests.urlretrievecCsl|jd��W\}}|jtjj|�d�t|d��}|j|j�d�WdQXWdQXdS)Nzhttp://www.example.com/z9file location returned by urlretrieve is not a valid pathr7z=reading from the file location returned by urlretrieve failed)rFr"r8�path�existsr3r)rrHr rrrr	r&�sz"urlretrieveNetworkTests.test_basiccCs�|jdtj��g\}}|j|tj�|jtjj|��t|d��}|j|j	�d�WdQXWdQXdS)Nzhttp://www.example.com/r7z"reading from temporary file failed)
rFrZTESTFNr.r"r8rIrJr3r)rrHr rrrr	�test_specified_path�s	z+urlretrieveNetworkTests.test_specified_pathcCs;|jd��&\}}|j|tjjd�WdQXdS)Nzhttp://www.example.com/z0info is not an instance of email.message.Message)rFr'r+r,r-)rrHr rrr	�test_header�sz#urlretrieveNetworkTests.test_headerzhttp://www.example.com/cCss|j|j��[\}}|jd�}d}ytj||�Wn"tk
rh|jd|�YnXWdQXdS)NZDatez%a, %d %b %Y %H:%M:%S GMTzDate value not in %r format)rF�logo�get�timeZstrptime�
ValueErrorZfail)rrH�fileheadersZ	datevalueZ
dateformatrrr	�test_data_header�s
z(urlretrieveNetworkTests.test_data_headercsKg��fdd�}|j|jd|��\}}t|d�}WdQXt��}|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�r<zKThere should always be two calls; the first one before the transfer starts.rzblock size can't be 0 in %s�cSsh|]\}}}|�qSrr)�.0�_rTrrr	�	<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���r\)rFrM�int�reprZ
assertGreater�lenr.ZassertGreaterEqual)rrVrHrQZ
expected_sizeZrecords_reprZblock_sizesr)rUr	�test_reporthook�s$	#z'urlretrieveNetworkTests.test_reporthookN)
rrrr?r@rArFr&rKrLrMrRr`rrrr	rE�s
			rE�__main__)rBZtestrr@rZurllib.requestr
rCr8Z
email.messager+rOZrequiresZTestCaserrrEr�mainrrrr	�<module>s
jJ