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

�Kev���dZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZddlmZddlmZddlZ	ddlZn
#e$rdZYnwxYwddlZddlZddlmZmZdd	lmZddlZejse
jd
���d�Z da!d5d�Z"d
�Z#d6d�Z$Gd�de%��Z&Gd�de%��Z'Gd�de
j(��Z)Gd�de
j(��Z*Gd�de
j(��Z+Gd�de
j(e&e'��Z,Gd�de
j(��Z-Gd�de
j(��Z.Gd �d!e
j(e&��Z/Gd"�d#e
j(��Z0Gd$�d%e
j(��Z1Gd&�d'e
j(��Z2Gd(�d)e
j(��Z3Gd*�d+e
j(��Z4Gd,�d-e&e
j(��Z5Gd.�d/e
j(��Z6Gd0�d1e
j(��Z7Gd2�d3e
j(��Z8e9d4kre
j:��dSdS)7z;Regression tests for what was in Python 2's "urllib" module�N)�patch)�support)�	os_helper)�
socket_helper)�warnings_helper)�url2pathname�pathname2url)�	b64encodeztest requires gethostname()c��tt|����dd����}t|��dkrd|z}d|zS)z!Escape char as RFC 2396 specifies�N�z0%s�%)�hex�ord�upper�len)�char�hex_reprs  �:/usr/local/apps/python3/lib/python3.11/test/test_urllib.py�	hexescaper sM���3�t�9�9�~�~�a�b�b�!�'�'�)�)�H�
�8�}�}�����8�#����>��c���|�!tj�|���}ntst��}|ant}|�|�|��S|�||��S)z.urlopen(url [, data]) -> open file-like objectN)�proxies)�urllib�request�FancyURLopener�
_urlopener�open)�url�datar�openers    r�urlopenr"+sn������.�.�w�.�?�?���
���!�!���
�
����|��{�{�3�����{�{�3��%�%�%rc��tjdtf��5tj���cddd��S#1swxYwYdS)Nz8FancyURLopener style of invoking requests is deprecated.)r�check_warnings�DeprecationWarningrrr�rrrr;s���	�	'�
G��
 �
!�
!�/�/��~�,�,�.�.�/�/�/�/�/�/�/�/�/�/�/�/����/�/�/�/�/�/s�A�A�AFc�����G�fd�dtj���G��fd�dtjj���|�_�S)Nc�:��eZdZdZ�fd�Zd�Zdd�Zdd�Zd�ZdS)	�fakehttp.<locals>.FakeSocketr
c���|�_dS�N)�buf)�selfr �FakeHTTPConnections  �r�sendallz$fakehttp.<locals>.FakeSocket.sendallFs���%)��"�"�"rc�&�|xjdz
c_|S)Nr
)�io_refs)r-�args�kwdss   r�makefilez%fakehttp.<locals>.FakeSocket.makefileIs���L�L�A��L�L��KrNc�T�|jrdStj�||��S�Nr)�closed�io�BytesIO�read)r-�amts  rr:z!fakehttp.<locals>.FakeSocket.readMs'���{�
��s��:�?�?�4��-�-�-rc�T�|jrdStj�||��Sr6)r7r8r9�readline)r-�lengths  rr=z%fakehttp.<locals>.FakeSocket.readlineRs)���{�
��s��:�&�&�t�V�4�4�4rc�~�|xjdzc_|jdkr!tj�|��dSdS)Nr
r)r1r8r9�close�r-s rr@z"fakehttp.<locals>.FakeSocket.closeWsC���L�L�A��L�L��|�q� � ��
� � ��&�&�&�&�&�!� rr+)	�__name__�
__module__�__qualname__r1r/r4r:r=r@)r.s�r�
FakeSocketr)Csy���������	*�	*�	*�	*�	*�	�	�	�	.�	.�	.�	.�
	5�	5�	5�	5�
	'�	'�	'�	'�	'rrEc�,��eZdZdZ�fd�Z�rd�ZdSdS)�$fakehttp.<locals>.FakeHTTPConnectionNc�d���|j��|_|jt|��_dSr+)�fakedata�sock�type�fakesock)r-rEs �r�connectz,fakehttp.<locals>.FakeHTTPConnection.connectas,���"�
�4�=�1�1�D�I�"&�)�D��J�J���rc��dSr+r&rAs rr@z*fakehttp.<locals>.FakeHTTPConnection.closej����r)rBrCrDr,rMr@)rE�
mock_closes��rr.rG\sX���������	,�	,�	,�	,�	,��	�

