Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_urllibnet.cpython-311.opt-2.pyc
�

�KeK%��*�ddlZddlmZddlmZddlmZddlZddlZddlZ	ddl
Z	ddlZddlZ
ddlZejd��Gd�dej��ZGd�d	ej��ZGd
�dej��Zedkrej��dSdS)
�N)�support)�	os_helper)�
socket_helper�networkc� �eZdZd�Zd�Zd�ZdS)�URLTimeoutTestc�B�tjtj��dS�N)�socket�setdefaulttimeoutr�INTERNET_TIMEOUT��selfs �=/usr/local/apps/python3/lib/python3.11/test/test_urllibnet.py�setUpzURLTimeoutTest.setUps��� ��!9�:�:�:�:�:�c�.�tjd��dSr
)rrrs r�tearDownzURLTimeoutTest.tearDowns��� ��&�&�&�&�&rc�~�|�tjj��tj�tj��j}tj
|��5tj�tj��}|���ddd��dS#1swxYwYdSr
)
�
addCleanup�urllib�request�
urlcleanup�parse�urlparser�
TEST_HTTP_URL�netlocr�transient_internet�urlopen�read)r�domain�fs   r�testURLreadzURLTimeoutTest.testURLreads��������1�2�2�2���&�&�w�'<�=�=�D��
�
-�f�
5�
5�	�	���&�&�w�'<�=�=�A�
�F�F�H�H�H�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�'>B2�2B6�9B6N)�__name__�
__module__�__qualname__rrr#�rrrrsA������;�;�;�'�'�'�����rrc�^�eZdZ	dZd�Zejd���Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
S)�urlopenNetworkTests�http://www.pythontest.net/c�N�|�tjj��dSr
�rrrrrs rrzurlopenNetworkTests.setUp6��������1�2�2�2�2�2rc/�K�|d}tj|��5tjj|i|��}	|V�|���n#|���wxYw	ddd��dS#1swxYwYdS�Nr)rrrrr�close)r�args�kwargs�resource�rs     rrzurlopenNetworkTests.urlopen:s�������7��
�
-�h�
7�
7�	�	���&��7��7�7�A�
��������	�	�	�	�����	�	�	�	����	�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s'�A7�A�A7�A&�&A7�7A;�>A;c��|�|j��5}dD])}|�t||��d|z���*|�|���d��ddd��dS#1swxYwYdS)N)r �readline�	readlines�filenor0�info�geturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)r�url�
assertTrue�hasattrr )r�open_url�attrs   r�
test_basiczurlopenNetworkTests.test_basicDs���
�\�\�$�(�
#�
#�	F�x�+�
I�
I�������$� 7� 7�:A�CG�:H�I�I�I�I��O�O�H�M�M�O�O�-D�E�E�E�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F����	F�	F�	F�	F�	F�	Fs�AA=�=B�Bc�$�|�|j��5}|�|���td��|�|���td��ddd��dS#1swxYwYdS)Nz readline did not return a stringzreadlines did not return a list)rr;�assertIsInstancer6�bytesr7�list)rr>s  r�test_readlinesz"urlopenNetworkTests.test_readlinesMs���
�\�\�$�(�
#�
#�	E�x��!�!�(�"3�"3�"5�"5�u�"D�
F�
F�
F��!�!�(�"4�"4�"6�"6��"C�
E�
E�
E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E����	E�	E�	E�	E�	E�	Es�AB�B	�B	c�0�|�|j��5}|���}|�|tjjd��|�|���d��ddd��dS#1swxYwYdS)NzEobject returned by 'info' is not an instance of email.message.Message�html)	rr;r9rB�email�message�Message�assertEqual�get_content_subtype)rr>�info_objs   r�	test_infozurlopenNetworkTests.test_infoUs���
�\�\�$�(�
#�
#�	E�x��}�}���H��!�!�(�E�M�,A�#F�
G�
G�
G�
���X�9�9�;�;�V�D�D�D�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E����	E�	E�	E�	E�	E�	Es�A#B�B�Bc���|�|j��5}|���}|�||j��ddd��dS#1swxYwYdSr
)rr;r:rK)rr>�
gotten_urls   r�test_geturlzurlopenNetworkTests.test_geturl^s���
�\�\�$�(�
#�
#�	3�x�!���*�*�J����Z���2�2�2�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3�	3�	3s�0A�A�Ac���|jdz}tj|��5|�t��5t
j����|��}ddd��n#1swxYwY	|�	��}|�
��n#|�
��wxYw|�|d��ddd��dS#1swxYwYdS)N�
XXXinvalidXXXi�)r;rr�assertWarns�DeprecationWarningrr�FancyURLopener�open�getcoder0rK)r�URLr>�codes    r�test_getcodez urlopenNetworkTests.test_getcodedst���h��(��
�
-�c�
2�
2�	(�	(��!�!�"4�5�5�
E�
E�!�>�8�8�:�:�?�?��D�D��
E�
E�
E�
E�
E�
E�
E�
E�
E�
E�
E����
E�
E�
E�
E�
!��'�'�)�)����� � � � ����� � � � �������T�3�'�'�'�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(����	(�	(�	(�	(�	(�	(sL�C)�2A8�,C)�8A<	�<C)�?A<	�C)�B-�C)�-C�C)�)C-�0C-c�X�d}	tj|��|�d|z��n#t$rYnwxYwd}|�t|���5t
j�d�|����ddd��dS#1swxYwYdS)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�skipTest�OSError�assertRaisesrrr�format)r�bogus_domain�failure_explanations   r�test_bad_addressz$urlopenNetworkTests.test_bad_addressps"��*0��		S�� ��.�.�.�
�M�M�B�\�Q�R�R�R�R���	�	�	�
�D�		���� D���
�
�w�,?�
�
@�
@�	F�	F��N�"�"�<�#6�#6�|�#D�#D�E�E�E�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F����	F�	F�	F�	F�	F�	Fs�1�
>�>�3B�B#�&B#N)r$r%r&r;r�
contextlib�contextmanagerrr@rErNrQr[rfr'rrr)r)%s��������'�C�3�3�3��������F�F�F�E�E�E�E�E�E�3�3�3�
(�
(�
(�$F�$F�$F�$F�$Frr)c�X�eZdZ	d�Zejd���Zd�Zd�Zd�Z	dZ
d�Zd�Zd	S)
�urlretrieveNetworkTestsc�N�|�tjj��dSr
r,rs rrzurlretrieveNetworkTests.setUp�r-rc/�K�|d}tj|��5tjj|i|��\}}	||fV�tj|��n#tj|��wxYw	ddd��dS#1swxYwYdSr/)rrrr�urlretriever�unlink)rr1r2r3�
file_locationr9s      rrmz#urlretrieveNetworkTests.urlretrieve�s�������7��
�
-�h�
7�
7�	0�	0�"(�.�"<�d�"M�f�"M�"M��M�4�
0�#�T�)�)�)�)�� ��/�/�/�/��	� ��/�/�/�/����/�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�	0�	0s(�A<�A�A<�A+�+A<�<B�Bc�x�|�|j��5\}}|�tj�|��d��t
|d��5}|�|���d��ddd��n#1swxYwYddd��dS#1swxYwYdS)Nz9file location returned by urlretrieve is not a valid path�rbz=reading from the file location returned by urlretrieve failed)rm�logor<�os�path�existsrWr �rror9r"s    rr@z"urlretrieveNetworkTests.test_basic�s3��
�
�
�d�i�
(�
(�	:�,A�]�D��O�O�B�G�N�N�=�9�9�<?�
@�
@�
@��m�T�*�*�
:�a���������+9�:�:�:�
:�
:�
:�
:�
:�
:�
:�
:�
:�
:�
:����
:�
:�
:�
:�	:�	:�	:�	:�	:�	:�	:�	:�	:�	:�	:�	:����	:�	:�	:�	:�	:�	:s6�AB/�")B�B/�B	�B/�B	�B/�/B3�6B3c���|�|jtj��5\}}|�|tj��|�tj�|����t|d��5}|�|�
��d��ddd��n#1swxYwYddd��dS#1swxYwYdS)Nrqz"reading from temporary file failed)rmrrr�TESTFNrKr<rsrtrurWr rvs    r�test_specified_pathz+urlretrieveNetworkTests.test_specified_path�sc��
�
�
�d�i�'�.�0�0�	P�3H�M�4����]�I�,<�=�=�=��O�O�B�G�N�N�=�9�9�:�:�:��m�T�*�*�
P�a���������*N�O�O�O�
P�
P�
P�
P�
P�
P�
P�
P�
P�
P�
P����
P�
P�
P�
P�		P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P����	P�	P�	P�	P�	P�	Ps6�A&C�)C�5C�C	�C�C	�	C�C� Cc��|�|j��5\}}|�|tjjd��ddd��dS#1swxYwYdS)Nz0info is not an instance of email.message.Message)rmrrrBrHrIrJ)rror9s   r�test_headerz#urlretrieveNetworkTests.test_header�s���
�
�
�d�i�
(�
(�	V�,A�]�D��!�!�$��
�(=�"T�
V�
V�
V�	V�	V�	V�	V�	V�	V�	V�	V�	V�	V�	V�	V����	V�	V�	V�	V�	V�	Vs�*A�A�Ar*c��|�|j��5\}}|�d��}d}	tj||��n(#t
$r|�d|z��YnwxYwddd��dS#1swxYwYdS)N�Datez%a, %d %b %Y %H:%M:%S GMTzDate value not in %r format)rmrr�get�time�strptime�
ValueError�fail)rro�fileheaders�	datevalue�
dateformats     r�test_data_headerz(urlretrieveNetworkTests.test_data_header�s���
�
�
�d�i�
(�
(�	F�,H�]�K�#����/�/�I�4�J�
F��
�i��4�4�4�4���
F�
F�
F��	�	�7�*�D�E�E�E�E�E�
F����	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F����	F�	F�	F�	F�	F�	Fs4�B�A
�B�
"A2�/B�1A2�2B�B�	Bc���g��fd�}|�|j|���5\}}t|d��}ddd��n#1swxYwYt���}|�t���dd���|��ddd��|��dddd|z���|��dd	|��|��d
d	|��d��D��}|��ddh|d|z���|��d
d�ddz|d
|z���dS)Nc�8����|||f��dSr
)�append)�blocks�
block_size�
total_size�recordss   �r�recording_reporthookzEurlretrieveNetworkTests.test_reporthook.<locals>.recording_reporthook�s"����N�N�F�J�
�;�<�<�<�<�<r)�
reporthookzContent-Length�zKThere should always be two calls; the first one before the transfer starts.r]rzblock size can't be 0 in %s����c��h|]\}}}|��	Sr'r')�.0�_r�s   r�	<setcomp>z:urlretrieveNetworkTests.test_reporthook.<locals>.<setcomp>�s��B�B�B�&6�a��Q�z�B�B�Brzblock sizes in %s must be equalz9number of blocks * block size must be >= total size in %s)rmrr�int�repr�
assertGreater�lenrK�assertGreaterEqual)rr�ror��
expected_size�records_repr�block_sizesr�s       @r�test_reporthookz'urlretrieveNetworkTests.test_reporthook�s�����	=�	=�	=�	=�	=��
�
�d�i�4H�
�
I�
I�	?�N,��{���,<� =�>�>�M�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?����	?�	?�	?�	?��G�}�}�����3�w�<�<��1N��	O�	O�	O�������A���*�*�*����7�1�:�a�=�!�<�|�K�	�	M�	M�	M�������A��
�6�6�6�������Q���7�7�7�B�B�'�B�B�B�����'�!�*�Q�-��+�>��M�	�	O�	O�	O�������A��w�q�z�!�}� <�m�%7�9E�%F�	 �	G�	G�	G�	G�	Gs�A
�
A�AN)
r$r%r&rrgrhrmr@ryr{rrr�r�r'rrrjrj�s�������=�3�3�3���0�0���0�:�:�:�P�P�P�V�V�V�(�D�F�F�F�G�G�G�G�Grrj�__main__)�unittest�testr�test.supportrrrgr�urllib.parser�urllib.requestrs�
email.messagerHr�requires�TestCaserr)rjr$�mainr'rr�<module>r�ss������������"�"�"�"�"�"�&�&�&�&�&�&�����
�
�
�
���������	�	�	�	���������������������X�&����&oF�oF�oF�oF�oF�(�+�oF�oF�oF�dLG�LG�LG�LG�LG�h�/�LG�LG�LG�^�z����H�M�O�O�O�O�O��r