Sindbad~EG File Manager
a
��g"% � @ s� d dl Z d dlmZ d dlmZ d dlZd dlZd dlZd dl Zd dl
Z
d dlZd dl
Z
e�d� G dd� de j�ZG dd� de j�ZG d d
� d
e j�Zedkr�e �� dS )� N)�support)�
socket_helper�networkc @ s$ e Zd Zdd� Zdd� Zdd� ZdS )�URLTimeoutTestc C s t �tj� d S �N)�socket�setdefaulttimeoutr ZINTERNET_TIMEOUT��self� r �//usr/local/lib/python3.9/test/test_urllibnet.py�setUp s zURLTimeoutTest.setUpc C s t �d � d S r )r r r r r r �tearDown s zURLTimeoutTest.tearDownc C sb | � tjj� tj�tj�j}t �
|��& tj�tj�}|�� W d � n1 sT0 Y d S r )
�
addCleanup�urllib�request�
urlcleanup�parse�urlparser Z
TEST_HTTP_URL�netlocr �transient_internet�urlopen�read)r
�domain�fr r r �testURLread s
zURLTimeoutTest.testURLreadN)�__name__�
__module__�__qualname__r
r r r r r r r s r c @ sZ e Zd ZdZdZdd� Zejdd� �Zdd� Z d d
� Z
dd� Zd
d� Zdd� Z
dd� ZdS )�urlopenNetworkTestsaA Tests 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.
�http://www.pythontest.net/c C s | � tjj� d S r �r r r r r r r r r
5 s zurlopenNetworkTests.setUpc o sf |d }t �|��@ tjj|i |��}z|V W |�� n
|�� 0 W d � n1 sX0 Y d S �Nr )r r r r r �close)r
�args�kwargs�resource�rr r r r 9 s zurlopenNetworkTests.urlopenc C s` | � | j��@}dD ]}| �t||�d| � q| �|�� d� W d � n1 sR0 Y d S )N)r �readline� readlines�filenor# �info�geturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)r �url�
assertTrue�hasattrr )r
�open_url�attrr r r �
test_basicC s �zurlopenNetworkTests.test_basicc C sT | � | j��4}| �|�� td� | �|�� td� W d � n1 sF0 Y d S )Nz readline did not return a stringzreadlines did not return a list)r r- �assertIsInstancer( �bytesr) �list)r
r0 r r r �test_readlinesL s ��z"urlopenNetworkTests.test_readlinesc C sZ | � | j��:}|�� }| �|tjjd� | �|�� d� W d � n1 sL0 Y d S )NzEobject returned by 'info' is not an instance of email.message.MessageZhtml) r r- r+ r3 �email�message�Message�assertEqualZget_content_subtype)r
r0 Zinfo_objr r r � test_infoT s �zurlopenNetworkTests.test_infoc C sF | � | j��&}|�� }| �|| j� W d � n1 s80 Y d S r )r r- r, r: )r
r0 Z
gotten_urlr r r �test_geturl] s zurlopenNetworkTests.test_geturlc C s� | j d }t�|��v | �t�� tj�� �|�}W d � n1 sF0 Y z|� � }W |�
� n
|�
� 0 | �|d� W d � n1 s�0 Y d S )NZ
XXXinvalidXXXi� )r- r r ZassertWarns�DeprecationWarningr r ZFancyURLopener�openZgetcoder# r: )r
ZURLr0 �coder r r �test_getcodec s
.
z urlopenNetworkTests.test_getcodec C s| d}zt �|� W n ty$ Y n0 | �d| � d}| jt|d��" tj�d�|�� W d � n1 sn0 Y d S )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�OSErrorZskipTestZassertRaisesr r r �format)r
Zbogus_domainZfailure_explanationr r r �test_bad_addresso s z$urlopenNetworkTests.test_bad_addressN)r r r �__doc__r- r
�
contextlib�contextmanagerr r2 r6 r; r<