�
�
�
�
�	�	rr.)r8r9�http�client�HTTPConnectionrI)rIrPr.rEs `@@r�fakehttprTBs������'�'�'�'�'�'�'�R�Z�'�'�'�2��������T�[�7���� #+����rc��eZdZdd�Zd�ZdS)�
FakeHTTPMixinFc�v�t||���}tjj|_|tj_dS)N�rP)rTrQrRrS�_connection_class)r-rIrP�fake_http_classs    rrTzFakeHTTPMixin.fakehttprs1��"�8�
�C�C�C��!%��!;���%4���"�"�"rc�2�|jtj_dSr+)rYrQrRrSrAs r�
unfakehttpzFakeHTTPMixin.unfakehttpws��%)�%;���"�"�"rN�F)rBrCrDrTr\r&rrrVrVqs7������5�5�5�5�
<�<�<�<�<rrVc��eZdZd�Zd�ZdS)�FakeFTPMixinc�z�Gd�dt��}tjj|_|tj_dS)Nc�&�eZdZ		dd�Zd�Zd�ZdS)�,FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapperNTc��dSr+r&)r-�user�passwd�host�port�dirs�timeout�
persistents        r�__init__z5FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapper.__init__~s���rc�,�tj��dfS)Nr)r8r9)r-�filerKs   r�retrfilez5FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapper.retrfile�s���z�|�|�Q��&rc��dSr+r&rAs rr@z2FakeFTPMixin.fakeftp.<locals>.FakeFtpWrapper.close�rOr)NT)rBrCrDrkrnr@r&rr�FakeFtpWrapperrb}sL������HL� $�
�
�
�
�
'�
'�
'�
�
�
�
�
rrp)�objectrr�
ftpwrapper�_ftpwrapper_class)r-rps  r�fakeftpzFakeFTPMixin.fakeftp|sK��		�		�		�		�		�V�		�		�		�"(��!:���$2���!�!�!rc�2�|jtj_dSr+)rsrrrrrAs r�	unfakeftpzFakeFTPMixin.unfakeftp�s��$(�$:���!�!�!rN)rBrCrDrtrvr&rrr_r_{s2������
3�
3�
3�;�;�;�;�;rr_c�r�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�ZdS)�urlopen_FileTestsz�Test urlopen() opening a temporary file.

    Try to test as much functionality as possible so as to cut down on reliance
    on connecting to the Net for testing.

    c��td|jjzd��|_t	t
jd��}	|�|j��|���n#|���wxYwt
j|_	tj�|j	��|_
td|j
z��|_dS)Nztest_urllib: %s
�ascii�wb�file:%s)�bytes�	__class__rB�textrr�TESTFN�writer@�pathnamer�parse�quote�quoted_pathnamer"�returned_obj)r-�fs  r�setUpzurlopen_FileTests.setUp�s����-���0G�G�!�#�#��	���!�4�(�(��	�
�G�G�D�I����
�G�G�I�I�I�I��A�G�G�I�I�I�I����!�(��
�%�|�1�1�$�-�@�@���#�I��0D�$D�E�E����s�A-�-Bc�t�|j���tjtj��dS)zShut down the open objectN)r�r@�os�removerr�rAs r�tearDownzurlopen_FileTests.tearDown�s0������!�!�!�
�	�)�"�#�#�#�#�#rc�h�dD].}|�t|j|��d|z���/dS)N)	r:r=�	readlines�filenor@�info�geturl�getcode�__iter__�/object returned by urlopen() lacks %s attribute)�
assertTrue�hasattrr��r-�attrs  r�test_interfacez urlopen_FileTests.test_interface�sS��G�	�	�D��O�O�G�D�$5�t�<�<�J���
�
�
�
�	�	rc�j�|�|j|j�����dSr+)�assertEqualrr�r:rAs r�	test_readzurlopen_FileTests.test_read�s/�������D�$5�$:�$:�$<�$<�=�=�=�=�=rc���|�|j|j�����|�d|j���d��dS)NrzKcalling readline() after exhausting the file did not return an empty string)r�rr�r=rAs r�
test_readlinezurlopen_FileTests.test_readline�sc�������D�$5�$>�$>�$@�$@�A�A�A�����d�/�8�8�:�:�3�	4�	4�	4�	4�	4rc���|j���}|�t|��dd��|�|d|jd��dS)Nr
z.readlines() returned the wrong number of linesrz"readlines() returned improper text)r�r�r�rr)r-�
lines_lists  r�test_readlinesz urlopen_FileTests.test_readlines�sm���&�0�0�2�2�
�����Z���!�I�	K�	K�	K�����A���	�=�	?�	?�	?�	?�	?rc���|j���}|�|td��|�tj|t|j����|jd��dS)Nzfileno() did not return an intzTReading on the file descriptor returned by fileno() did not return the expected text)	r�r��assertIsInstance�intr�r�r:rr)r-�file_nums  r�test_filenozurlopen_FileTests.test_fileno�sp���$�+�+�-�-�����h��-M�N�N�N�������3�t�y�>�>�:�:�D�I�<�	=�	=�	=�	=�	=rc�8�|j���dSr+)r�r@rAs r�
test_closezurlopen_FileTests.test_close�s��	
����!�!�!�!�!rc�d�|�|jjtjj��dSr+)r�r��headers�email�message�MessagerAs r�test_headerszurlopen_FileTests.test_headers�s)�����d�/�7���9N�O�O�O�O�Orc�P�|�|jj|j��dSr+)r�r�rr�rAs r�test_urlzurlopen_FileTests.test_url�s'������*�.��0D�E�E�E�E�Erc�D�|�|jj��dSr+)�assertIsNoner��statusrAs r�test_statuszurlopen_FileTests.test_status�s"�����$�+�2�3�3�3�3�3rc�~�|�|j���tjj��dSr+)r�r�r�r�r�r�rAs r�	test_infozurlopen_FileTests.test_info�s2�����d�/�4�4�6�6��
�8M�N�N�N�N�Nrc�j�|�|j���|j��dSr+)r�r�r�r�rAs r�test_geturlzurlopen_FileTests.test_geturl�s0������*�1�1�3�3�T�5I�J�J�J�J�Jrc�^�|�|j�����dSr+)r�r�r�rAs r�test_getcodezurlopen_FileTests.test_getcode�s+�����$�+�3�3�5�5�6�6�6�6�6rc�P�|jD]}|�||j���dSr+)r�r�r)r-�lines  r�	test_iterzurlopen_FileTests.test_iter�s;���%�	.�	.�D����T�4�9�-�-�-�-�	.�	.rc�l�|�ttjjd|jz��dS)Nz./)�assertRaises�
ValueErrorrrr"r�rAs r�test_relativelocalfilez(urlopen_FileTests.test_relativelocalfile�s,�����*�V�^�%;�D�4�=�<P�Q�Q�Q�Q�QrN)rBrCrD�__doc__r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r&rrrxrx�s"��������F�F�F�$�$�$�
���>�>�>�4�4�4�?�?�?�=�=�=�"�"�"�
P�P�P�F�F�F�4�4�4�O�O�O�K�K�K�7�7�7�.�.�.�R�R�R�R�Rrrxc�2�eZdZd�Zd�Zd�Zd�Zd�Zd�ZdS)�
ProxyTestsc���|�tj����|_t	t
j��D]2}d|���vr|j�|���3dS)N�proxy)	�enterContextr�EnvironmentVarGuard�env�listr��environ�lower�unset)r-�ks  rr�zProxyTests.setUp�sk���$�$�Y�%B�%D�%D�E�E����b�j�!�!�	"�	"�A��!�'�'�)�)�#�#�����q�!�!�!��	"�	"rc��|j�dd��tj���}|�d|d��|j�dd��|�tj�d����|�tj�d����|�tj�d����dS)N�NO_PROXY�	localhost�no�0localhost, anotherdomain.com, newdomain.com:1234�anotherdomain.com�anotherdomain.com:8888�newdomain.com:1234)r��setrr�getproxies_environmentr�r��proxy_bypass_environment�r-rs  r�+test_getproxies_environment_keep_no_proxiesz6ProxyTests.test_getproxies_environment_keep_no_proxies�s�������Z��-�-�-��.�7�7�9�9������g�d�m�4�4�4�����Z�!S�T�T�T������?�?�@S�T�T�U�U�U������?�?�@X�Y�Y�Z�Z�Z������?�?�@T�U�U�V�V�V�V�Vrc�*�	|j�dd��tj���}|�d|d��|j�dd��tj���}|�d|��|j�d��|j�d��dS#|j�d��|j�d��wxYw)N�
HTTP_PROXY�http://somewhere:3128rQ�REQUEST_METHOD�GET)r�r�rrr�r��assertNotInr�r�s  r�test_proxy_cgi_ignorez ProxyTests.test_proxy_cgi_ignores���		)��H�L�L��'>�?�?�?��n�;�;�=�=�G����4�g�f�o�F�F�F��H�L�L�)�5�1�1�1��n�;�;�=�=�G����V�W�-�-�-��H�N�N�+�,�,�,��H�N�N�<�(�(�(�(�(��
�H�N�N�+�,�,�,��H�N�N�<�(�(�(�(���s�B$C�6Dc��tjj}|j�dd��|�|d����|�|d����|�|d����|�|d����|�|d����|�|d����|�|d	����|�|d
����|�|d����|�|d����|�|d
����|�|d����|�|d����|�|d����dS)Nr�z8localhost, anotherdomain.com, newdomain.com:1234, .d.o.tr��	LocalHost�	LOCALHOSTz
.localhostr�z.newdomain.com:1234z	foo.d.o.tzd.o.tr�z.anotherdomain.com:8888zwww.newdomain.com:1234�prelocalhost�
newdomain.comznewdomain.com:1235�rrr�r�r�r��assertFalse�r-�bypasss  r�(test_proxy_bypass_environment_host_matchz3ProxyTests.test_proxy_bypass_environment_host_match
s�����8������Z�O�	Q�	Q�	Q������{�+�+�,�,�,������{�+�+�,�,�,������{�+�+�,�,�,������|�,�,�-�-�-������3�4�4�5�5�5������4�5�5�6�6�6������{�+�+�,�,�,������w���(�(�(������7�8�8�9�9�9������8�9�9�:�:�:������7�8�8�9�9�9�������/�/�0�0�0�������0�0�1�1�1������ 4�5�5�6�6�6�6�6rc��tjj}|j�dd��|�|d����|�|d����|j�dd��|�|d����|�|d����|�|d����dS)Nr��*r�r�z*, anotherdomain.comr�r�r�s  r�*test_proxy_bypass_environment_always_matchz5ProxyTests.test_proxy_bypass_environment_always_match s�����8������Z��%�%�%�������/�/�0�0�0������3�4�4�5�5�5�����Z�!7�8�8�8������2�3�3�4�4�4�������0�0�1�1�1������ 4�5�5�6�6�6�6�6rc��tjj}|j�dd��|�|d����|�|d����|�|d����dS)Nr�r�z
localhost
zanotherdomain.com:8888
znewdomain.com:1234
)rrr�r�r�r�r�s  r�%test_proxy_bypass_environment_newlinez0ProxyTests.test_proxy_bypass_environment_newline*s�����8������Z�G�	I�	I�	I������
�.�.�/�/�/������ :�;�;�<�<�<������ 6�7�7�8�8�8�8�8rN)	rBrCrDr�r�r�r�r�r�r&rrr�r��sq������"�"�"�	W�	W�	W�
)�
)�
)�7�7�7�&7�7�7�9�9�9�9�9rr�c� �eZdZd�Zd�Zd�ZdS)�ProxyTests_withOrderedEnvc�b�tj|_tj��t_dSr+)r�r��
_saved_env�collections�OrderedDictrAs rr�zProxyTests_withOrderedEnv.setUp5s���*��� �,�.�.��
�
�
rc�(�|jt_dSr+)r�r�r�rAs rr�z"ProxyTests_withOrderedEnv.tearDown;s���_��
�
�
rc��dtjd<dtjd<|�tj�d����|�tj�d����dtjd<dtjd<tj���}|�i|��d	tjd<d
tjd<|�tj�d����|�tj�d����|�tj�d����|�tj�d
����|�tj�d����dtjd<dtjd<tj���}|�d|d��dS)N��no_proxyr��No_Proxy�	arbitrary�
http_proxyr�r�z%localhost, noproxy.com, my.proxy:1234zxyz.comznoproxy.com:5678z
my.proxy:1234zmy.proxyzhttp://somewhereelse:3128�
Http_ProxyrQ)	r�r�r�rrr�r�r�r�r�s  r�,test_getproxies_environment_prefer_lowercasezFProxyTests_withOrderedEnv.test_getproxies_environment_prefer_lowercase>s���!#��
�:��!,��
�:�������@�@��M�M�N�N�N������@�@��M�M�N�N�N�#%��
�<� �#:��
�<� ��.�7�7�9�9������W�%�%�%�!H��
�:��!*��
�:�������?�?��L�L�M�M�M������?�?�@R�S�S�T�T�T������?�?��P�P�Q�Q�Q������@�@��L�L�M�M�M������@�@��M�M�N�N�N�#:��
�<� �#>��
�<� ��.�7�7�9�9�����0�'�&�/�B�B�B�B�BrN)rBrCrDr�r�rr&rrr�r�3sF������/�/�/�%�%�%�C�C�C�C�Crr�c��eZdZdZd�Zd�Zd�Zeje	d��d���Z
eje	d��d���Zeje	d��d���Zeje	d��d	���Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zejejdd��d���Zd�Zd�Zd�Z eje	d��d���Z!dS)�urlopen_HttpTestsz.Test urlopen() opening a fake http connection.c��|�d|zdz��	td��}|�|���d��|�|���d��|�|���d��|�|���d��|���dS#|���wxYw)NsHTTP/s 200 OK

Hello!�http://python.org/�Hello!r���rTr"r�r=r�r�r\)r-�ver�fps   r�
check_readzurlopen_HttpTests.check_readZs����
�
�h��n�'?�?�@�@�@�	��-�.�.�B����R�[�[�]�]�I�6�6�6����R�[�[�]�]�C�0�0�0����R�Y�Y�[�[�*>�?�?�?����R�Z�Z�\�\�3�/�/�/��O�O�������D�O�O�������s�B/C"�"C8c��d}|�d��	tj�|��}|�|���|��|���dS#|���wxYw)Nz-http://docs.python.org/library/urllib.html#OK�HTTP/1.1 200 OK

Hello!)rTrrr"r�r�r\)r-rr	s   r�test_url_fragmentz#urlopen_HttpTests.test_url_fragmentes~��=���
�
�6�7�7�7�	���'�'��,�,�B����R�Y�Y�[�[�#�.�.�.��O�O�������D�O�O�������s�AA6�6Bc���|�d��	td��}|�|jj��|���dS#|���wxYw)Nr�http://www.python.org)rTr"r�r	�
will_closer\)r-�resps  r�test_willclosez urlopen_HttpTests.test_willcloseosk���
�
�6�7�7�7�	��2�3�3�D��O�O�D�G�.�/�/�/��O�O�������D�O�O�������s�.A�A1zssl module requiredc�*�ttdd����dgzD�]o}t|��}d|�d�}|�d��	t	|���dd��}tjj}|�	|d	|����5tj�d
|����ddd��n#1swxYwY|�	|d	|����5tj�d|����ddd��n#1swxYwYtd
|����}|�
||�����|�����X#|���wxYwdS)Nr�!�z//localhost:7777/test�/�HTTP/1.1 200 OK

Hello.�\�\\�contain control.*�http:�https:)r��range�chrrT�repr�replacerQrR�
InvalidURL�assertRaisesRegexrrr"r�r�r\)r-�char_nor�schemeless_url�escaped_char_reprr!rs       r�(test_url_path_with_control_char_rejectedz:urlopen_HttpTests.test_url_path_with_control_char_rejectedwsF���E�!�T�N�N�+�+�t�f�4�	"�	"�G��w�<�<�D�<�T�<�<�<�N��M�M�:�;�;�;�
"�%)��J�J�$6�$6�t�U�$C�$C�!�!�[�3�
��+�+�� G�4E� G� G�I�I�E�E��N�*�*�+C�>�+C�+C�D�D�D�E�E�E�E�E�E�E�E�E�E�E����E�E�E�E��+�+�� G�4E� G� G�I�I�F�F��N�*�*�+D�N�+D�+D�E�E�E�F�F�F�F�F�F�F�F�F�F�F����F�F�F�F��7�~�7�7�8�8��� � ��t�{�{�}�}�5�5�5����!�!�!�!�����!�!�!�!����/	"�	"sU�A
E:�#C�E:�C	�E:�C	�E:�0#D�E:�D#	�#E:�&D#	�'=E:�:Fc��|�d��d}d|zdz}	tjj}|�|d��5t
j�d|����ddd��n#1swxYwY|�|d��5t
j�d|����ddd��n#1swxYwYtd|����}|�d	|�	����|�d
|�	����|�d|�	����|�
��dS#|�
��wxYw)Nrz:localhost:7777?a=1 HTTP/1.1
X-injected: header
TEST: 123�//�:8080/test/?test=az*contain control.*\\r.*(found at least . .)r�contain control.*\\nr� �
�
)rTrQrRr!r"rrr"r�r�r\)r-rfr$r!rs     r�4test_url_path_with_newline_header_injection_rejectedzFurlopen_HttpTests.test_url_path_with_newline_header_injection_rejected�s���
�
�6�7�7�7�O�����';�;��	���/�J��'�'��I�K�K�
A�
A���&�&�'?�~�'?�'?�@�@�@�
A�
A�
A�
A�
A�
A�
A�
A�
A�
A�
A����
A�
A�
A�
A��'�'�
�4K�L�L�
B�
B���&�&�'@��'@�'@�A�A�A�
B�
B�
B�
B�
B�
B�
B�
B�
B�
B�
B����
B�
B�
B�
B��3�>�3�3�4�4�D����S�$�+�+�-�-�0�0�0����T�4�;�;�=�=�1�1�1����T�4�;�;�=�=�1�1�1��O�O�������D�O�O�������sT�'E2�#A7�+E2�7A;�;E2�>A;�?E2�#C�;E2�C�E2�C�B
E2�2Fc�t�ttdd����dgzD�]}t|��}d|�d�}|�d��	t	|���dd��}tjj}|�	|d	|����5td
|����ddd��n#1swxYwY|�	|d	|����5td|����ddd��n#1swxYwY|�����#|���wxYwdS)Nrrrz//localhostz/test/rrrrrr)r�rrrTrr rQrRr!r"r"r\)r-r#rr$r%r!s      r�(test_url_host_with_control_char_rejectedz:urlopen_HttpTests.test_url_host_with_control_char_rejected�s����E�!�T�N�N�+�+�t�f�4�
	"�
	"�G��w�<�<�D�7�4�7�7�7�N��M�M�:�;�;�;�	
"�$(��J�J�$6�$6�t�U�$C�$C�!�!�[�3�
��+�+�� G�4E� G� G�I�I�6�6��4�N�4�4�5�5�5�6�6�6�6�6�6�6�6�6�6�6����6�6�6�6��+�+�J�8_�L]�8_�8_�`�`�7�7��5�^�5�5�6�6�6�7�7�7�7�7�7�7�7�7�7�7����7�7�7�7����!�!�!�!�����!�!�!�!����
	"�
	"sU�A
D�B<�0D�<C	�D�C	�D� C?�3D�?D	�D�D	�D�D5c���|�d��d}d|zdz}	tjj}|�|d��5td|����ddd��n#1swxYwY|�|d��5td|����ddd��n#1swxYwY|���dS#|���wxYw)	Nrzlocalhost
X-injected: header
r(r)zcontain control.*\\rrr*r)rTrQrRr!r"r"r\)r-rfr$r!s    r�4test_url_host_with_newline_header_injection_rejectedzFurlopen_HttpTests.test_url_host_with_newline_header_injection_rejected�ss���
�
�6�7�7�7�4�����';�;��	���/�J��'�'��3�5�5�
2�
2��0��0�0�1�1�1�
2�
2�
2�
2�
2�
2�
2�
2�
2�
2�
2����
2�
2�
2�
2��'�'�
�4K�L�L�
3�
3��1��1�1�2�2�2�
3�
3�
3�
3�
3�
3�
3�
3�
3�
3�
3����
3�
3�
3�
3�
�O�O�������D�O�O�������sS�'C�A'�C�'A+�+C�.A+�/C�B'�C�'B+�+C�.B+�/C�Cc�0�|�d��dS)Ns0.9�r
rAs r�
test_read_0_9zurlopen_HttpTests.test_read_0_9�s��	
��������rc�0�|�d��dS)Ns1.0r4rAs r�
test_read_1_0zurlopen_HttpTests.test_read_1_0������������rc�0�|�d��dS)Ns1.1r4rAs r�
test_read_1_1zurlopen_HttpTests.test_read_1_1�r8rc���|�dd���	|�ttd��|���dS#|���wxYw)Ns�HTTP/1.1 401 Authentication Required
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Connection: close
Content-Type: text/html; charset=iso-8859-1
TrXr�rTr��OSErrorr"r\rAs r�test_read_bogusz!urlopen_HttpTests.test_read_bogus�sq���
�
��
�	�	�	�	�	����g�w�0D�E�E�E��O�O�������D�O�O�������s�!A�A&c�,�|�dd���	d}|�tjj|��5td��ddd��n#1swxYwY|���dS#|���wxYw)Ns�HTTP/1.1 302 Found
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Location: file://guidocomputer.athome.com:/python/license
Connection: close
Content-Type: text/html; charset=iso-8859-1
TrXzRedirection to url 'file:r)rTr"r�error�	HTTPErrorr"r\)r-�msgs  r�test_invalid_redirectz'urlopen_HttpTests.test_invalid_redirect�s����
�
���
	�	�	�	�	�-�C��'�'���(>��D�D�
.�
.��,�-�-�-�
.�
.�
.�
.�
.�
.�
.�
.�
.�
.�
.����
.�
.�
.�
.�
�O�O�������D�O�O�������s/�'A=�A�A=�A � A=�#A �$A=�=Bc�,�tt��j��D]r}|�dd���	|�t
jjtd��|�	���Z#|�	��wxYwdS)Ns_HTTP/1.1 302 Found
Location: file://guidocomputer.athome.com:/python/license
Connection: close
TrX�http://something)
rr�maxtriesrTr�rr@rAr"r\)r-�is  r�test_redirect_limit_independentz1urlopen_HttpTests.test_redirect_limit_independent�s����~�'�'�0�1�1�		"�		"�A��M�M���
�
�
�
�
"��!�!�&�,�"8�'�&�(�(�(����!�!�!�!�����!�!�!�!����		"�		"s�+A;�;Bc���|�d��	|�ttd��|���dS#|���wxYw)NrrEr<rAs r�test_empty_socketz#urlopen_HttpTests.test_empty_sockets`��	
�
�
�c����	����g�w�0B�C�C�C��O�O�������D�O�O�������s�!A�A$c��|�tjj��5}t	d��ddd��n#1swxYwY|�|jj��|�|jj��dS)Nz/file://localhost/a/file/which/doesnot/exists.py)	r�rr@�URLErrorr"r��	exception�filename�reason�r-�es  r�test_missing_localfilez(urlopen_HttpTests.test_missing_localfiles���
�
�
�v�|�4�
5�
5�	G���E�F�F�F�	G�	G�	G�	G�	G�	G�	G�	G�	G�	G�	G����	G�	G�	G�	G������,�-�-�-������*�+�+�+�+�+��A�A�Ac��tj��\}}d|�tjjd��z}	|�tj�|����t|��5}|�|��ddd��n#1swxYwYtj	|��tj
|��n-#tj	|��tj
|��wxYw|�tj�|����|�tjj��5t|��ddd��dS#1swxYwYdS)Nzfile://localhost/r)�tempfile�mkstempr r��path�sepr��existsr"r@�unlinkr�r�rr@rL)r-�fd�tmp_file�tmp_fileurl�fobjs     r�test_file_notexistsz%urlopen_HttpTests.test_file_notexistss����'�)�)���H�)�H�,<�,<�R�W�[�#�,N�,N�N��	 ��O�O�B�G�N�N�8�4�4�5�5�5���%�%�
&������%�%�%�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&����
&�
&�
&�
&�
�H�R�L�L�L��I�h������
�H�R�L�L�L��I�h����������������1�1�2�2�2�
�
�
�v�|�4�
5�
5�	!�	!��K� � � �	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!����	!�	!�	!�	!�	!�	!sC�AC�B#�C�#B'�'C�*B'�+C�*D�E7�7E;�>E;c��d}|�tjj��5}t	|��ddd��n#1swxYwY|�|jj��|�|jj	��dS)Nzftp:///path�
r�rr@rLr"r�rMrNr�rO)r-�test_ftp_urlrQs   r�test_ftp_nohostz!urlopen_HttpTests.test_ftp_nohost s���$��
�
�
�v�|�4�
5�
5�	"���L�!�!�!�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"������-�.�.�.������*�+�+�+�+�+s�A�A�
Ac��|�tjj��5}t	d��ddd��n#1swxYwY|�|jj��|�|jj	��dS)Nz.ftp://localhost/a/file/which/doesnot/exists.pyrarPs  r�test_ftp_nonexistingz&urlopen_HttpTests.test_ftp_nonexisting's���
�
�
�v�|�4�
5�
5�	F���D�E�E�E�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F����	F�	F�	F�	F������-�.�.�.������*�+�+�+�+�+rS�MAXFTPCACHErc��|���	tj�ddddg��tjjd<td��|���dS#|���wxYw)Nrd�passr���testzftp://localhost)rtrrrr�ftpcacher"rvrAs r�test_ftp_cache_pruningz(urlopen_HttpTests.test_ftp_cache_pruning-sz��������	�.4�n�.G�.G��PV�Xc�eg�ik�.l�.l�F�N�#�F�+��%�&�&�&��N�N�������D�N�N�������s�AA0�0Bc���|�d��	td��}|�|���d��|�|���d��|�|���d��|�|���d��|���dS#|���wxYw)N�HTTP/1.0 200 OK

Hello!zhttp://user:pass@python.org/rrrr)r-r	s  r�test_userpass_inurlz%urlopen_HttpTests.test_userpass_inurl6s����
�
�6�7�7�7�	��7�8�8�B����R�[�[�]�]�I�6�6�6����R�[�[�]�]�C�0�0�0����R�Y�Y�[�[�*H�I�I�I����R�Z�Z�\�\�3�/�/�/��O�O�������D�O�O�������s�B/C�C2c��|�d��	d}d�|��}tjj}dt|�d�����d��z}t|��}|�	||j
�d����|�|���d��|�|���d��|�
|���|��|�|���d	��|���dS#|���wxYw)
Nrnza b:c dzhttp://{}@python.org/zAuthorization: Basic %s
�ASCIIzUTF-8rrr)rT�formatrQrRrSr
�encode�decoder"�assertInr,r�r=�assertNotEqualr�r�r\)r-�userpassr�fakehttp_wrapper�
authorizationr	s      r�test_userpass_inurl_w_spacesz.urlopen_HttpTests.test_userpass_inurl_w_spacesAsB���
�
�6�7�7�7�	� �H�)�0�0��:�:�C�#�{�9��:�&�x���w�'?�'?�@�@�G�G��P�P�Q�M�����B��M�M�-�)9�)=�)D�)D�W�)M�)M�N�N�N����R�[�[�]�]�I�6�6�6����R�[�[�]�]�C�0�0�0�����	�	���S�1�1�1����R�Z�Z�\�\�3�/�/�/��O�O�������D�O�O�������s�D=E*�*Fc��tjdtf��5tj���ddd��dS#1swxYwYdS�Nr�)rr$r%rr�	URLopenerrAs r�test_URLopener_deprecationz,urlopen_HttpTests.test_URLopener_deprecationTs���
�
+�R�0B�,C�
D�
D�	'�	'��N�$�$�&�&�&�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'����	'�	'�	'�	'�	'�	's�A�A�Ac�<�tj��}tjdtf��5|�t��5tj�	dd|���ddd��n#1swxYwYddd��dS#1swxYwYdS)Nr�zhttps://localhostz/nonexistent/path)�cafile�context)
�ssl�create_default_contextrr$r%r�r�rrr")r-r�s  r�test_cafile_and_contextz)urlopen_HttpTests.test_cafile_and_contextXs���,�.�.��
�
+�R�1C�,D�
E�
E�	�	��"�"�:�.�.�
�
���&�&�'�0C�W�'����
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s5�B�
#A9�-B�9A=	�=B�A=	�B�B�BN)"rBrCrDr�r
r
r�unittest�
skipUnlessr�r&r.r0r2r5r7r:r>rCrHrJrRr_rcrerrqrrrlrorzr~r�r&rrrrWs#������8�8�	�	�	��������X���3�4�4�"�"�5�4�"�4�X���3�4�4���5�4��2�X���3�4�4�"�"�5�4�"� �X���3�4�4���5�4�� � � �
 � � � � � ������� "�"�"����,�,�,�!�!�!�,�,�,�,�,�,��U�\�&�.�-��3�3���4�3��	�	�	����&'�'�'��X���3�4�4���5�4���rrc�H�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�ZdS)�urlopen_DataTestsz"Test urlopen() opening a data URL.c��|�tjj��d|_d|_d|_d|_d|_tj�	|j��|_
tj�	|j��|_tj�	|j��|_dS)Nutest data URLs :;,%=& ö Ä sU�PNG


IHDR{@��sRGB���IDAT�c```���?�
o/IEND�B`�zZdata:text/plain;charset=UTF-8,test%20data%20URLs%20%3A%3B%2C%25%3D%26%20%C3%B6%20%C3%84%20zPdata:text/plain;charset=ISO-8859-1;base64,dGVzdCBkYXRhIFVSTHMgOjssJT0mIPYgxCA%3Dz�data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAIAAAB7
QOjdAAAAAXNSR0IArs4c6QAAAA9JREFUCNdj%0AYGBg%2BP//PwAGAQL%2BCm8 vHgAAAABJRU5ErkJggg%3D%3D%0A%20)
�
addCleanuprr�
urlcleanupr�image�text_url�text_url_base64�	image_urlr"�
text_url_resp�text_url_base64_resp�image_url_resprAs rr�zurlopen_DataTests.setUpes��������1�2�2�2�;��	�
F�	
�
�
(�	
�
�
�	
��
.�	
��
$�^�3�3�D�M�B�B���$*�N�$:�$:�� �%"�%"��!�$�n�4�4�T�^�D�D����rc�h�dD].}|�t|j|��d|z���/dS)N)r:r=r�r@r�r�r�r�r�)r�r�r�r�s  rr�z urlopen_DataTests.test_interface�sS��G�	�	�D��O�O�G�D�$6��=�=�J���
�
�
�
�	�	rc�V�|�|j���tjj��|�|j������ddg��|�|j	���dtt|j������|�tj�d��������ddg��dS)N)z
text/plainr�)�charsetz
ISO-8859-1zcontent-lengthzdata:,)r�zUS-ASCII)r�r�r�r�r�r�r�r��
get_paramsr��strrr�rrr"rAs rr�zurlopen_DataTests.test_info�s�����d�0�5�5�7�7���9N�O�O�O�����2�7�7�9�9�D�D�F�F�
�!:�;�	=�	=�	=�����,�1�1�3�3�4D�E���D�J��� � �	"�	"�	"������/�/��9�9�>�>�@�@�K�K�M�M�
�!8�9�	;�	;�	;�	;�	;rc�2�|�|j���|j��|�|j���|j��|�|j���|j��dSr+)r�r�r�r�r�r�r�r�rAs rr�zurlopen_DataTests.test_geturl�s�������+�2�2�4�4�d�m�D�D�D�����2�9�9�;�;�� �	"�	"�	"�����,�3�3�5�5�t�~�F�F�F�F�Frc��|�|j����t	|j��������d��|j��dS�Nr�)r�r�r:rt�dictr�r�rrAs r�test_read_textz urlopen_DataTests.test_read_text�s|������+�0�0�2�2�9�9���#�(�(�*�*�5�5�7�7�8�8��C�E�E�FJ�i�	Q�	Q�	Q�	Q�	Qrc��|�|j����t	|j��������d��|j��dSr�)r�r�r:rtr�r�r�rrAs r�test_read_text_base64z'urlopen_DataTests.test_read_text_base64�sw������2�7�7�9�9�@�@���*�/�/�1�1�<�<�>�>�?�?�	�J�L�L��I�	�	�	�	�	rc�j�|�|j���|j��dSr+)r�r�r:r�rAs r�test_read_imagez!urlopen_DataTests.test_read_image�s/������,�1�1�3�3�T�Z�@�@�@�@�@rc�\�|�ttjjd��dS)Nzdata:text/plain�r�r�rrr"rAs r�test_missing_commaz$urlopen_DataTests.test_missing_comma�s&�����*�V�^�%;�<M�N�N�N�N�Nrc�\�|�ttjjd��dS)Nzdata:;base64,Cg=r�rAs r�test_invalid_base64_dataz*urlopen_DataTests.test_invalid_base64_data�s&�����*�V�^�%;�<N�O�O�O�O�OrN)
rBrCrDr�r�r�r�r�r�r�r�r�r�r&rrr�r�bs�������,�,�E�E�E�>���;�;�;�G�G�G�Q�Q�Q����
A�A�A�O�O�O�P�P�P�P�Prr�c�V�eZdZdZd�Zd�Zd�Zdd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�ZdS)�urlretrieve_FileTestsz(Test urllib.urlretrieve() on local filesc��|�tjj��g|_|�tj��d|_	ttjd��}|�
|j��|���|���dS#YdSxYw#|���w#YwxYwxYw)Nstesting urllib.urlretriever{)r�rrr��	tempFiles�registerFileForCleanUprr�rrr�r@)r-�FILEs  rr�zurlretrieve_FileTests.setUp�s��������1�2�2�2����	
�#�#�I�$4�5�5�5�1��	�	��	�(�$�/�/�D��J�J�t�y�!�!�!��J�J�L�L�L�����������D�D�D��������������D�D������s1�AB9�B1�1B6�9C�:C�C�C�Cc�P�|jD]}tj|���#Y�xYwdSr+)r�r�r�)r-�eachs  rr�zurlretrieve_FileTests.tearDown�s7���N�	�	�D���4�������D�D����	�	s��#c��tj�|��}	|�d��n"#t$rtjd���wxYwdtj�	|��zS)Nzutf-8z!filePath is not encodable to utf8z	file://%s)
r�rW�abspathrs�UnicodeEncodeErrorr��SkipTestrrr	)r-�filePaths  r�constructLocalFileUrlz+urlretrieve_FileTests.constructLocalFileUrl�s|���7�?�?�8�,�,��	I��O�O�G�$�$�$�$��!�	I�	I�	I��#�$G�H�H�H�	I�����V�^�8�8��B�B�B�Bs	�7�Arc�R�tj��\}}	|�|��tj|d��}|�|��|���|���n'#Yn#xYw#|���w#YwxYwxYw|S)z�Creates a new temporary file containing the specified data,
        registers the file for deletion during the test fixture tear down, and
        returns the absolute path of the file.r{)rUrVr�r��fdopenr�r@)r-r �newFd�newFilePath�newFiles     r�createNewTempFilez'urlretrieve_FileTests.createNewTempFile�s���
&�-�/�/���{�	��'�'��4�4�4��i��t�,�,�G��M�M�$�����M�M�O�O�O����������D�D��������������D�D��������s0�AB�+B�B�B$�B�B$�B!�B$c�:�|j�|��dSr+)r��append)r-�fileNames  rr�z,urlretrieve_FileTests.registerFileForCleanUp�s������h�'�'�'�'�'rc��tj�dtjz��}|�|dtj��|�|dtjj	d��dS)Nr|rr
zFdid not get an email.message.Message instance as second returned value)
rr�urlretrieverr�r�r�r�r�r�)r-�results  r�
test_basicz urlretrieve_FileTests.test_basic�sr����+�+�I�	�8H�,H�I�I��������I�$4�5�5�5����f�Q�i���)>�9�	:�	:�	:�	:�	:rc��dtjz}|�|��tj�|�tj��|��}|�||d��|�tj
�|��d��t|d��}	|�
��}|���|���n'#Yn#xYw#|���w#YwxYwxYw|�|j|��dS)N�%s.2rzcopy of the file was not made�rb)rr�r�rrr�r�r�r�r�rWrYrr:r@r)r-�second_tempr�r�rs     r�	test_copyzurlretrieve_FileTests.test_copy�s ���y�/�/���#�#�K�0�0�0���+�+�D�,F�,F���-�-�*�,�,������f�Q�i�0�0�0��������{�3�3�69�	:�	:�	:��K��&�&��	��9�9�;�;�D��J�J�L�L�L����������D�D��������������D�D������������D�)�)�)�)�)s0�(D�*C?�?D�D#�D�D#�D �D#c����dgf�fd�	}dtjz}��|��tj���tj��||��dS)Nrc�����|t����|t����|t����||d��|ddz|d<dS)Nrr
)r�r�r�)�block_count�block_read_size�	file_size�count_holderr-s    �r�
hooktesterz9urlretrieve_FileTests.test_reporthook.<locals>.hooktestersu����!�!�+�s�3�3�3��!�!�/�3�7�7�7��!�!�)�S�1�1�1����[�,�q�/�:�:�:�*�1�o��1�L��O�O�Orr�)rr�r�rrr�r�)r-r�r�s`  r�test_reporthookz%urlretrieve_FileTests.test_reporthooks����NO�S�	2�	2�	2�	2�	2�	2��y�/�/���#�#�K�0�0�0���"�"��&�&�y�'7�8�8���	%�	%�	%�	%�	%rc�B�g}|fd�}|���}tj�|�|��t
j|��|�t|��d��|�|ddd��dS)Nc�6�|�|||f��dSr+�r��r�r�r��_reports    rr�zAurlretrieve_FileTests.test_reporthook_0_bytes.<locals>.hooktester�!���N�N�K��)�D�E�E�E�E�Err
rr�	r�rrr�r�rr�r�r�r-�reportr��srcFileNames    r�test_reporthook_0_bytesz-urlretrieve_FileTests.test_reporthook_0_bytess�����HN�	F�	F�	F�	F��,�,�.�.����"�"�4�#=�#=�k�#J�#J���j�	*�	*�	*�����V���a�(�(�(�������1��q�)�)�)�)�)rc��g}|fd�}|�d��}tj�|�|��t
j|��|�t|��d��|�|ddd��|�|ddd��dS)Nc�6�|�|||f��dSr+r�r�s    rr�zAurlretrieve_FileTests.test_reporthook_5_bytes.<locals>.hooktester$r�rsxxxxxrr�r
r�r�s    r�test_reporthook_5_bytesz-urlretrieve_FileTests.test_reporthook_5_bytess�����HN�	F�	F�	F�	F��,�,�X�6�6����"�"�4�#=�#=�k�#J�#J���j�	*�	*�	*�����V���a�(�(�(�������1��q�)�)�)�������1��q�)�)�)�)�)rc��g}|fd�}|�ddz��}tj�|�|��t
j|��|�t|��d��|�|ddd��|�|ddd��|�|ddd��|�|ddd��dS)	Nc�6�|�|||f��dSr+r�r�s    rr�zDurlretrieve_FileTests.test_reporthook_8193_bytes.<locals>.hooktester2r�r�xi �rrr
i r�r�s    r�test_reporthook_8193_bytesz0urlretrieve_FileTests.test_reporthook_8193_bytes-s����HN�	F�	F�	F�	F��,�,�T�D�[�9�9����"�"�4�#=�#=�k�#J�#J���j�	*�	*�	*�����V���a�(�(�(�������1��t�,�,�,�������1��t�,�,�,�������1��t�,�,�,�������1��t�,�,�,�,�,rN)r)rBrCrDr�r�r�r�r�r�r�r�r�r�r�r�r&rrr�r��s�������2�2����0���C�C�C����� (�(�(�:�:�:�*�*�*�$%�%�%�	*�	*�	*�*�*�*�-�-�-�-�-rr�c��eZdZdZd�Zd�ZdS)�urlretrieve_HttpTestsz5Test urllib.urlretrieve() using fake http connectionsc��|�tjj��|�d��d�}|�tjj��5	tj�tj
|���|���n#|���wxYw	ddd��dS#1swxYwYdS)N��HTTP/1.1 200 OK
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Connection: close
Content-Length: 100
Content-Type: text/html; charset=iso-8859-1

FF
c��dSr+r&)�par1�par2�par3s   r�_reporthookzYurlretrieve_HttpTests.test_short_content_raises_ContentTooShortError.<locals>._reporthookNs���Dr)�
reporthook�r�rrr�rTr�r@�ContentTooShortErrorr�r�
TEST_HTTP_URLr\)r-r�s  r�.test_short_content_raises_ContentTooShortErrorzDurlretrieve_HttpTests.test_short_content_raises_ContentTooShortErrorAs�������1�2�2�2��
�
��	�	�	�	�	�	��
�
�v�|�@�
A�
A�	"�	"�
"���*�*�7�+@�6A�+�C�C�C����!�!�!�!�����!�!�!�!����!�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"s*�!C
�#+B#�C
�#B9�9C
�
C�Cc��|�tjj��|�d��|�tjj��5	tj�tj
��|���n#|���wxYw	ddd��dS#1swxYwYdS)Nr�r�rAs r�Atest_short_content_raises_ContentTooShortError_without_reporthookzWurlretrieve_HttpTests.test_short_content_raises_ContentTooShortError_without_reporthookXs��������1�2�2�2��
�
��	�	�	��
�
�v�|�@�
A�
A�	"�	"�
"���*�*�7�+@�A�A�A����!�!�!�!�����!�!�!�!����!�		"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"s*�C� )B�	C�B4�4C�C	�C	N)rBrCrDr�r�r�r&rrr�r�>s8������?�?�"�"�"�."�"�"�"�"rr�c�H�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�ZdS)�QuotingTestsauTests for urllib.quote() and urllib.quote_plus()

    According to RFC 3986 (Uniform Resource Identifiers), to escape a
    character you write it as '%' + <2 character US-ASCII hex value>.
    The Python code of ``'%' + hex(ord(<character>))[2:]`` escapes a
    character properly. Case does not matter on the hex letters.

    The various character sets specified are:

    Reserved characters : ";/?:@&=+$,"
        Have special meaning in URIs and must be escaped if not being used for
        their special meaning
    Data characters : letters, digits, and "-_.!~*'()"
        Unreserved and do not need to be escaped; can be, though, if desired
    Control characters : 0x00 - 0x1F, 0x7F
        Have no use in URIs so must be escaped
    space : 0x20
        Must be escaped
    Delimiters : '<>#%"'
        Must be escaped
    Unwise : "{}|\^[]`"
        Must be escaped

    c�$�d�gd���}tj�|��}|�||d|�d|����tj�|��}|�||d|�d|����dS)Nr�)�ABCDEFGHIJKLMNOPQRSTUVWXYZ�abcdefghijklmnopqrstuvwxyz�
0123456789z_.-~�using quote(): � != �using quote_plus(): )�joinrr�r�r��
quote_plus)r-�do_not_quoter�s   r�test_never_quotezQuotingTests.test_never_quote�s����x�x�!)�!)�!)�*�*����#�#�L�1�1������v�v�6B�l�l�F�F�K�	M�	M�	M���(�(��6�6������v�v�:F�,�,���O�	Q�	Q�	Q�	Q�	Qrc�f�|�tjjjdd��dS)Nrr)r�rr�r��__defaults__rAs r�test_default_safezQuotingTests.test_default_safe�s+�������+�8��;�S�A�A�A�A�Arc��d}tj�||���}|�||d|�d|����tj�||���}|�||d|�d|����tj�|d���}|�||d|�d|����tj�ddd	�
��}tj�ddd�
��}|�||d|�d|����tj�ddd�
��}tj�ddd�
��}|�||d|�d|����dS)
Nz<>��safer�r�r�s<>uaüb�latin-1�ü)�encodingrr���)rr�r�r�r�)r-�quote_by_defaultr��expects    r�	test_safezQuotingTests.test_safe�s�������#�#�$4�;K�#�L�L�����)�6�6�6F�6F�6F���O�	Q�	Q�	Q���(�(�)9�.>�)�@�@�����)�6�6�*�*�*�F�F�4�	5�	5�	5���#�#�$4�5�#�A�A�����)�6�6�6F�6F�6F���O�	Q�	Q�	Q���#�#�H�y�v�#�N�N����#�#�H�y�r�#�J�J�������� �&�&�&�&�*�	+�	+�	+���#�#�H�y�w�#�O�O����#�#�H�y�r�#�J�J�������� �&�&�&�&�*�	+�	+�	+�	+�	+rc�8�d�td��D��}|�d��|�td����d�|��}|D]�}tj�|��}|�t|��|d|�dt|���d|����tj�	|��}|�t|��|d	|�d
t|���d|������~d}d}tj�|��}|�||d|�d
|����tj�	|��}|�||d	|�d
|����dS)Nc�,�g|]}t|����Sr&)r)�.0�nums  r�
<listcomp>z5QuotingTests.test_default_quoting.<locals>.<listcomp>�s��6�6�6�S��C���6�6�6r� z
<>#%"{}|\^[]`rr�r�z should be escaped to z, not r�z should be escapes to zab[]cdz
ab%5B%5Dcdr�)
rr�rr�rr�r�r�rr�)r-�should_quoterr��
partial_quote�expecteds      r�test_default_quotingz!QuotingTests.test_default_quoting�s���7�6�E�"�I�I�6�6�6�����,�-�-�-����C��H�H�%�%�%��w�w�|�,�,�� �
	>�
	>�D��\�'�'��-�-�F����Y�t�_�_�f�f�#�d�d�I�d�O�O�O�O�V�V�=�
>�
>�
>��\�,�,�T�2�2�F����Y�t�_�_�f�f�#�d�d�I�d�O�O�O�O�V�V�=�
>�
>�
>�
>�
� �
�����#�#�M�2�2������6�6�6>�h�h���G�	I�	I�	I���(�(��7�7������6�6�;C�8�8�V�V�L�	N�	N�	N�	N�	Nrc
��tj�d��}|�|t	d��d|�dt	d������tj�d��}|�|dd|z��d}|�dt	d����}tj�|��}|�||d|�d|����|�dd��}tj�|��}|�||d|�d|����dS)Nr+r�r��+zusing quote_plus(): %r != +z
a b cd e fr�)rr�r�r�rr�r )r-r��givenr
s    r�test_quoting_spacezQuotingTests.test_quoting_space�sU����#�#�C�(�(�������3����6<�f�f�i��n�n�n�M�	O�	O�	O���(�(��-�-�������6��?�	A�	A�	A������s�I�c�N�N�3�3����#�#�E�*�*��������6<�f�f�f�f�E�	G�	G�	G����s�C�(�(����(�(��/�/��������;A�6�6�6�6�J�	L�	L�	L�	L�	Lrc��|�tj�d��d��|�tj�dd��d��|�tj�d��d��|�tj�dd��d��dS)Nzalpha+beta gammazalpha%2Bbeta+gammarzalpha+beta+gammasalpha+beta gamma�+)r�rr�r�rAs r�test_quoting_pluszQuotingTests.test_quoting_plus�s��������0�0�1C�D�D�-�	/�	/�	/������0�0�1C�S�I�I�+�	-�	-�	-�	
�����0�0�1D�E�E�-�	/�	/�	/�	
�����0�0�1C�T�J�J�+�	-�	-�	-�	-�	-rc�X�d}d}tj�|��}|�||d|�d|����|�t
tjj|d���tj�|��}|�||d|�d|����dS)N���ab��%A2%D8ab%FFr�r�r�rzusing quote_from_bytes(): )rr�r�r�r��	TypeError�quote_from_bytes�r-rr
r�s    r�test_quote_byteszQuotingTests.test_quote_bytes�s���!������#�#�E�*�*��������6<�f�f�f�f�E�	G�	G�	G�	
���)�V�\�%7��%.�	�	0�	0�	0���.�.�u�5�5��������"�F�F�F�F�,�	-�	-�	-�	-�	-rc�r�d}d}tj�|��}|�||d|�d|����tj�|dd���}|�||d|�d|����d}d}tj�|d���}|�||d|�d|����d	}d
}tj�|��}|�||d|�d|����d	}|�t
tjj|d���d	}d}tj�|dd���}|�||d|�d|����d	}d
}tj�|dd���}|�||d|�d|����dS)Nu¢Øabÿz%C2%A2%C3%98ab%C3%BFr�r��r�errorsrrr �漢字�%E6%BC%A2%E5%AD%97z%3F%3Fr z%26%2328450%3B%26%2323383%3B�xmlcharrefreplace)rr�r�r�r�r�r#s    r�test_quote_with_unicodez$QuotingTests.test_quote_with_unicode�s?�� ��'����#�#�E�*�*��������6<�f�f�f�f�E�	G�	G�	G���#�#�E�D��#�F�F��������6<�f�f�f�f�E�	G�	G�	G�!������#�#�E�I�#�>�>��������6<�f�f�f�f�E�	G�	G�	G���%����#�#�E�*�*��������6<�f�f�f�f�E�	G�	G�	G������,�f�l�.@�%�-6�	�	8�	8�	8�������#�#�E�I�+4�$�6�6��������6<�f�f�f�f�E�	G�	G�	G���/����#�#�E�I�+>�$�@�@��������6<�f�f�f�f�E�	G�	G�	G�	G�	Grc��d}d}tj�|d���}|�||d|�d|����d}d}tj�|dd	�
��}|�||d|�d|����dS)Nu¢Ø ÿz
%A2%D8+%FFrr r�r�uab漢字 cdzab%3F%3F+cdr r&)rr�r�r�r#s    r�test_quote_plus_with_unicodez)QuotingTests.test_quote_plus_with_unicode(s���������(�(���(�C�C��������;A�6�6�6�6�J�	L�	L�	L�$������(�(���09�)�;�;��������;A�6�6�6�6�J�	L�	L�	L�	L�	LrN)
rBrCrDr�r�rrrrrr$r+r-r&rrr�r�ks���������2Q�Q�Q�B�B�B�+�+�+�:N�N�N�8L�L�L�&
-�
-�
-�-�-�-� (G�(G�(G�T
L�
L�
L�
L�
Lrr�c�B�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
S)�UnquotingTestszwTests for unquote() and unquote_plus()

    See the doc string for quoting_Tests for details on quoting and such.

    c	�*�g}td��D]�}tt|����}t|��}tj�|��}|�||d|�d|����tj�|��}|�||d|�d|����|�|����d�	|��}~tj�|��}|�|�
d��dd|z��|�ttftjjd��|�ttftjjd	��dS)
N��using unquote(): r��using unquote_plus(): r�rr
z/using unquote(): not all characters escaped: %sr&)rrrrr��unquoter��unquote_plusr�r��countr�r!�AttributeError)r-�escape_listrrr
r��
escape_strings       r�test_unquotingzUnquotingTests.test_unquoting?s�������:�:�
	&�
	&�C��c�#�h�h�'�'�E���X�X�F��\�)�)�%�0�0�F����V�V�V�<B�F�F�F�F�K�
M�
M�
M��\�.�.�u�5�5�F����V�V�V�$�f�f�f�f�.�
/�
/�
/�
���u�%�%�%�%�����,�,�
����%�%�m�4�4��������c�*�*�A�� &�'�	(�	(�	(�	
���9�n�5�v�|�7K�T�R�R�R����9�n�5�v�|�7K�R�P�P�P�P�Prc�"�d}|}tj�|��}|�||d|�d|����d}|}tj�|��}|�||d|�d|����d}|}tj�|��}|�||d|�d|����d}t	|d��}tj�|��}|�||d|�d|����d}t	|d��}tj�|��}|�||d|�d|����d}t	|d��}tj�|��}|�||d|�d|����|�ttftjjd��|�ttftjjd��dS)	Nz%xabr2r�z%xrrz�using unquote_to_bytes(): r&)	rr�r4r�r}�unquote_to_bytesr�r!r7r#s    r�test_unquoting_badpercentz(UnquotingTests.test_unquoting_badpercentVs<��������%�%�e�,�,��������"�F�F�F�F�*,�	-�	-�	-�������%�%�e�,�,��������"�F�F�F�F�*,�	-�	-�	-�������%�%�e�,�,��������"�F�F�F�F�*,�	-�	-�	-����u�g�&�&����.�.�u�5�5��������"�F�F�F�F�*,�	-�	-�	-����u�g�&�&����.�.�u�5�5��������"�F�F�F�F�*,�	-�	-�	-����u�g�&�&����.�.�u�5�5��������"�F�F�F�F�*,�	-�	-�	-����9�n�5�v�|�7T�VZ�[�[�[����9�n�5�v�|�7T�VX�Y�Y�Y�Y�Yrc��d}d}tj�|��}|�||d|�d|����dS)Nz%Ab%eAs��r<r��rr�r=r�r#s    r�test_unquoting_mixed_casez(UnquotingTests.test_unquoting_mixed_casezsY��������.�.�u�5�5��������"�F�F�F�F�,�	-�	-�	-�	-�	-rc��dtd��z}d}tj�|��}|�||d|�d|����tj�|��}|�||d|�d|����dS)Nzab%sd�c�abcdr�r�r3)rrr�r4r�r5r#s    r�test_unquoting_partsz#UnquotingTests.test_unquoting_parts�s����)�C�.�.�(������%�%�e�,�,��������6<�f�f�f�f�E�	G�	G�	G���*�*�5�1�1��������=C�V�V�V�V�L�	N�	N�	N�	N�	Nrc�*�d}|}tj�|��}|�||d|�d|����|�dd��}tj�|��}|�||d|�d|����dS)Nzare+there+spaces...r2r�rr+r3)rr�r4r�r r5r#s    r�test_unquoting_plusz"UnquotingTests.test_unquoting_plus�s���%������%�%�e�,�,��������8>�����G�	I�	I�	I����s�C�(�(����*�*�5�1�1��������=C�V�V�V�V�L�	N�	N�	N�	N�	Nrc��d}d}tj�|��}|�||d|�d|����tj�d��}d}|�||d|�d|����d}d}tj�|��}|�||d|�d|����d	}d}tj�|��}|�||d|�d|����dS)
N�"br%C3%BCckner_sapporo_20050930.docsbrückner_sapporo_20050930.docr<r��	漢%C3%BCs漢üs%A2%D8ab%FFrs	%A2�ab%FFr@r#s    r�test_unquote_to_bytesz$UnquotingTests.test_unquote_to_bytes�sA��4��8����.�.�u�5�5��������"�F�F�F�F�,�	-�	-�	-���.�.�~�>�>��(��������"�F�F�F�F�,�	-�	-�	-���"����.�.�u�5�5��������"�F�F�F�F�,�	-�	-�	-�
 ��"����.�.�u�5�5��������"�F�F�F�F�,�	-�	-�	-�	-�	-rc��d}d}tj�|��}|�||d|�d|����tj�|dd���}|�||d|�d|����tj�dd���}d}|�||d|�d|����d	}d
}tj�|��}|�||d|�d|����d}d}tj�|��}|�||d|�d|����tj�|d
���}|�||d|�d|����d}d}tj�|d���}|�||d|�d|����tj�d��}d}|�||d|�d|����tj�dd���}d}|�||d|�d|����dS)NrIubrückner_sapporo_20050930.docr2r�r&zbr%FCckner_sapporo_20050930.docrr r)r(z%F3%B1u�r )r'r��ignorerJu漢üu漢%FC�rr�r4r�r#s    r�test_unquote_with_unicodez(UnquotingTests.test_unquote_with_unicode�s���4��5����%�%�e�,�,��������8>�����G�	I�	I�	I���%�%�e�d�4�%�H�H��������8>�����G�	I�	I�	I���%�%�&G�/8�&�:�:��5��������8>�����G�	I�	I�	I�%������%�%�e�,�,��������8>�����G�	I�	I�	I�������%�%�e�,�,��������8>�����G�	I�	I�	I���%�%�e�I�%�>�>��������8>�����G�	I�	I�	I�������%�%�e�H�%�=�=��������8>�����G�	I�	I�	I���%�%�n�5�5����������8>�����G�	I�	I�	I�
��%�%�k�I�%�F�F����������8>�����G�	I�	I�	I�	I�	Irc��d}d}tj�|��}|�||d|�d|����d}d}tj�|��}|�||d|�d|����d}d}tj�|��}|�||d|�d|����dS)	Nsblueberryjam�blueberryjamr2r�sblåbærsyltetøyublåbærsyltetøysbl%c3%a5b%c3%a6rsyltet%c3%b8jublåbærsyltetøjrNr#s    r�test_unquoting_with_bytes_inputz.UnquotingTests.test_unquoting_with_bytes_input�s���������%�%�e�,�,��������8>�����G�	I�	I�	I�7��0����%�%�e�,�,��������8>�����G�	I�	I�	I�1��0����%�%�e�,�,��������8>�����G�	I�	I�	I�	I�	IrN)rBrCrDr�r:r>rArErGrKrOrRr&rrr/r/8s���������Q�Q�Q�."Z�"Z�"Z�H-�-�-�
N�
N�
N�
N�
N�
N�-�-�-�>8I�8I�8I�tI�I�I�I�Irr/c�Z�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�ZdS)�urlencode_TestszTests for urlencode()c�j�gd�}tj�|��}|D]"}|�||d|�d|�d|�����#|�|�d��dd|�d|�d������|�d��}||dz
}||dz}|�|���o|���d|�d	|����|�t|��d
d|�dt|���dd
����d
S)aHelper method for testing different input types.

        'given' must lead to only the pairs:
            * 1st, 1
            * 2nd, 2
            * 3rd, 3

        Test cannot assume anything about order.  Docs make no guarantee and
        have possible dictionary input.

        )z1st=1z2nd=2z3rd=3ztesting z: z not found in �&rz: expected 2 '&'s; got r
z%: '&' not located in proper place in �z#: unexpected number of characters: r�N)
rr��	urlencoderur�r6�indexr��isdigitr)	r-r�	test_type�expect_somewherer�r�amp_location�on_amp_left�on_amp_rights	         r�help_inputtypezurlencode_Tests.help_inputtypes~��7�6�6����'�'��.�.��(�	8�	8�H��M�M�(�F�F�#�)�)�X�X�X�v�v�7�
8�
8�
8�
8�	
������c�*�*�A�A�#�)�)�V�\�\�#�%6�%6�%6�8�	9�	9�	9��|�|�C�(�(���\�A�-�.���l�Q�.�/������+�+�-�-�H�,�2F�2F�2H�2H���i�i���)�	*�	*�	*�	
����V���k�k�$�)�)�S��[�[�[�[�+�+�?�	@�	@�	@�	@�	@rc�:�|�dddd�d��dS)N�1�2�3)�1st�2nd�3rdzusing dict as input type�r`rAs r�test_using_mappingz"urlencode_Tests.test_using_mapping.s3�����3�c��=�=�6�	8�	8�	8�	8�	8rc�6�|�gd�d��dS)N))rerb)rfrc)rgrdz*using sequence of two-item tuples as inputrhrAs r�test_using_sequencez#urlencode_Tests.test_using_sequence3s5�����F�F�F�H�	J�	J�	J�	J�	Jrc�0�ddi}td���dtd����}tj�|��}|�||��ddi}d}tj�|��}|�||��dS)NrV�=zkey namezA bunch of pluseszkey+name=A+bunch+of+pluses)rrr�rXr�r#s    r�test_quotingzurlencode_Tests.test_quoting8s����S�	��%�c�N�N�N�N�I�c�N�N�N�;����'�'��.�.�������(�(�(��/�0��-����'�'��.�.�������(�(�(�(�(rc���dgd�i}dtj�tgd�����z}tj�|��}|�||��tj�|d��}|dD]}d|z}|�||���|�|�d��dd|�d��z��dS)N�sequence)rbrcrdzsequence=%sTrVrzExpected 2 '&'s, got %s)rr�r�r�rXr�rur6)r-rr
r��values     r�
test_doseqzurlencode_Tests.test_doseqCs����O�O�O�,�����!8�!8��_�_�_�9M�9M�!N�!N�N����'�'��.�.�������(�(�(���'�'��t�4�4���:�&�	*�	*�E�"�U�*�F��M�M�&�&�)�)�)�)�������c�*�*�A�2�V�\�\�#�5F�5F�F�	H�	H�	H�	H�	Hrc���|�dtj�i����|�dtj�g����dSr|�r�rr�rXrAs r�test_empty_sequencez#urlencode_Tests.test_empty_sequencePsT������V�\�3�3�B�7�7�8�8�8�����V�\�3�3�B�7�7�8�8�8�8�8rc���|�dtj�ddi����|�dtj�ddi����dS)Nza=1�ar
za=NonertrAs r�test_nonstring_valuesz%urlencode_Tests.test_nonstring_valuesTs\�������� 6� 6��Q�x� @� @�A�A�A�����6�<�#9�#9�3��+�#F�#F�G�G�G�G�Grc�~�|�dtj�dddgid����|�dtj�dddgid����t	jddg��}|�d	tj�d|id����dS)
Nza=1&a=2rwr
rTz
a=None&a=a)rwr
)�br
za=a&a=b)r�rr�rXr�r�)r-r s  r�test_nonstring_seq_valuesz)urlencode_Tests.test_nonstring_seq_valuesXs�������F�L�$:�$:�C�!�Q��=�$�$O�$O�P�P�P�������/�/��t�S�k�0B�D�I�I�	K�	K�	K��&��(�';�<�<��������/�/��d��T�B�B�	D�	D�	D�	D�	Drc�f�d}d}tj�|dd���}|�||��d}d}tj�|��}|�||��d}d}tj�|d�	��}|�||��dS)
N�)� �Á�%3F=%3Frqr r&�
%C2%A0=%C3%81�%A0=%C1rr �rr�rXr�r#s    r�test_urlencode_encodingz'urlencode_Tests.test_urlencode_encoding`s���'������'�'���	�'�R�R�������(�(�(�(�� ����'�'��.�.�������(�(�(�(������'�'��	�'�B�B�������(�(�(�(�(rc���d}d}tj�|ddd���}|�||��d}d}tj�|ddd�	��}|�||��d}d
}tj�|d��}|�||��d}d}tj�|d��}|�||��d}d
}tj�|dd���}|�||��d}d}tj�|dd���}|�||��dS)Nr}r�Trqr )�doseqrr'))r~)r
rz
%3F=1&%3F=%3Fr&r�))r~)�*rz%C2%A0=42&%C2%A0=%C3%81r�rr z%A0=42&%A0=%C1r�r#s    r�test_urlencode_encoding_doseqz-urlencode_Tests.test_urlencode_encoding_doseqss���'������'�'��T�18��(�L�L�������(�(�(�-�� ����'�'��t�18��(�L�L�������(�(�(�(�� ����'�'��t�4�4�������(�(�(�-��*����'�'��t�4�4�������(�(�(�(������'�'��t�i�'�H�H�������(�(�(�-��!����'�'��t�i�'�H�H�������(�(�(�(�(rc�X�d}d}tj�|��}|�||��tj�|d��}|�||��d}d}tj�|d��}|�||��dS)N�)��$��$z
%A0%24=%C1%24T))r�)r�r�z%A0%24=42&%A0%24=%C1%24r�r#s    r�test_urlencode_bytesz$urlencode_Tests.test_urlencode_bytes�s���-�� ����'�'��.�.�������(�(�(���'�'��t�4�4�������(�(�(�4��*����'�'��t�4�4�������(�(�(�(�(rc��d}tj�|d���}d}|�||��d}tj�|dd���}d}|�||��d}d}tj�|dd���}|�||��d}tj�|dd	�
��}d}|�||��d}d}tj�|ddd	���}d}d}tj�|ddd	�
��}|�||��dS)Nr�z:$rz	%A0$=%C1$T)r�r))r�)r��
r�z%A0$=%C1$&%A0$=13&%A0$=42r)rr)r�rrr�)r-rr�r
s    r�&test_urlencode_encoding_safe_parameterz6urlencode_Tests.test_urlencode_encoding_safe_parameter�sy��
.����'�'��D�'�9�9���������(�(�(�-����'�'��T��'�E�E���������(�(�(�9��,����'�'��t�$�'�?�?�������(�(�(�.����'�'��D�1:�(�<�<���������(�(�(�-������'�'��T��1:�(�<�<��9��,����'�'��t�$�1:�(�<�<�������(�(�(�(�(rN)rBrCrDr�r`rirkrnrrrurxr{r�r�r�r�r&rrrTrTs���������@�@�@�@8�8�8�
J�J�J�
	)�	)�	)�H�H�H�9�9�9�H�H�H�D�D�D�)�)�)�&#)�#)�#)�J)�)�)�&)�&)�&)�&)�&)rrTc��eZdZdZd�Zd�Zejej	dkd��d���Z
ejej	dkd��d���Zd	S)
�Pathname_Testsz&Test pathname2url() and url2pathname()c�>�tj�dddd��}d}tj�|��}|�||d|�d|����tj�|��}|�||d|�d|����dS)	N�parts�ofrwrWzparts/of/a/path�pathname2url() failed; r�zurl2pathame() failed; )r�rWr�rrr	r�r)r-�
expected_path�expected_urlr�s    rr�zPathname_Tests.test_basic�s�������W�d�C��@�@�
�(����,�,�]�;�;������v�v� �&�&�,�,�0�	1�	1�	1���,�,�\�:�:�������� �&�&�-�-�1�	2�	2�	2�	2�	2rc�8�tj�ddd��}dtj�d��z}tj�|��}|�||d|�d|����|}tj�	|��}|�||d|�d|����tj�dd	��}d
tj�d��z}tj�|��}|�||d|�d|����d}tj�dd
��}tj�	|��}|�||d|�d|����dS)N�needszquot=ing�herez
needs/%s/herer�r�zurl2pathname() failed; z	make sure�using_quotez%s/using_quotezmake+sure/using_unquotez	make+sure�
using_unquote)
r�rWr�rr�r�rr	r�rr#s    rrnzPathname_Tests.test_quoting�s�������W�j�&�9�9�� �6�<�#5�#5�j�#A�#A�A����,�,�U�3�3�������� �&�&�&�&�*�	+�	+�	+�����,�,�V�4�4�������� �&�&�&�&�*�	+�	+�	+�����[�-�8�8��!�F�L�$6�$6�{�$C�$C�C����,�,�U�3�3�������� �&�&�&�&�*�	+�	+�	+�*������k�?�;�;����,�,�U�3�3�������� �&�&�&�&�*�	+�	+�	+�	+�	+r�win32z*test specific to the nturl2path functions.c��d}d}tj�|��}|�||d|�d|����d}d}tj�|��}|�||d|�d|����dS)Nz
\\?\C:\dirz	///C:/dirr�r�z\\?\unc\server\share\dirz/server/share/dir)rrr	r�r#s    r�
test_prefixeszPathname_Tests.test_prefixes�s���!������,�,�U�3�3�������� �&�&�&�&�*�	+�	+�	+�1��$����,�,�U�3�3�������� �&�&�&�&�*�	+�	+�	+�	+�	+rz.test specific to the urllib.url2path function.c	��d}d}|D]>}tj�|��}|�||d|�d|�����?d}d}tj�|��}|�||d|�d|����dS)N)z/C:/z///C:/z/C|//�C:\z'urllib.request..url2pathname() failed; r�z
///C|/pathzC:\pathz&urllib.request.url2pathname() failed; )rrrr�)r-rr
rr�s     r�test_ntpathzPathname_Tests.test_ntpaths���,�����	/�	/�C��^�0�0��5�5�F����V�V�V�$�f�f�f�f�.�
/�
/�
/�
/�������,�,�U�3�3�������� �&�&�&�&�*�	+�	+�	+�	+�	+rN)rBrCrDr�r�rnr�r��sys�platformr�r�r&rrr�r��s�������0�0�2�2�2�+�+�+�6�X�����0�E�G�G�
+�
+�G�G�
+� �X�����0�I�K�K�
+�
+�K�K�
+�
+�
+rr�c��eZdZdZd�ZdS)�
Utility_Testsz=Testcase to test the various utility functions in the urllib.c�t�|�tj���t��dS)zATest the urllib.request.thishost utility function returns a tupleN)r�rr�thishost�tuplerAs r�
test_thishostzUtility_Tests.test_thishosts,�����f�n�5�5�7�7��?�?�?�?�?rN)rBrCrDr�r�r&rrr�r�s.������G�G�@�@�@�@�@rr�c��eZdZdZd�Zeje���d���Zeje���d���Z	eje���d���Z
dS)�URLopener_Testsz4Testcase to test the open method of URLopener class.c�l�Gd�dtjj��}tjdt
f��5|�|���d��d��|�|���d��d��ddd��dS#1swxYwYdS)Nc��eZdZd�ZdS)�8URLopener_Tests.test_quoted_open.<locals>.DummyURLopenerc��|Sr+r&�r-rs  r�	open_spamzBURLopener_Tests.test_quoted_open.<locals>.DummyURLopener.open_spam)����
rN)rBrCrDr�r&rr�DummyURLopenerr�(�#������
�
�
�
�
rr�z8DummyURLopener style of invoking requests is deprecated.zspam://example/ /z//example/%20/z,spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/z'//c:|windows%/:=&?~#+!$,;'@()*[]|/path/)rrr}rr$r%r�r)r-r�s  r�test_quoted_openz URLopener_Tests.test_quoted_open's+��	�	�	�	�	�V�^�5�	�	�	��
+�K�"�$�%�%�		;�		;�
���^�^�-�-�2�2�#�%�%�%5�
7�
7�
7�
���^�^�-�-�2�2�>�@�@�9�
;�
;�
;�		;�		;�		;�		;�		;�		;�		;�		;�		;�		;�		;�		;����		;�		;�		;�		;�		;�		;s�A#B)�)B-�0B-)�categoryc��tj��5}tj|���\}}t	j|��dtj�|��z}tj�	���
|��\}}|�tj�
|��tj�
|����ddd��dS#1swxYwYdS)N)�dirzfile:)r�temp_dirrUrVr�r@rrr	r}�retriever�rW�normcase)r-�tmpdirr[�tmpfile�fileurlrN�_s       r�test_urlopener_retrieve_filez,URLopener_Tests.test_urlopener_retrieve_file6s��
�
�
!�
!�	T�V�"�*�v�6�6�6�K�B���H�R�L�L�L���� ;� ;�G� D� D�D�G� �.�2�2�4�4�=�=�g�F�F�K�H�a����R�W�-�-�h�7�7���9I�9I�'�9R�9R�S�S�S�
	T�	T�	T�	T�	T�	T�	T�	T�	T�	T�	T�	T����	T�	T�	T�	T�	T�	Ts�CC4�4C8�;C8c�B�d}|�d��|�|j��tj����|��\}}|�tj	�
|��dd��dS)Nzhttp://www.python.org/file.txtrr
z.txt)rTr�r\rrr}r�r�r�rW�splitext)r-rrNr�s    r�test_urlopener_retrieve_remotez.URLopener_Tests.test_urlopener_retrieve_remote@s���.���
�
�6�7�7�7������(�(�(��n�.�.�0�0�9�9�#�>�>���!������)�)�(�3�3�A�6��?�?�?�?�?rc�8�Gd�dtjj��}dD]�}|�ttjj|��|�ttj���j|��|�ttj���j|��|�t|��j|��|�t|��j|����dS)Nc��eZdZd�ZdS)�<URLopener_Tests.test_local_file_open.<locals>.DummyURLopenerc��|Sr+r&r�s  r�open_local_filezLURLopener_Tests.test_local_file_open.<locals>.DummyURLopener.open_local_fileLr�rN)rBrCrDr�r&rrr�r�Kr�rr�)zlocal_file://examplezlocal-file://example)rrr}r�r=r"rr�)r-r�rs   r�test_local_file_openz$URLopener_Tests.test_local_file_openHs	��	�	�	�	�	�V�^�5�	�	�	�D�	G�	G�C����g�v�~�'=�s�C�C�C����g�v�~�'?�'?�'A�'A�'F��L�L�L����g�v�~�'?�'?�'A�'A�'J�C�P�P�P����g�~�~�'7�'7�'<�c�B�B�B����g�~�~�'7�'7�'@�#�F�F�F�F�	G�	GrN)rBrCrDr�r�r�ignore_warningsr%r�r�r�r&rrr�r�$s�������>�>�
;�
;�
;�%�_�$�.@�A�A�A�T�T�B�A�T�%�_�$�.@�A�A�A�@�@�B�A�@�%�_�$�.@�A�A�A�
G�
G�B�A�
G�
G�
Grr�c��eZdZdZd�Zd�ZdS)�RequestTestsz&Unit tests for urllib.request.Request.c��tjj}|d��}|�|���d��|di��}|�|���d��dS)Nrr��POST)rr�Requestr��
get_method�r-r�rs   r�test_default_valuesz RequestTests.test_default_valuesYsx���.�(���'�1�2�2������+�+�-�-�u�5�5�5��'�1�2�6�6������+�+�-�-�v�6�6�6�6�6rc�2�tjj}|dd���}|�|jd��|�|���d��|did���}|�|jd��|�|���d��|dd���}|�|���d��d|_|�|���d��dS)Nr�HEAD)�methodr�)rrr�r�r�r�r�s   r�test_with_method_argz!RequestTests.test_with_method_arg`s���.�(���'�1�&�A�A�A��������0�0�0�����+�+�-�-�v�6�6�6��'�1�2�f�E�E�E��������0�0�0�����+�+�-�-�v�6�6�6��'�1�%�@�@�@������+�+�-�-�u�5�5�5��������+�+�-�-�v�6�6�6�6�6rN)rBrCrDr�r�r�r&rrr�r�Vs8������0�0�7�7�7�7�7�7�7�7rr�c�,�eZdZd�Zd�Zd�Zd�Zd�ZdS)�URL2PathNameTestsc���|�td��d��|�td��d��|�td��d��dS)Nz///C|�C:�///C:z///C|/r��r�rrAs r�test_converting_drive_letterz.URL2PathNameTests.test_converting_drive_letterpsb������g�.�.��5�5�5�����g�.�.��5�5�5�����h�/�/��8�8�8�8�8rc��|�td��d��|�td��d��dS)Nz
///C/test/z
\\\C\test\z////C/test/z	\\C\test\r�rAs r�$test_converting_when_no_drive_letterz6URL2PathNameTests.test_converting_when_no_drive_letterusF������l�3�3�5F�G�G�G�����m�4�4�6F�G�G�G�G�Grc�L�|�td��d��dS)Nz///C|/foo/bar/spam.foo�C:\foo\bar\spam.foor�rAs r�test_simple_comparez%URL2PathNameTests.test_simple_comparezs2������&>�?�?�/�	1�	1�	1�	1�	1rc�H�|�ttd��dS)Nu///è|/)r��IOErrorrrAs r�test_non_ascii_drive_letterz-URL2PathNameTests.test_non_ascii_drive_letter~s �����'�<��?�?�?�?�?rc�x�gd�}|D]2}|�tt|����|���3dS)N)r�z\\\C\test\\r�)r�rr	�r-�
list_of_pathsrWs   r�test_roundtrip_url2pathnamez-URL2PathNameTests.test_roundtrip_url2pathname�s[�����
�"�	E�	E�D����\�,�t�*<�*<�=�=�t�D�D�D�D�	E�	ErN)rBrCrDr�r�r�r�r�r&rrr�r�nsj������9�9�9�
H�H�H�
1�1�1�@�@�@�E�E�E�E�Err�c�,�eZdZd�Zd�Zd�Zd�Zd�ZdS)�PathName2URLTestsc��|�td��d��|�td��d��dS)Nr�r�r��r�r	rAs rr�z.PathName2URLTests.test_converting_drive_letter�sD������d�+�+�W�5�5�5�����f�-�-�w�7�7�7�7�7rc���|�td��d��|�td��d��|�td��d��dS)Nz\\\folder\test\�/////folder/test/z\\folder\test\z////folder/test/z
\folder\test\z
/folder/test/r�rAs rr�z6PathName2URLTests.test_converting_when_no_drive_letter�s~������&<�=�=�,�	.�	.�	.�����&;�<�<�+�	-�	-�	-�����&:�;�;�(�	*�	*�	*�	*�	*rc�L�|�td��d��dS)Nr��///C:/foo/bar/spam.foor�rAs rr�z%PathName2URLTests.test_simple_compare�s2������&<�=�=�1�	4�	4�	4�	4�	4rc�H�|�ttd��dS)NzXX:\)r�r�r	rAs r�test_long_drive_letterz(PathName2URLTests.test_long_drive_letter�s �����'�<��9�9�9�9�9rc�x�gd�}|D]2}|�tt|����|���3dS)N)r�r�r�)r�r	rr�s   r�test_roundtrip_pathname2urlz-PathName2URLTests.test_roundtrip_pathname2url�s[��3�3�3�
�"�	E�	E�D����\�,�t�*<�*<�=�=�t�D�D�D�D�	E�	ErN)rBrCrDr�r�r�r�r�r&rrr�r��sd������8�8�8�*�*�*�4�4�4�:�:�:�E�E�E�E�Err��__main__)NNr]);r��urllib.parser�urllib.request�urllib.error�http.clientrQ�
email.messager�r8r��
unittest.mockrrjr�test.supportrrrr�r��ImportErrorr�rU�
nturl2pathrr	�base64r
r��has_gethostnamer�rrr"rrTrqrVr_�TestCaserxr�r�rr�r�r�r�r/rTr�r�r�r�r�r�rB�mainr&rr�<module>rs���A�A���������������������	�	�	�	�����������������"�"�"�"�"�"�&�&�&�&�&�&�(�(�(�(�(�(�	�	�	�	���J�J�J�J������
�C�C�C�����
�
�
�
�����1�1�1�1�1�1�1�1������������$�;�
�(�
�9�
:�
:�:�����
�
&�
&�
&�
&� /�/�/�,�,�,�,�^<�<�<�<�<�F�<�<�<�;�;�;�;�;�6�;�;�;�(ZR�ZR�ZR�ZR�ZR��)�ZR�ZR�ZR�zD9�D9�D9�D9�D9��"�D9�D9�D9�N!C�!C�!C�!C�!C�� 1�!C�!C�!C�HH�H�H�H�H��)�=�,�H�H�H�VJP�JP�JP�JP�JP��)�JP�JP�JP�ZL-�L-�L-�L-�L-�H�-�L-�L-�L-�^*"�*"�*"�*"�*"�H�-�}�*"�*"�*"�ZJL�JL�JL�JL�JL�8�$�JL�JL�JL�ZPI�PI�PI�PI�PI�X�&�PI�PI�PI�fA)�A)�A)�A)�A)�h�'�A)�A)�A)�FL+�L+�L+�L+�L+�X�&�L+�L+�L+�\@�@�@�@�@�H�%�@�@�@�/G�/G�/G�/G�/G�m�X�%6�/G�/G�/G�d7�7�7�7�7�8�$�7�7�7�0E�E�E�E�E��)�E�E�E�6E�E�E�E�E��)�E�E�E�8�z����H�M�O�O�O�O�O��s�A�A�A