Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.11/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.11/test/__pycache__/test_urllib2.cpython-311.pyc

�

SԚg�;����ddlZddlmZddlmZddlmZddlmZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZmZmZmZmZmZmZddlmZddlZddlZejd	�
��Gd�dej��Z Gd
�dej��Z!Gd�d��Z"Gd�d��Z#Gd�de$��Z%Gd�de	j&��Z'Gd�d��Z(Gd�d��Z)Gd�de	j*��Z+Gd�d��Z,Gd�d ��Z-d!�Z.d"�Z/Gd#�d$ej0j1��Z2Gd%�d&ej0j3��Z4Gd'�d(ej0j1��Z5Gd)�d*��Z6Gd+�d,ej��Z7d-�Z8Gd.�d/ej��Z9Gd0�d1ej��Z:Gd2�d3ej��Z;e<d4krej=��dSdS)5�N)�support)�	os_helper)�
socket_helper)�warnings_helper)�test_urllib)�Request�OpenerDirector�HTTPBasicAuthHandler�HTTPPasswordMgrWithPriorAuth�_parse_proxy�_proxy_bypass_winreg_override�_proxy_bypass_macosx_sysconf�AbstractDigestAuthHandler)�urlparseT)�modulec�&�eZdZd�Zd�Zd�Zd�ZdS)�TrivialTestsc��dD]�}i}td|z|��|d=|dkrptjdkr`|�d��|�d��}}|�|jd��|�|jd��|���D]1\}}|�|jd	|z|�d
|�d|j�����2��dS)N)�request�response�parse�error�robotparserzfrom urllib.%s import *�__builtins__r�nt�url2pathname�pathname2url�
nturl2pathz	urllib.%sz is exposed in 'urllib.z' but defined in )�exec�os�name�pop�assertEqual�
__module__�items)�selfr�context�u�p�k�vs       �./usr/local/lib/python3.11/test/test_urllib2.py�test___all__zTrivialTests.test___all__&s��L�	/�	/�F��G��*�V�3�W�=�=�=���'���"�"�r�w�$����{�{�>�2�2�G�K�K��4O�4O�1��� � ���|�<�<�<�� � ���|�<�<�<��
�
���
/�
/���1�� � ���{�V�/C��Q�Q�������.�/�/�/�/�
/�	/�	/�c�
�|�tjj��|�t
tjjd��tj�	tjj
���tjd��}tj
dkrd|z}nd|z}tj�|��5}|���ddd��dS#1swxYwYdS)Nz	bogus url�/rz
file:///%s�	file://%s)�
addCleanup�urllibr�
urlcleanup�assertRaises�
ValueError�urlopenr �path�abspath�__file__�replace�sepr!�read)r&�fname�file_url�fs    r,�test_trivialzTrivialTests.test_trivial5s	��	
�����1�2�2�2����*�f�n�&<�k�J�J�J������� 7�8�8�@�@����M�M��
�7�d�?�?�#�e�+�H�H�"�U�*�H�
�^�
#�
#�H�
-�
-�	��
�F�F�H�H�H�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�C8�8C<�?C<c��dgd�fdddgfdgd�fdgd	�fg}|D]8\}}|�tj�|��|���9dS)
Nza,b,c)�a�b�czpath"o,l"og"i"cal, examplezpath"o,l"og"i"cal�exampleza, b, "c", "d", "e,f", g, h)rCrDz"c"z"d"z"e,f"�g�hza="b\"c", d="e\,f", g="h\\i")za="b"c"zd="e,f"zg="h\i")r#r3r�parse_http_list)r&�tests�string�lists    r,�test_parse_http_listz!TrivialTests.test_parse_http_listHs���
�o�o�o�&�
)�,?��+K�L�
*�
8�
8�
8�
:�
/�
/�
/�
/�
1�2��"�	K�	K�L�F�D����V�^�;�;�F�C�C�T�J�J�J�J�	K�	Kr.c��tj�d��}|�|jt|����dS)N�reason)r3r�URLError�assertInrO�str)r&�errs  r,�test_URLError_reasonstrz$TrivialTests.test_URLError_reasonstrSs9���l�#�#�H�-�-���
�
�c�j�#�c�(�(�+�+�+�+�+r.N)�__name__r$�__qualname__r-rArMrT�r.r,rr$sS������
/�
/�
/����&	K�	K�	K�,�,�,�,�,r.rc�&�eZdZd�Zd�Zd�Zd�ZdS)�RequestHdrsTestsc���d}|�t|ddi���jdd��|�t|ddi���jdd��dS)a(
        The Request.headers dictionary is not a documented interface.  It
        should stay that way, because the complete set of headers are only
        accessible through the .get_header(), .has_header(), .header_items()
        interface.  However, .headers pre-dates those methods, and so real code
        will be using the dictionary.

        The introduction in 2.4 of those methods was a mistake for the same
        reason: code that previously saw all (urllib2 user)-provided headers in
        .headers now sees only a subset.

        �http://example.com�	Spam-eggs�blah��headersz	spam-EggSN)r#rr_)r&�urls  r,�test_request_headers_dictz*RequestHdrsTests.test_request_headers_dictZs���#�������*5�v�)>�#�#�#�#*�;�8�9?�	A�	A�	A�	
�����*5�v�)>�#�#�#�#*�;�8�9?�	A�	A�	A�	A�	Ar.c���d}t|ddi���}|�|�d����|�|���dg��|�dd��|�t
|�����ddg��|�|�d	����|�|�	d	����|�|�	d	d
��d
��|�
d��|�|�d����|�dd��|�|�d����|�
d��|�|�d����d
S)a;
        Note the case normalization of header names here, to
        .capitalize()-case.  This should be preserved for
        backwards-compatibility.  (In the HTTP case, normalization to
        .title()-case is done by urllib2 before sending headers to
        http.client).

        Note that e.g. r.has_header("spam-EggS") is currently False, and
        r.get_header("spam-EggS") returns None, but that could be changed in
        future.

        Method r.remove_header should remove items both from r.headers and
        r.unredirected_hdrs dictionaries
        r[r\r]r^)r\r]zFoo-Bar�baz)zFoo-barrcz	Not-there�defaultzUnredirected-spam�EggsN)r�
assertTrue�
has_headerr#�header_items�
add_header�sorted�assertFalse�assertIsNone�
get_header�
remove_header�add_unredirected_header)r&r`�reqs   r,�test_request_headers_methodsz-RequestHdrsTests.test_request_headers_methodsos���#���c�K��#8�9�9�9��������{�3�3�4�4�4�����)�)�+�+�.C�-D�E�E�E����y�%�(�(�(������ 0� 0� 2� 2�3�3�,�.C�D�	F�	F�	F��������4�4�5�5�5����#�.�.��5�5�6�6�6��������Y�?�?��K�K�K����+�&�&�&��������4�4�5�5�5��#�#�$7��@�@�@�������':�;�;�<�<�<����-�.�.�.�������(;�<�<�=�=�=�=�=r.c�n�tj���}|j}|j}|dddd��|dddd��|dddd	��|dd
dd��|dd
dd��|�|dd��d��|�|dd��d��|�|dd��d��|�|dd��d��|�|dd��d��|�|dd��d��|d	ddd��|d	ddd��|d	ddd��|�|d	d��d��|�|d	d��d��|�|d	d��d��|�|d	d��d��|�|d	d ��d��|�|d	d!��d"��|d	d#d$d%��|�|d	d&��d"��|�|d	d#��d'��|�|d	d(��d'��|d)dd*d+��|d)dd,d-��|�|d)d��d.��|d/dd0d/��|�|d/d��d1��|�|d/d2��d"��|�|dd3��d"��|�|dd4��d5��|�|dd��d5��|�|dd
��d6��|�|dd
��d7��dS)8Nz
Some Realm�http://example.com/�joe�passwordzhttp://example.com/ni�nizhttp://c.example.com:3128�3rEz
d.example.com�4�dze.example.com:3128�5�e�example.com)rtrur[zhttp://example.com/spamzhttp://example.com/spam/spamzhttp://example.com/foo�foozhttp://example.com/bar�bar�ninizhttp://example.com/foo/bar�foobar�nibar)r}rv)r~rzhttp://example.com/foo/zhttp://example.com/foo/bazzhttp://example.com/foobar�NNzhttp://example.com/baz/rc�nininizhttp://example.com/baz)rcr�zhttp://example.com/baz/barrD�firstr]�second�spam)r�r�rC�1)r�rCzhttp://a.example.com/z
c.example.comzc.example.com:3128)rwrE)rxry)rzr{�r3r�HTTPPasswordMgr�add_password�find_user_passwordr#�r&�mgr�add�find_user_passs    r,�test_password_managerz&RequestHdrsTests.test_password_manager�s$���n�,�,�.�.������/����L�/��
�C�C�C���L�1�4��>�>�>���L�5�s�C�@�@�@���L�/�3��4�4�4���L�.��S�9�9�9�	
������m�D�D�,�	.�	.�	.�������6M�N�N�,�	.�	.�	.�������6J�K�K�,�	.�	.�	.�������6K�L�L�,�	.�	.�	.�������(A�C�C�,�	.�	.�	.�	
������(F�H�H�,�	.�	.�	.�	��C�)�5�$�7�7�7���C�)�5�&�9�9�9���C�-�x��A�A�A�������-E�F�F�&�	(�	(�	(�������-E�F�F�(�	*�	*�	*�������-F�G�G�&�	(�	(�	(�������-I�J�J�&�	(�	(�	(�������-I�J�J�&�	(�	(�	(�������-H�I�I�%�	'�	'�	'�	��C�*�E�8�<�<�<�������-E�F�F�%�	'�	'�	'�������-F�G�G�*�	,�	,�	,�������-I�J�J�*�	,�	,�	,�
	��C�&���8�8�8���C�&��&�9�9�9�������-B�C�C�+�	-�	-�	-�
	��C�%�s�C�0�0�0�������-B�C�C�#�	%�	%�	%�	
������-D�E�E�%�	'�	'�	'�
	
������o�F�F�%�	'�	'�	'�������6J�K�K�#�	%�	%�	%�����N�<�)D�E�E��	�	�	�	
������o�F�F�#�	%�	%�	%�������6J�K�K�#�	%�	%�	%�	%�	%r.c���tj���}|j}|j}|dddd��|dddd��|d	d
dd��|d
ddd��|�|dd��d��|�|dd��d��|�|dd��d��|�|dd��d��|�|dd��d��|�|dd��d��|�|dd��d��|�|dd��d��|�|dd��d��|�|d	d��d��|�|d	d
��d��|�|d	d��d��|�|d
d��d��|�|d
d ��d��|�|d
d!��d��|�|d
d"��d��d#S)$z�
        The point to note here is that we can't guess the default port if
        there's no scheme.  This applies to both add_password and
        find_user_password.
        r@zhttp://g.example.com:80�10�jrGzhttp://h.example.com�11r*rHzi.example.com:80�12�l�iz
j.example.com�13�mzg.example.com:100r�zg.example.com:80)r�r�z
g.example.comzhttp://g.example.com:100zhttp://g.example.comz
h.example.com)r�r*zh.example.com:80zhttp://h.example.com:80z
i.example.com)r�r�zhttp://i.example.com:80)r�r�zj.example.com:80zhttp://j.example.comzhttp://j.example.com:80Nr�r�s    r,�"test_password_manager_default_portz3RequestHdrsTests.test_password_manager_default_port�s���n�,�,�.�.������/����C�*�D�#�6�6�6���C�'��s�3�3�3���C�#�T�3�/�/�/���C��$��,�,�,�������-@�A�A�%�	'�	'�	'�������-?�@�@�$�	&�	&�	&�������_�=�=�%�	'�	'�	'�������-G�H�H�%�	'�	'�	'�������-F�G�G�$�	&�	&�	&�������-C�D�D�$�	&�	&�	&�������_�=�=�{�K�K�K�������-?�@�@�+�N�N�N�������-F�G�G�$�	&�	&�	&�������_�=�=�|�L�L�L�������-?�@�@�+�N�N�N�������-F�G�G�$�	&�	&�	&�������_�=�=�{�K�K�K�������-?�@�@�%�	'�	'�	'�������-C�D�D�$�	&�	&�	&�������-F�G�G�%�	'�	'�	'�	'�	'r.N)rUr$rVrarqr�r�rWr.r,rYrYXsX������A�A�A�*">�">�">�HT%�T%�T%�l''�''�''�''�''r.rYc�.�eZdZgZdejfd�Zd�ZdS)�
MockOpenerNc�2�|||c|_|_|_dS�N)rp�data�timeout)r&rpr�r�s    r,�openzMockOpener.opens��,/��w�)���$�)�T�\�\�\r.c�$�||c|_|_dSr�)�proto�args)r&r�r�s   r,rzMockOpener.errors�� %�t���
�D�I�I�Ir.)rUr$rV�
addheaders�socket�_GLOBAL_DEFAULT_TIMEOUTr�rrWr.r,r�r�sD�������J�!�6�+I�?�?�?�?�,�,�,�,�,r.r�c�$�eZdZdd�Zdd�Zd�ZdS)�MockFileNc��dSr�rW�r&�counts  r,r=z
MockFile.read����r.c��dSr�rWr�s  r,�readlinezMockFile.readline!r�r.c��dSr�rW�r&s r,�closezMockFile.close$r�r.r�)rUr$rVr=r�r�rWr.r,r�r�sK������
�
�
�
�
�
�
�
�
�
�
�
�
r.r�c��eZdZd�ZdS)�MockHeadersc�D�t|�����Sr�)rL�values)r&r!s  r,�
getheaderszMockHeaders.getheaders)s���D�K�K�M�M�"�"�"r.N)rUr$rVr�rWr.r,r�r�(s#������#�#�#�#�#r.r�c�"�eZdZdd�Zd�Zd�ZdS)�MockResponseNc��tj�||��||||f\|_|_|_|_dSr�)�io�StringIO�__init__�code�msgr_r`)r&r�r�r_r�r`s      r,r�zMockResponse.__init__.s=��
����T�4�(�(�(�6:�C��#�6M�3��	�4�8�T�\�4�8�8�8r.c��|jSr�r^r�s r,�infozMockResponse.info2s
���|�r.c��|jSr��r`r�s r,�geturlzMockResponse.geturl5�	���x�r.r�)rUr$rVr�r�r�rWr.r,r�r�-sJ������N�N�N�N��������r.r�c��eZdZd�Zd�ZdS)�
MockCookieJarc��||_dSr�)�ach_req)r&rs  r,�add_cookie_headerzMockCookieJar.add_cookie_header:s
������r.c�$�||c|_|_dSr�)�ec_req�ec_r)r&rrs   r,�extract_cookieszMockCookieJar.extract_cookies=s��!(�(����T�Y�Y�Yr.N)rUr$rVr�r�rWr.r,r�r�9s2���������3�3�3�3�3r.r�c��eZdZd�Zd�ZdS)�
FakeMethodc�0�||_||_||_dSr�)�	meth_name�handle�action)r&r�r�r�s    r,r�zFakeMethod.__init__Bs��"����������r.c�4�|j|j|jg|�R�Sr�)r�r�r�)r&r�s  r,�__call__zFakeMethod.__call__Gs"���t�{�4�>�4�;�>��>�>�>�>r.N)rUr$rVr�r�rWr.r,r�r�As2���������
?�?�?�?�?r.r�c�&�eZdZd�Zd�Zd�Zd�ZdS)�MockHTTPResponsec�L�||_||_||_||_d|_dS)N��)�fpr��statusrOr�)r&r�r�r�rOs     r,r�zMockHTTPResponse.__init__Ls)����������������	�	�	r.c��dS)N�rWr�s r,r=zMockHTTPResponse.readSs���rr.c��iSr�rWr�s r,r�zMockHTTPResponse.infoVs���	r.c��|jSr�r�r�s r,r�zMockHTTPResponse.geturlYr�r.N)rUr$rVr�r=r�r�rWr.r,r�r�KsP�������������������r.r�c�P�eZdZd�Zejfd�Zd�Zdd�Zddd�d�Z	d	�Z
d
�ZdS)�
MockHTTPClassc�Z�d|_g|_d|_d|_d|_i|_dS)NrF)�level�req_headersr��raise_on_endheaders�sock�_tunnel_headersr�s r,r�zMockHTTPClass.__init__^s5����
������	�#(�� ���	�!����r.c�"�||_||_|Sr�)�hostr�)r&r�r�s   r,r�zMockHTTPClass.__call__fs����	�����r.c��||_dSr�)r�)r&r�s  r,�set_debuglevelzMockHTTPClass.set_debuglevelks
����
�
�
r.Nc�j�||_||_|r	||_dS|j���dSr�)�_tunnel_host�_tunnel_portr��clear)r&r��portr_s    r,�
set_tunnelzMockHTTPClass.set_tunnelnsC�� ��� ����	)�#*�D� � � �� �&�&�(�(�(�(�(r.F)�encode_chunkedc���||_||_|�"|xj|���z
c_|j���|r||_||_|jrt���dSr�)	�method�selectorr�r%�sortr�r�r��OSError)r&r�r`�bodyr_r�s      r,rzMockHTTPClass.requestvs|�������
�������
�
���/�����������	��D�I�,����#�	��)�)�O�	�	r.c�>�tt��idd��S)Nr��OK)r�r�r�s r,�getresponsezMockHTTPClass.getresponse�s����
�
�B��T�:�:�:r.c��dSr�rWr�s r,r�zMockHTTPClass.close�r�r.r�)rUr$rVr�r�r�r�r�r�rr�r�rWr.r,r�r�]s�������"�"�"�&,�%C�����
���)�)�)�)��$������;�;�;�
�
�
�
�
r.r�c�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�MockHandler��c�0�|�|��dSr�)�_define_methods)r&�methodss  r,r�zMockHandler.__init__�s�����W�%�%�%�%�%r.c��|D]K}t|��dkr|\}}n|d}}t|||j��}t|j||���LdS)N�)�lenr�r��setattr�	__class__)r&r�specr!r��meths      r,rzMockHandler._define_methods�sh���	0�	0�D��4�y�y�A�~�~�#���f�f�#�T�f���d�F�D�K�8�8�D��D�N�D�$�/�/�/�/�
	0�	0r.c�&�|jj�||||f��|�dS|dkr|S|dkrtddid��}|S|dkrt	d��S|�d��rx||�d	��d
zd�}	t|��}n#t$rYnwxYwtddid��}|j�	d|d||di��S|d
krtj	�d���J�)N�return self�return responser�r�r��return requestzhttp://blah/r� ��httpr�raiser])�parent�calls�appendr�r�
startswith�rfind�intr6rr3rP)r&�fn_namer�r��kwds�resr�s       r,r�zMockHandler.handle�sB����� � �$���t�!<�=�=�=��>��4�
�}�
$�
$��K�
�(�
(�
(��s�D�"�b�1�1�C��J�
�'�
'�
'��>�*�*�*�
�
�
�w�
'�
'�		0��&�,�,�s�+�+�A�-�.�.�/�D�
��4�y�y�����
�
�
���
�����s�D�"�b�1�1�C��;�$�$�V�T�!�W�c�4��R�H�H�H�
�w�
�
��,�'�'��/�/�/��us�B%�%
B2�1B2c��dSr�rWr�s r,r�zMockHandler.close�r�r.c�,�||_g|j_dSr�)rr)r&rs  r,�
add_parentzMockHandler.add_parent�s����������r.c�F�t|d��sdS|j|jkS)N�
handler_orderT)�hasattrr )r&�others  r,�__lt__zMockHandler.__lt__�s*���u�o�.�.�	��4��!�E�$7�7�7r.N)
rUr$rVr r�rr�r�rr#rWr.r,r�r��su�������M�&�&�&�0�0�0����.
�
�
����8�8�8�8�8r.r�c��g}d}|D]t}Gd�dt��}||��}|xj|z
c_|�|��|dz}|�|��|�|���u|S)a�Create MockHandlers and add them to an OpenerDirector.

    meth_spec: list of lists of tuples and strings defining methods to define
    on handlers.  eg:

    [["http_error", "ftp_open"], ["http_open"]]

    defines methods .http_error() and .ftp_open() on one handler, and
    .http_open() on another.  These methods just record their arguments and
    return None.  Using a tuple instead of a string causes the method to
    perform some action (see MockHandler.handle()), eg:

    [["http_error"], [("http_open", "return request")]]

    defines .http_error() on one handler (which simply returns None), and
    .http_open() on another handler, which returns a Request object.

    rc��eZdZdS)�6add_ordered_mock_handlers.<locals>.MockHandlerSubclassN�rUr$rVrWr.r,�MockHandlerSubclassr&���������Dr.r(r)r�r rr�add_handler)�opener�	meth_spec�handlersr��methsr(rHs       r,�add_ordered_mock_handlersr/�s���&�H�
�E��	�	��	�	�	�	�	�+�	�	�	�
 ���&�&��	���5� ���	���V������	������������1������Or.c�V�t��}|D]}|�|���|Sr�)r	r*)�handler_instancesr+rHs   r,�build_test_openerr2�s8��
�
�
�F�
�������1������Mr.c� �eZdZd�Zd�Zd�ZdS)�MockHTTPHandlerc�J�||_||_|���dSr�)r�r_�reset)r&r�r_s   r,r�zMockHTTPHandler.__init__�s!����	�����
�
�����r.c�"�d|_g|_dS)Nr)�_count�requestsr�s r,r6zMockHTTPHandler.reset�s�������
�
�
r.c���ddl}ddl}|j�|�|����|jdkru|jdz|_tjj|j	}|�
|j��}|j�
d|t��|j	||��S||_|�
d��}t!dd|d|�����S)Nrrr�

r�r�r�)�email�copyr9r�deepcopyr8r�client�	responsesr��message_from_stringr_rrr�rpr��get_full_url)r&rpr<r=r!r�s      r,�	http_openzMockHTTPHandler.http_open�s������������
���T�]�]�3�/�/�0�0�0��;�!����+��/�D�K��;�(���3�D��+�+�D�L�9�9�C��;�$�$���X�Z�Z���D�#�?�?�
?��D�H��+�+�J�7�7�C���T�3��C�4D�4D�4F�4F�G�G�Gr.N�rUr$rVr�r6rCrWr.r,r4r4�sF���������
���H�H�H�H�Hr.r4c��eZdZdd�Zd�ZdS)�MockHTTPSHandlerrc�x�tjj�||���t	��|_dS)N��
debuglevel)r3r�AbstractHTTPHandlerr�r��httpconn)r&rIs  r,r�zMockHTTPSHandler.__init__	s/����*�3�3�D�Z�3�P�P�P�%����
�
�
r.c�8�|�|j|��Sr�)�do_openrK�r&rps  r,�
https_openzMockHTTPSHandler.https_open
s���|�|�D�M�3�/�/�/r.N)r)rUr$rVr�rOrWr.r,rFrFs7������(�(�(�(�0�0�0�0�0r.rFc� �eZdZd�Zd�Zd�ZdS)�MockHTTPHandlerCheckAuthc�"�||_d|_dS�NF)r��has_auth_header)r&r�s  r,r�z!MockHTTPHandlerCheckAuth.__init__s����	�$����r.c��d|_dSrS)rTr�s r,r6zMockHTTPHandlerCheckAuth.resets��$����r.c���|�d��rd|_tjj|j}t
|j|t��d|�����S)N�
AuthorizationTr�)	rgrTrr?r@r�r�r�rB)r&rpr!s   r,rCz"MockHTTPHandlerCheckAuth.http_opensW���>�>�/�*�*�	(�#'�D� ��{�$�T�Y�/���D�I�t�X�Z�Z��S�=M�=M�=O�=O�P�P�Pr.NrDrWr.r,rQrQsF������%�%�%�%�%�%�Q�Q�Q�Q�Qr.rQc��eZdZd�Zd�ZdS)�MockPasswordManagerc�>�||_||_||_||_dSr�)�realmr`�userru)r&r[�urir\rus     r,r�z MockPasswordManager.add_password%s"����
������	� ��
�
�
r.c�:�||_||_|j|jfSr�)�target_realm�
target_urlr\ru)r&r[�authuris   r,r�z&MockPasswordManager.find_user_password+s ��!���!����y�$�-�'�'r.N)rUr$rVr�r�rWr.r,rYrY$s2������!�!�!�(�(�(�(�(r.rYc�8�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�OpenerDirectorTestsc��Gd�dt��}|�tt��j|����dS)Nc��eZdZdS)�<OpenerDirectorTests.test_add_non_handler.<locals>.NonHandlerNr'rWr.r,�
NonHandlerrf4r)r.rg)�objectr5�	TypeErrorr	r*)r&rgs  r,�test_add_non_handlerz(OpenerDirectorTests.test_add_non_handler3si��	�	�	�	�	��	�	�	����)�(�*�*�6�
�
���	F�	F�	F�	F�	Fr.c��ddlm}t��}ddgdgg}t||��|�t
j�����dD]!}|�||j	|dz���"dS)Nr)rP)rMr)�
proxy_openr)�redirect_requestr)�do�proxy�redirectz://example.com/)
�urllib.errorrPr	r/r*r3r�UnknownHandlerr5r�)r&rP�or,�schemes     r,�test_badly_named_methodsz,OpenerDirectorTests.test_badly_named_methods9s���	*�)�)�)�)�)�����
'�)F�G�
0�1��	�	"�!�Y�/�/�/�	�
�
�f�n�3�3�5�5�6�6�6�/�	J�	J�F����h����7H�0H�I�I�I�I�	J�	Jr.c��t��}gd�dgdgdgg}t||��}td��}|�|��}|�||d��|ddf|ddfg}t||j��D];\}}|\}	}
}}|�|	|
f|��|�||f���<dS)N)rC�ftp_open�http_error_302rw�rCrrsrrrC)r	r/rr�r#�zipr)
r&rsr,r-rp�rr�expected�got�handlerr!r�rs
             r,�test_handledz OpenerDirectorTests.test_handledNs������7�7�7�
�L�
)�*�
)�*�	�	�-�Q�	�:�:���+�,�,��
�F�F�3�K�K��	
����H�Q�K�(�(�(��1�+�{�+�h�q�k�;�-G�H�� ����0�0�	+�	+�M�H�c�(+�%�G�T�4�����g�t�_�h�7�7�7����T�C�6�*�*�*�*�	+�	+r.c���t��}g}dgdfdgdffD]T\}}Gd�dt��}||��}||_|�|��|�|���U|�d��|�|jdd|d��|�|jdd|d��dS)	NryrrCrc��eZdZdS)�COpenerDirectorTests.test_handler_order.<locals>.MockHandlerSubclassNr'rWr.r,r(r�ms�������r.r(rsr)r	r�r rr*r�r#r)r&rsr-r.r r(rHs       r,�test_handler_orderz&OpenerDirectorTests.test_handler_orderhs��������'C�&D�c�%J�'2�m�Q�%7�%9�	�	� �E�=�
�
�
�
�
�k�
�
�
�$�#�E�*�*�A�+�A�O��O�O�A����
�M�M�!�����	���$�%�%�%��������A�����4�4�4��������A�����4�4�4�4�4r.c��t��}dgdgg}t||��}td��}|�tjj|j|��|�|j	|dd|fifg��dS)N)rCrryrsrrC)
r	r/rr5r3rrPr�r#r)r&rsr,r-rps     r,�
test_raisezOpenerDirectorTests.test_raisezs�������
#�$�
)�*��	�-�Q�	�:�:���+�,�,�����&�,�/����=�=�=������H�Q�K��s�f�b�#I�"J�K�K�K�K�Kr.c���t��}dgddggd�dgg}t||��}td��}|�|��t	|j��dksJ�|dd|ff|dd|tjd	d
iffg}t||j��D]G\}}|\}}	}
|�	||	f|dd���|�	|
|d���HdS)N)rCz	error 302)�http_error_400rrC))rxr
�http_error_303�
http_errorrxrsrr�.r�)
r	r/rr�rrr�	ALWAYS_EQrzr#)r&rsr,r-rprr|r}r~�method_namer�s           r,�test_http_errorz#OpenerDirectorTests.test_http_error�s.��
����
'�(�
(�+�6�
�
�
�� ��	�-�Q�	�:�:���+�,�,��	���s�����1�7�|�|�q� � � � ��1�+�{�S�F�3��1�+�/���)�3��B�7�9�:��!����0�0�	+�	+�M�H�c�)1�&�G�[�$����g�{�3�S��!��W�=�=�=����T�3�q�6�*�*�*�*�	+�	+r.c��t��}ddgddgg}t||��}td��}|�|��|ddf|ddf|ddf|ddfg}t	|j��D]�\}\}}}	}
|dkrc|�||f||��|�t|	��d��|�|	dt���s|�||f||��|�t|	��d��|�|	dt��|	d�!|�|	dt����dS)	N)�http_requestr)�
http_responser
rsrr�rr�r)
r	r/rr��	enumeraterr#r�assertIsInstancer�)r&rsr,r-rprr�r~r!r�rs           r,�test_processorsz#OpenerDirectorTests.test_processors�s�������
/�
1�
3�
/�
1�
3��	�-�Q�	�:�:���+�,�,��	���s�����a�[�.�)�H�Q�K��+H�
�a�[�/�*�X�a�[�/�,J�L��/8���.@�.@�	A�	A�*�A�*���t�T��1�u�u�� � �'�4��%��(�;�;�;�� � ��T���A�.�.�.��%�%�d�1�g�w�7�7�7�7�� � �'�4��%��(�;�;�;�� � ��T���A�.�.�.��%�%�d�1�g�w�7�7�7���7�&��)�)�$�q�'�<�@�@�@��	A�	Ar.N)
rUr$rVrjrurr�r�r�r�rWr.r,rcrc1s�������F�F�F�J�J�J�*+�+�+�45�5�5�$L�L�L�+�+�+�.!A�!A�!A�!A�!Ar.rcc��	|�d��n"#t$rtjd���wxYwtj�|��}tjdkr|�	d��r
|dd�}|S)Nzutf-8zpath is not encodable to utf8rz///r)
�encode�UnicodeEncodeError�unittest�SkipTestr3rrr r!r)r8�urlpaths  r,�sanepathname2urlr��s���A����G�������A�A�A��� ?�@�@�@�A�����n�)�)�$�/�/�G�	�w�$���7�-�-�e�4�4���!�"�"�+���Ns��7c��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zej e!j"dkd��d���Z#ej e$j%d kd!��d"���Z&d#�Z'd$�Z(d%�Z)d&�Z*d'�Z+d(�Z,d)�Z-d*�Z.d+�Z/d,�Z0d-�Z1d.S)/�HandlerTestsc�v��Gd�d���G�fd�dtjj��}ddl}d}||��}t	��|_dd|jd	d	d
ddgd
df	dd|jdd	d
ddgd
df	dd|jdd	d
ddgd
df	dd|jdd	d
ddgd
df	dddd	d	dddgd	df	dd|jd	d	dgddf	fD�]�\	}}}}}	}
}}}
t|��}d|_|�	|��}|�
|j|��|�
|j|	��|�
|j
tj|����|�
|j|��|�
|j|��|�
|jj|��|�
|jj|
��|���}|�
|�d��|
��|�
t/|d��t1|�������dS)Nc� �eZdZd�Zd�Zd�ZdS)�-HandlerTests.test_ftp.<locals>.MockFTPWrapperc��||_dSr��r��r&r�s  r,r�z6HandlerTests.test_ftp.<locals>.MockFTPWrapper.__init__��
�� ��	�	�	r.c�z�||c|_|_tj|j��t|j��fSr�)�filename�filetyper�r�r�r)r&r�r�s   r,�retrfilez6HandlerTests.test_ftp.<locals>.MockFTPWrapper.retrfile�s1��/7��,��
�t�}��{�4�9�-�-�s�4�9�~�~�=�=r.c��dSr�rWr�s r,r�z3HandlerTests.test_ftp.<locals>.MockFTPWrapper.close�����r.N)rUr$rVr�r�r�rWr.r,�MockFTPWrapperr��sA������
!�
!�
!�
>�
>�
>�
�
�
�
�
r.r�c�.��eZdZd�Zejf�fd�	ZdS)�-HandlerTests.test_ftp.<locals>.NullFTPHandlerc��||_dSr�r�r�s  r,r�z6HandlerTests.test_ftp.<locals>.NullFTPHandler.__init__�r�r.c���||c|_|_||c|_|_||_�|j��|_|jSr�)r\�passwdr�r��dirsr��
ftpwrapper)r&r\r�r�r�r�r�r�s       �r,�connect_ftpz9HandlerTests.test_ftp.<locals>.NullFTPHandler.connect_ftp�sE���)-�v�&��	�4�;�'+�T�$��	�4�9� ��	�"0�.���";�";�����&r.N)rUr$rVr�r�r�r�)r�s�r,�NullFTPHandlerr��sJ�������
!�
!�
!�%+�$B�
'�
'�
'�
'�
'�
'�
'�
'r.r�rzrheum rhaponicumz ftp://localhost/foo/bar/baz.html�	localhostr��Ir}r~zbaz.htmlz	text/htmlz'ftp://parrot@localhost/foo/bar/baz.html�parrotz*ftp://%25parrot@localhost/foo/bar/baz.htmlz%parrotz,ftp://%2542parrot@localhost/foo/bar/baz.htmlz	%42parrotzftp://localhost:80/foo/bar/�P�Dzftp://localhost/baz.gif;type=a�Azbaz.gifz	image/gif�Content-type�Content-length)r3r�
FTPHandler�ftplibr�r�FTP_PORTrr�rwr#r\r�r�r��
gethostbynamer�r�r�r�r�r��getrr)r&r�r�r�rHr`r�r�r\r��type_r�r��mimetyperpr{r_r�s                 @r,�test_ftpzHandlerTests.test_ftp�s����		�		�		�		�		�		�		�		�
	'�
	'�
	'�
	'�
	'�
	'�
	'�V�^�6�
	'�
	'�
	'�	�
�
�
�!���N�4� � ���<�<���0�
�&�/�2�r�3��U�^�Z��
6�7�
�&�/�8�R���U�^�Z��
6�:�
�&�/�9�b�#��U�^�Z��
6�<�
�&�/�;��C��U�^�Z��
6�+�
�"�b�"�c��U�^�R��
'�.�
�&�/�2�r�3�
��K�
)�!O�!	H�!	H�J�C��t�T�6�5�$��(�(�#�,�,�C��C�K��
�
�3���A����Q�V�T�*�*�*����Q�X�v�.�.�.����Q�V�V�%9�$�%?�%?�@�@�@����Q�V�T�*�*�*����Q�V�T�*�*�*����Q�\�2�H�=�=�=����Q�\�2�E�:�:�:��f�f�h�h�G����W�[�[��8�8�(�C�C�C����S��)9�!:�;�;�S��Y�Y�G�G�G�G�C!	H�!	Hr.c	�V	�ddl}tj���}t	��x}|_tj}ttj
�|����}d}d|zd|zdtj
d���|��g}	tj
tj����}n#tj$rd}YnwxYw|r|�d|�|����|D�]�}	t#|d��}
		|
�|��|
���n#|
���wxYw|�t+|	����}	|���}|���}
|���}|���n#|���wxYwtj|��}|j�|jd	�
��}tj|��n#tj|��wxYw|�||��|�|
dd��|�|
d
d��|�|
d|��|�||	�����d|zdddtj
d���dtj���d|��dtj���d|��fD]�}		t#|d��}
	|
�|��|
���n#|
���wxYw|� tj!j"|jt+|	����tj|����#tj|��wxYwtj���}t	��x}|_dD]�\}	}t+|	��}	|�|��|�#|j$|��|�|j%d��n/#tj!j"$r|�&|��YnwxYw|�|j%dk|����dS)Nrs
hello, world
zfile://localhost%sr1zfile://r�r��wbT)�usegmtr�z
text/plainr�r�z
Last-modifiedzfile://localhost:80%szfile:///file_does_not_exist.txtz)file://not-a-local-host.com//dir/file.txtz:80r0z'file://somerandomhost.ontheinternet.com))zfile://ftp.example.com//foo.txtF)z file://ftp.example.com///foo.txtF)zfile://ftp.example.com/foo.txtF)z"file://somehost//foo/something.txtF)z#file://localhost//foo/something.txtF�ftp)'�email.utilsr3r�FileHandlerr�rr�TESTFNr�r r8r9r�r��gethostname�gaierrorrr��writer��	file_openrr=r�r��stat�utils�
formatdate�st_mtime�remover#�getcwdr5rrP�assertIsrp�typerk)r&r<rHrsr�r��towrite�urls�	localaddrr`r@r{r�r_�respurl�stats�modifiedr�rps                   r,�	test_filezHandlerTests.test_files��������N�&�&�(�(��!�|�|�#��A�H��!��"�2�7�?�?�6�#:�#:�;�;��#�� �7�*��'�!�!�#�1�+�>�>�>���H���
	��,�V�-?�-A�-A�B�B�I�I����	�	�	��I�I�I�	�����	>��K�K�K���G�G�<�=�=�=��	+�	+�C��V�T�"�"�A�
"���G�G�G�$�$�$��G�G�I�I�I�I��A�G�G�I�I�I�I�����K�K�����-�-����6�6�8�8�D��f�f�h�h�G��h�h�j�j�G��G�G�I�I�I�I��A�G�G�I�I�I�I���������� �;�1�1�%�.��1�N�N���	�&�!�!�!�!���	�&�!�!�!�!�������T�7�+�+�+����W�^�4�l�C�C�C����W�%5�6��=�=�=����W�_�5�x�@�@�@����W�c�*�*�*�*�
$�g�-�-�7�7�#)�#7��#D�#D�#D�#D�#%�9�;�;�;�;���
8�
8��Y�[�[�[�[�&�&�
"�
�	"�	"�C�

"����&�&����G�G�G�$�$�$��G�G�I�I�I�I��A�G�G�I�I�I�I�����!�!�&�,�"7�"#�+�w�s�|�|�=�=�=��	�&�!�!�!�!���	�&�!�!�!�!�����N�&�&�(�(��!�|�|�#��A�H��	5�	5�H�C���#�,�,�C�
2����C� � � ��
�
�a�e�S�)�)�)�� � ���5�1�1�1�1��	�<�(�
&�
&�
&�� � ��%�%�%�%�%�
&����

���S�X��.��4�4�4�4�	5�	5s~�%B;�;C�C�D/�H�/E�%H�+<F<�'H�<G�8H�H5�
N+�M�0N+�M�;N+�+O�Q�)R�Rc��tj���}t��x}|_d}dD�]w\}}t||ddi��}d|_|�dd��t��}|�	||��}|j
|j|j|j
|j|jdkdf|���}	|	j|	j|�|�
��|��|�|jd	��|�|jd
��|�|j|��|�|jd��|�|jgd���|�|j|����yd
|_|�tjj|j	||��tdd��}|�t:|j|��dg|_dD�]�}td|��}tAddid��}|�|��}
|�7|�!d|j"��|�!d|j"��nB|�|j"dd��|�|j"dd��|�|j"dd	��|�|j"dd��|�dd��|�dd��|�dd��|�dd��|�|��}
|�|j"dd��|�|j"dd��|�|j"dd��|�|j"dd�����dS)Nrs))�GETN)�POSTsblah�Foor~�Spam�eggsr�r�r|rr0))�
Connectionr�)r�r~�r�r�T�badpostr�)r.Nr�r�r��0z!application/x-www-form-urlencoded�Hostr}rc)#r3rrJr�rrr�ror�rMr=r�r�r�r�r�r��__contains__r#r�r�r�r�r�r�r�r5rrPri�do_request_r�r��assertNotIn�unredirected_hdrs)r&rHrsr`r�r�rprr{�hdrs�newreqs           r,�	test_httpzHandlerTests.test_httpls���N�.�.�0�0��!�|�|�#��A�H�#��>�	.�	.�L�F�D��#�t�e�U�^�4�4�C��C�K��'�'���7�7�7� �?�?�D��	�	�$��$�$�A�
�F�F�A�J�J�
�F�F�A�H�H�
�F�A�E�S�L�$�&�&��6�6�8�8�D��H�H�d�'�'����Q�X�X�Z�Z��-�-�-����T�Y�
�6�6�6����T�Z��+�+�+����T�[�&�1�1�1����T�]�C�0�0�0����T�-�@�@�@�
A�
A�
A�
���T�Y��-�-�-�-�$(�� ����&�,�/���D�#�F�F�F��+�I�6�6�����)�Q�]�C�8�8�8�)�)����	C�	C�D��/��6�6�C��S�$��B�/�/�A��]�]�3�'�'�F��|�� � �!1�3�3H�I�I�I�� � ���1F�G�G�G�G�� � ��!6�7G�!H�#�N�N�N�� � ��!6�~�!F�@�B�B�B�
���S�2�6�:�M�J�J�J����S�2�6�:�F�C�C�C�
�'�'�(8�%�@�@�@��'�'���>�>�>��'�'���6�6�6��'�'���6�6�6��]�]�3�'�'�F����S�2�3C�D�e�L�L�L����S�2�>�B�E�J�J�J����S�2�6�:�E�B�B�B����S�2�6�:�E�B�B�B�B�1	C�	Cr.c��tj���}t��x}|_tjdd���}|j}|���|�	tj|��t|d��5}td|i��}|�|��}|�d��}|�|d��|�|�d����ddd��n#1swxYwYt|d��5}td|d	d
i��}|�|��}|�t'|�d����d
��|�|�d����ddd��dS#1swxYwYdS)Nzw+bF)�mode�delete�rbrs�Transfer-encoding�chunkedr��Content-Length�)r3rrJr�r�tempfile�NamedTemporaryFiler!r�r2r �unlinkr�rr�rmr#rkrgr)	r&rHrs�file_obj�	file_pathr@rpr��tes	         r,�test_http_body_filez HandlerTests.test_http_body_file�sJ��
�N�.�.�0�0��!�|�|�#��A�H��.�E�%�H�H�H���M�	�����������	�9�-�-�-�
�)�T�
"�
"�	B�a��/��B�7�7�C��]�]�3�'�'�F��"�"�#6�7�7�B����R��+�+�+����V�.�.�/?�@�@�A�A�A�	B�	B�	B�	B�	B�	B�	B�	B�	B�	B�	B����	B�	B�	B�	B��)�T�
"�
"�	E�a��/��5E�r�4J�K�K�C��]�]�3�'�'�F����S��!2�!2�3C�!D�!D�E�E�r�J�J�J����V�.�.�/B�C�C�D�D�D�		E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E����	E�	E�	E�	E�	E�	Es&�A:D�D�"D�6BG
�
G�Gc��tj���}t��x}|_tj��}td|i��}|�|��}|�	|�
d��d��|�|�d����ddi}td||��}|�|��}|�	t|�
d����d��|�|�d����|���dS)Nrsr�r�r�r�r�)r3rrJr�rr��BytesIOrr�r#rmrkrgrr�)r&rHrsr�rpr�r_s       r,�test_http_body_fileobjz#HandlerTests.test_http_body_fileobj�s0��
�N�.�.�0�0��!�|�|�#��A�H��:�<�<���+�X�r�:�:�����s�#�#������*�*�+>�?�?��K�K�K�����*�*�+;�<�<�=�=�=�#�R�(���+�X�w�?�?�����s�#�#������V�.�.�/?�@�@�A�A�2�F�F�F�����*�*�+>�?�?�@�@�@��������r.c	�x�tj���}t��x}|_t
jddg}iddifD]�}tj|tj	���5}td|j|��}|�|��}|sS|�
|�d��d��|�
|�d��d	��n6|�
t|�d����d��ddd��n#1swxYwY��dS)
Nz-c�passr�r�)�stdoutrsr�r�r�)r3rrJr�r�sys�
executable�
subprocess�Popen�PIPErrr�r#rmr)r&rHrs�cmdr_�procrpr�s        r,�test_http_body_pipez HandlerTests.test_http_body_pipe�s}��
�N�.�.�0�0��!�|�|�#��A�H��~�t�W�-���,�b�1�1�
	)�
	)�G��!�#�j�o�>�>�>�	
)�$��3�T�[�'�J�J�����s�+�+���)��$�$�V�%6�%6�7G�%H�%H�$�O�O�O��$�$�V�%6�%6�7J�%K�%K�%.�0�0�0�0��$�$�S��):�):�;K�)L�)L�%M�%M�%'�)�)�)�	
)�	
)�	
)�	
)�	
)�	
)�	
)�	
)�	
)�	
)�	
)����	
)�	
)�	
)�	
)��
	)�
	)s�+B7D.�.D2	�5D2	c��tj���}t��x}|_d�}iddifD]�}td|��|��}|�|��}|sS|�|�d��d��|�|�d��d����|�t|�d����d����dS)Nc3�K�dV�dS)NsonerWrWr.r,�
iterable_bodyz;HandlerTests.test_http_body_iterable.<locals>.iterable_body�s�����L�L�L�L�Lr.r��rsr�r�r�)
r3rrJr�rrr�r#rmr)r&rHrsrr_rpr�s       r,�test_http_body_iterablez$HandlerTests.test_http_body_iterable�s��
�N�.�.�0�0��!�|�|�#��A�H�	�	�	��,�b�1�1�	O�	O�G��/�����'�J�J�C��]�]�3�'�'�F��
O�� � ��!2�!2�3C�!D�!D�d�K�K�K�� � ��!2�!2�3F�!G�!G�!*�,�,�,�,�� � ��V�%6�%6�7G�%H�%H�!I�!I�2�N�N�N�N�	O�	Or.c�P�tj���}t��|_|�t
dd����}|�|�d��d��|�	|�
d����dS)NrsrWr�r�r�)r3rrJr�rr�rr#rmrkrg)r&rHrps   r,�test_http_body_empty_seqz%HandlerTests.test_http_body_empty_seqs����N�.�.�0�0���<�<����m�m�G�$9�2�>�>�?�?��������(;�<�<�i�H�H�H�������(8�9�9�:�:�:�:�:r.c�d�tj���}t��x}|_tjdgd���}iddifD]^}t
d||��}|�|��}|�t|�
d����d���_dS)Nr�)rr��r��rsr�)r3rrJr�r�arrayrr�r#rrm)r&rHrs�iterable_arrayr_rpr�s       r,�test_http_body_arrayz!HandlerTests.test_http_body_arrays���
�N�.�.�0�0��!�|�|�#��A�H���S����3�3���,�b�1�1�	J�	J�G��/���I�I�C��]�]�3�'�'�F����S��!2�!2�3C�!D�!D�E�E�b�I�I�I�I�	J�	Jr.c���t��}td���}|�|��|�d��|�|jd��dS)NrrHzhttps://www.example.com)r	rFr*r�r#�_debuglevel)r&rsrHs   r,�test_http_handler_debuglevelz)HandlerTests.test_http_handler_debuglevels`��������*�*�*��	�
�
�a����	���(�)�)�)�������*�*�*�*�*r.c��tj���}t��|_d}gd�}|D]�}t||��}|�|��}|�|jdd��|�	dd��|�|��}|�|jdd����dS)Nr.)z#http://example.com/foo/bar/baz.htmlz$http://example.com//foo/bar/baz.htmlz$http://example.com/foo//bar/baz.htmlz$http://example.com/foo/bar//baz.htmlr�r|zsomeproxy:3128)
r3rrJr�rrr�r#r��	set_proxy)r&rHr��ds_urls�ds_url�ds_req�	np_ds_req�p_ds_reqs        r,�test_http_doubleslashz"HandlerTests.test_http_doubleslash$s���
�N�.�.�0�0���<�<����������
	P�
	P�F��V�T�*�*�F��
�
�f�-�-�I����Y�8��@�-�P�P�P�
���-�t�4�4�4��}�}�V�,�,�H����X�7��?��O�O�O�O�
	P�
	Pr.c�t�gd�}td��}|D]�}||_t|��}|�|���|��|�|jpd|j��|�t|�����j|j����dS)N)zhttp://example.com?foo=bar#bazz)http://example.com?foo=bar&spam=eggs#bashr[r[r�)r�full_urlrr#rB�fragment�query)r&r�r{r`�parseds     r,�test_full_url_setterz!HandlerTests.test_full_url_setter?s���
�
�
��
�(�)�)���	M�	M�C��A�J��c�]�]�F����Q�^�^�-�-�s�3�3�3�
���Q�Z�-�2�v��?�?�?����X�a�n�n�&6�&6�7�7�=�v�|�L�L�L�L�	M�	Mr.c���td��}|`|�|j��|�|j��|�|jd��dS)N�http://www.example.comr�)rr'rlr(r#r�)r&r{s  r,�test_full_url_deleterz"HandlerTests.test_full_url_deleterVs_���,�-�-��
�J����!�*�%�%�%����!�*�%�%�%������R�(�(�(�(�(r.c���tj���}t��|_d}t|��}|�|��}|�|jd��|�|j	d��d}t|��}|�|��}|�|jd��|�|j	d��dS)Nzhttp://www.python.org?getspam�www.python.orgz	/?getspam�http://www.python.orgr�)
r3rrJr�rrr�r#r�r�)r&rH�	weird_urlrpr��url_without_paths      r,�test_fixpath_in_weirdurlsz&HandlerTests.test_fixpath_in_weirdurls]s���
�N�.�.�0�0���<�<���3�	��i� � �����s�#�#�������&6�7�7�7������+�6�6�6�2���&�'�'�����s�#�#�������&6�7�7�7������"�-�-�-�-�-r.c���tj���}t��x}|_d}t|��}t
ddid|��}|�||��}|�||��|�	t|d����t
ddid|��}|�||��}|�||��|�	t|d����t
dd	id|��}|�||��}|�||��|�	t|d����t
d
did|��}|�|�||����|�|j
d��|�|j||d
dif��dS)
Nrsr�r�r�r����Accepted��zPartial contenti�zBad gatewayr)r3r�HTTPErrorProcessorr�rrr�r�r�rkr!rlr#r�r�)r&rHrsr`rpr{�newrs       r,�test_errorszHandlerTests.test_errorsps����N�-�-�/�/��!�|�|�#��A�H�#���c�l�l����d�B��C�0�0�����s�A�&�&���
�
�a����������G�,�,�-�-�-���j�"�b�#�6�6�����s�A�&�&���
�
�a����������G�,�,�-�-�-���/��R��=�=�����s�A�&�&���
�
�a����������G�,�,�-�-�-���m�R��S�9�9�����!�/�/�#�q�1�1�2�2�2������&�)�)�)������#�q�#�}�b�!A�B�B�B�B�Br.c��t��}tj�|��}t	��|_t
d��}tddid��}|�|��}|�	|j
|��|�	|j
|��|�|jd��|�
|j��|�||��}|�	|j|��|�	|j|��|�	||��dS)Nrsr�r�r�r|)r�r3r�HTTPCookieProcessorr�rrr�r�r�r�r#�origin_req_hostrk�unverifiabler�r�r�)r&�cjrHrpr{r�r:s       r,�test_cookieszHandlerTests.test_cookies�s��
�_�_���N�.�.�r�2�2���<�<����+�,�,����d�B��+�+������$�$���
�
�b�j�#�&�&�&��
�
�b�j�&�)�)�)�����,�m�<�<�<�����)�*�*�*����s�A�&�&���
�
�b�i��%�%�%��
�
�b�g�q�!�!�!��
�
�a������r.c�>�d}d}tj���}t��x}|_dD�]@}dD�]9}t|d|z��}t
||��}tj|_	|�
dd��|�0|�
dtt|������|�
d	d
��	||t��|dtd|i����nE#tjj$r.|�|d
��|�|��YnwxYw|�|j���|��	|�|j���d��n/#t0$r"|�|jj��YnwxYwd�|jjD��}	|�d|	��|�d|	��|�|jjdd��|�d	|jj��|�d	|jj����;��Bt
|��}tj|_	|fd�}
t
|d���}d}tj|_			|
||d��|dz}�#tjj$r-|�|tjjj��YnwxYwt
|d���}d}tj|_			|
||d|z��|dz}�#tjj$r.|�|tjjj��YdSwxYw)N�http://example.com/a.htmlzhttp://example.com/b.html)i-r�i/�3�4)Nz
blah
blah
z
http_error_%s�Nonsensezviking=withholdr�r�r��Blah�location)rDrEr�c�6�g|]}|�����SrW)�lower)�.0�xs  r,�
<listcomp>z.HandlerTests.test_redirect.<locals>.<listcomp>�s ��<�<�<��1�7�7�9�9�<�<�<r.zcontent-lengthzcontent-typec
�n�|�|t��ddtd|i����dS)Nr�rGrH)rxr�r�)rHrpr`s   r,rpz,HandlerTests.test_redirect.<locals>.redirect�s@��
���S�(�*�*�c�6�(�*�c�):�;�;�
=�
=�
=�
=�
=r.r|)r>rrrszhttp://example.com/%d) r3r�HTTPRedirectHandlerr�r�getattrrr�r�r�rirRrror�r�r�	HTTPErrorrQ�assertIsNotNoner#rprB�
get_method�AttributeErrorrkr�r_r�r��max_repeats�max_redirections)r&�from_url�to_urlrHrsr�r�r�rpr_rpr�s            r,�
test_redirectzHandlerTests.test_redirect�s��.��,���N�.�.�0�0��!�|�|�#��A�H�,�	B�	B�D�,�
B�
B�� ��O�d�$:�;�;���h��-�-��$�<������z�+<�=�=�=��#��N�N�#3�S��T���^�^�D�D�D��+�+�F�F�;�;�;�/��F�3��
�
�D�&�&�
�F�';�<�<�>�>�>�>���|�-�/�/�/��M�M�$�
�3�3�3��(�(��.�.�.�.�.�/����� � ���!3�!3�!5�!5�v�>�>�>�1��$�$�Q�U�%5�%5�%7�%7��?�?�?�?��%�1�1�1��$�$�Q�U�Z�0�0�0�0�0�1����
=�<�a�e�m�<�<�<��� � �!1�7�;�;�;�� � ���9�9�9�� � ����z�!:�!2�4�4�4�� � �����7�7�7�� � ����)@�A�A�A�A�=
B�B�h�����4���!'�	=�	=�	=�	=��h�
�>�>�>�����4���	T�
"����C�!6�7�7�7���	��
"���|�%�	T�	T�	T����U�F�N�$F�$R�S�S�S�S�S�	T����
�h�
�>�>�>�����4���	R�
"����C�!8�5�!@�A�A�A���	��
"���|�%�	R�	R�	R����U�#�^�?�P�
R�
R�
R�
R�
R�
R�	R���sH�*D�?E�E�3-F!�!)G
�G
�K�>L�L�M�>N�Nc
�N�d}gd�}gd�}d}tj���}t��x}|_t|��}tj|_|D]T}|dz|z}	|�	tj
j|j|t��ddtd|	i�����U|D]k}|dz|z}
|�|t��dd	td|
i����|�|j���|
���ldS)
NrC)r�httpsr�)�file�imap�ldapzexample.com/b.htmlz://r�zSecurity LoopholerH�That's fine)r3rrOr�rrr�r�r�r5rrQrxr�r�r#rprB)r&rW�
valid_schemes�invalid_schemes�schemeless_urlrHrsrprt�invalid_url�	valid_urls           r,�test_invalid_redirectz"HandlerTests.test_invalid_redirect�sD��.��.�.�.�
�0�0�0��-���N�.�.�0�0��!�|�|�#��A�H��h�����4���%�	<�	<�F� �5�.�>�9�K����f�l�4�a�6F�����S�*=���[� 9�:�:�
<�
<�
<�
<�$�	>�	>�F�����7�I�
���S�(�*�*�c�=��Z��3�4�4�
6�
6�
6����Q�U�/�/�1�1�9�=�=�=�=�		>�	>r.c
��d}d}tj���}t��x}|_t|��}tj|_tj	�
||��}|�|t��ddtd|i����|�|j���|��dS)NrCz/b.htmlr�r_rH)r3rrOr�rrr�r�r�r�urljoinrxr�r�r#rprB)r&rW�relative_urlrHrsrprds       r,�test_relative_redirectz#HandlerTests.test_relative_redirect�s���.�� ���N�.�.�0�0��!�|�|�#��A�H��h�����4����L�(�(��,�?�?�	�	����h�j�j�#�}���Y�/�0�0�	2�	2�	2������+�+�-�-�y�9�9�9�9�9r.c���ddlm}ddlm}|��}||dd��t	dd��}t
j���}t
j���}t
j�	|��}t||||��}|�d��|�|j
�d����dS)	Nr)�	CookieJar)�interact_netscapezhttp://www.example.com/z	spam=eggsr�z%Location: http://www.cracker.com/

�Cookie)�http.cookiejarrk�test.test_http_cookiejarrlr4r3r�HTTPDefaultErrorHandlerrOr=r2r�rkrprg)	r&rkrlr@�hh�hdeh�hrh�cprss	         r,�test_cookie_redirectz!HandlerTests.test_cookie_redirects���,�,�,�,�,�,�>�>�>�>�>�>�
�Y�[�[����"�7��E�E�E�
�S�"M�
N�
N���~�5�5�7�7���n�0�0�2�2��
�^�
/�
/��
3�
3���b�$��R�0�0��	���(�)�)�)������*�*�8�4�4�5�5�5�5�5r.c�h�d}tdd|z��}tj���}tj���}t|||��}|�d��}|�|���|�	����dS)Nz(http://www.example.com/index.html#OK

r�z
Location: r-)
r4r3rrprOr2r�r#r��strip)r&�redirected_urlrqrrrsrsr�s       r,�test_redirect_fragmentz#HandlerTests.test_redirect_fragments���G��
�S�,��"?�
@�
@���~�5�5�7�7���n�0�0�2�2���b�$��,�,��
�V�V�,�
-�
-����������n�&:�&:�&<�&<�=�=�=�=�=r.c��������tjj��tjj�d}tj|��tj_��ttjd���td������fd�}|tjj_tj�d��}��|�
��d��dS)Ns(HTTP/1.1 302 Found
Location: ?query

�HTTPConnection)z/pathz/path?queryc�����|t������j|||g|�Ri|��d|j_dS)NsHTTP/1.1 200 OK

Hello!)r#�nextrr�fakedata)�connr�r`�pos�kw�
real_classr&r�s     ���r,rz3HandlerTests.test_redirect_no_path.<locals>.request*sV������S�$�t�*�*�-�-�-��J��t�V�S�=�3�=�=�=�"�=�=�=�&F�D�N�#�#�#r.zhttp://python.org/pathzhttp://python.org/path?query)r2r3rr4rr?r{r�fakehttpr�iterr7r#r�)r&�	response1rr�r�r�s`   @@r,�test_redirect_no_pathz"HandlerTests.test_redirect_no_paths������	
�����1�2�2�2��[�/�
�E�	�%0�%9�)�%D�%D���"�������.>�
�K�K�K��,�-�-��	G�	G�	G�	G�	G�	G�	G�
.5���"�*�
�^�
#�
#�$<�
=�
=����������&D�E�E�E�E�Er.c��Gd�dtjj��}|��}tj�|��}d}|D]�\}}|�t|����5t
jd|zdz��|_|�	d��}d|zdz}|j
}	|�|	�|��t|	����ddd��n#1swxYwY��dS)	Nc��eZdZd�ZdS)�4HandlerTests.test_redirect_encoding.<locals>.Handlerc��|�|j|��}|jj|_t	jd��|_|S)Ns)HTTP/1.1 200 OK
Content-Length: 3

123)rM�
connection�buf�last_bufrr�)r&rp�results   r,rCz>HandlerTests.test_redirect_encoding.<locals>.Handler.http_open7sC�����d�o�s�;�;�� $�� 3��
�"-�"6��#�#����
r.N)rUr$rVrCrWr.r,�Handlerr�6s#������

�

�

�

�

r.r�))s/på-dansk/s/p%C3%A5-dansk/)�/spaced%20path/r�)s
/spaced path/r�)s/?på-dansks/?p%C3%A5-dansks!HTTP/1.1 302 Redirect
Location: s

rssGET � )
r3r�HTTPHandler�build_opener�subTest�reprrr�r�r�r�rfr)
r&r�r~r+rJrHr�rr|rs
          r,�test_redirect_encodingz#HandlerTests.test_redirect_encoding3s|��	�	�	�	�	�f�n�0�	�	�	��'�)�)����,�,�W�5�5��
��#(�
	M�
	M��X�v����d�8�n�n�-�-�	
M�	
M�%0�%9�"�$,�-�0��&�&��"�
"�;�;�'<�=�=��"�V�+�d�2��!�*������ 2� 2�8� <� <�d�7�m�m�L�L�L�	
M�	
M�	
M�	
M�	
M�	
M�	
M�	
M�	
M�	
M�	
M����	
M�	
M�	
M�	
M��
	M�
	Ms�2A:C8�8C<	�?C<	c��d}t|���t|���fD]�}t��}tj�|��}|�|��dgg}t
||��}td��}|�|j	d��|�
|��|�|j	|��|�|ddfgd	�|jD������dS)
N�proxy.example.com:3128�r)�HTTP)rCr
zhttp://acme.example.com/zacme.example.comrrCc�"�g|]}|dd���
S�rrrW�rK�tups  r,rMz+HandlerTests.test_proxy.<locals>.<listcomp>fs ��:�:�:�3�c�!�A�#�h�:�:�:r.)�dictr	r3r�ProxyHandlerr*r/rr#r�r�r)r&r(ryrs�phr,r-rps        r,�
test_proxyzHandlerTests.test_proxyVs��$���1����t��|�|�|�+�	<�	<�A�� � �A���,�,�Q�/�/�B�
�M�M�"����1�2��I�1��I�>�>�H��4�5�5�C����S�X�'9�:�:�:�
�F�F�3�K�K�K����S�X�q�)�)�)����x��{�K�8�9�:�:�!�'�:�:�:�
<�
<�
<�
<�	<�	<r.c�F�dtjd<t��}tj�t
d�����}|�|��td��}|�	|j
d��|�|��|�	|j
d��td��}|�	|j
d��|�|��|�	|j
d��tjd=dS)	Nz
python.org�no_proxy�proxy.example.comr�zhttp://www.perl.org/�www.perl.orgr1r0�r �environr	r3rr�r�r*rr#r�r��r&rsr�rps    r,�test_proxy_no_proxyz HandlerTests.test_proxy_no_proxyhs���!-��
�:������
�^�
(�
(��3F�)G�)G�)G�
H�
H��	�
�
�b�����,�-�-�������>�2�2�2�	���s���������#6�7�7�7��-�.�.�������#3�4�4�4�	���s���������#3�4�4�4��J�z�"�"�"r.c��dtjd<t��}tj�t
d�����}|�|��td��}|�	|j
d��|�|��|�	|j
d��tjd=dS)N�*r�r�r�r1r0r�r�s    r,�test_proxy_no_proxy_allz$HandlerTests.test_proxy_no_proxy_allws���!$��
�:������
�^�
(�
(��3F�)G�)G�)G�
H�
H��	�
�
�b�����-�.�.�������#3�4�4�4�	���s���������#3�4�4�4��J�z�"�"�"r.c���t��}tj�t	d�����}|�|��dgg}t
||��}td��}|�|j	d��|�
|��|�|j	d��|�|ddfgd�|jD����dS)	Nr��r[)rOr
�https://www.example.com/�www.example.comrrOc�"�g|]}|dd���
Sr�rWr�s  r,rMz1HandlerTests.test_proxy_https.<locals>.<listcomp>�s ��6�6�6�s�#�a��c�(�6�6�6r.)r	r3rr�r�r*r/rr#r�r�r)r&rsr�r,r-rps      r,�test_proxy_httpszHandlerTests.test_proxy_https�s�������
�^�
(�
(��4L�)M�)M�)M�
N�
N��	�
�
�b����
.�/�
�	�-�Q�	�:�:���0�1�1�������#4�5�5�5�	���s���������#;�<�<�<����8�A�;��5�6�6�6�a�g�6�6�6�	8�	8�	8�	8�	8r.c�2�t��}tj�t	d�����}|�|��t
��}|�|��td��}|�dd��|�dd��|�	|j
d��|�|j��|�
|��|�d	|jj��|�d
|jj��|�|j��|�	|j
d��|�	|�d��d��dS)Nr�r�r��Proxy-Authorization�FooBar�
User-Agent�Grailr�)r�r�)r�r��Proxy-authorization)r	r3rr�r�r*rFrrir#r�rlr�r�r�rKr�rQrRrm)r&rsr��
https_handlerrps     r,�$test_proxy_https_proxy_authorizationz1HandlerTests.test_proxy_https_proxy_authorization�st������
�^�
(�
(��4L�)M�)M�)M�
N�
N��	�
�
�b����(�*�*�
�	�
�
�m�$�$�$��0�1�1�����,�h�7�7�7����|�W�-�-�-������#4�5�5�5����#�*�+�+�+�	���s����	
���:�&�/�;�	=�	=�	=��
�
�-�#�,�8�	:�	:�	:����S�-�.�.�.������#;�<�<�<�������(=�>�>��I�I�I�I�Ir.rzonly relevant for Windowsc��d}t}dD]%}|�|||��d|z���&dD]%}|�|||��d|z���&d}|�|d|��d|z��|�|d|��d|z��d	D]%}|�|||��d
|z���&dS)Nz*www.example.com;*.example.net; 192.168.0.1)r�zwww.example.netz192.168.0.1z expected bypass of %s to be true)r|zwww.example.org�example.netz192.168.0.2�!expected bypass of %s to be Falsezexample.com; <local>r|r�)�testr�z.expect <local> to bypass intranet address '%s')r
rfrk)r&�proxy_override�proxy_bypassr�s    r,�test_winreg_proxy_bypassz%HandlerTests.test_winreg_proxy_bypass�sP��E��4��I�	G�	G�D��O�O�L�L��~�>�>�>��E�
G�
G�
G�
G�$�	I�	I�D����\�\�$��?�?�@�4�G�
I�
I�
I�
I�0�������]�N�C�C�:�T�A�	C�	C�	C������m�^�D�D�<�t�C�	E�	E�	E�)�	$�	$�D��O�O�L�L��~�>�>�L�"�#�
$�
$�
$�
$�	$�	$r.�darwinzonly relevant for OSXc���dgd�d�}dD])}|�t||��d|z���*dD])}|�t||��d|z���*dgd�}|�td	|����dd
dgd�}d}|�t||��d|z��d
}|�t||��d|z��dS)NF)�foo.barz	*.bar.com�	127.0.0.1z10.10z10.0/16)�exclude_simple�
exceptions)r�zwww.bar.comr�z	10.10.0.1z10.0.0.1z expected bypass of %s to be True)zabc.foo.barzbar.comz	127.0.0.2z	10.11.0.1�notinbypassr�Tr�z10.0.0.0/40z172.19.10.0/24z172.19.10.5z10.0.1.5)rfrrk)r&�bypassr�s   r,�test_osx_proxy_bypassz"HandlerTests.test_osx_proxy_bypass�sn��$�&�&�&�
�
��!�	G�	G�D��O�O�8��v�F�F�>��E�
G�
G�
G�
G��	I�	I�D����9�$��G�G�@�4�G�
I�
I�
I�
I�%)��;�;�����4�V�V�D�D�E�E�E�$�)�+;�=�
�
�������4�T�6�B�B�:�T�A�	C�	C�	C������5�d�F�C�C�;�d�B�	D�	D�	D�	D�	Dr.c��|�||���5t��}t��}tj�|��}d�|��dz}td|��}|�|��|�|��|�	||d|||dd��ddd��dS#1swxYwYdS)N)r[r_z
r;�rW�!http://acme.example.com/protected)
r�r	rYr3rr
�joinr4r*�_test_basic_auth)r&r_r[r+�password_manager�auth_handlerr��http_handlers        r,�check_basic_authzHandlerTests.check_basic_auth�s9��
�\�\��w�\�
7�
7�	G�	G�#�%�%�F�2�4�4��!�>�>�>�?O�P�P�L��;�;�w�'�'�*�4�D�*�3��5�5�L����|�,�,�,����|�,�,�,��!�!�&�,��"'��7G�"E�"E�
G�
G�
G�	G�	G�	G�	G�	G�	G�	G�	G�	G�	G�	G�	G����	G�	G�	G�	G�	G�	Gs�B*C�C�Cc
���d}d}d|�d�}d|�d�}d}d|�d�}d|�d�d|�d�d|�d	�|�d
|��|�d
|��|�d
|��|�d
|��|�d
|��fD]}d|��g}|�||���tjdtf��5d
|��g}|�||��ddd��n#1swxYwY||g||g||gfD]$}	d�|	D��}|�||���%dS)Nzrealm2@example.comz
Basic realm="�"zOtherscheme xxxzDigest realm="zn", qop="auth, auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"z
Basic realm='�'z", charset="UTF-8"z, �WWW-Authenticate: zBasic Auth Realm was unquotedzWWW-Authenticate: Basic realm=c��g|]}d|����S)r�rW)rK�	challenges  r,rMz0HandlerTests.test_basic_auth.<locals>.<listcomp>s0��4�4�4�$�8�I�7�7�4�4�4r.)r�r�check_warnings�UserWarning)
r&r[�realm2�basic�basic2�other_no_realm�digest�	realm_strr_�
challengess
          r,�test_basic_authzHandlerTests.test_basic_auth�s��$��%��(��(�(�(��*��*�*�*��*��?�6�?�?�?��
%�E�$�$�$�$�E�$�$�$�
6�E�5�5�5�� � �� � ��(�(��(�(��(�(��(�(�� � �� � �� � �� � �
�	2�	2�I�8�I�7�7�8�G��!�!�'�5�1�1�1�1��
+�-L�%0�-2�3�3�	2�	2�?��?�?�@�G��!�!�'�5�1�1�1�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2����	2�	2�	2�	2��V��
�V��
�U�O�
�	2�	2�J�
4�4�(2�4�4�4�G��!�!�'�5�1�1�1�1�	2�	2s�B+�+B/�2B/c
��t��}tj�t	d�����}|�|��t
��}tj�|��}d}tdd|z��}|�|��|�|��|�	||d|||dd��dS)Nr�r��
ACME Networksi�z(Proxy-Authenticate: Basic realm="%s"

r�z&http://acme.example.com:3128/protected)
r	r3rr�r�r*rY�ProxyBasicAuthHandlerr4r�)r&r+r�r�r�r[r�s       r,�test_proxy_basic_authz"HandlerTests.test_proxy_basic_auths����!�!��
�^�
(�
(��3K�)L�)L�)L�
M�
M�����2����.�0�0���~�;�;�<L�M�M����&��?�%�G�I�I�����<�(�(�(����<�(�(�(����f�l�4I�#�\�3C�F�6�	 �	 �	 �	 �	 r.c
��Gd�dt��}Gd�dtjj��}Gd�dtjj��}|��}t��}||��}||��}d}t
dd	|z��}	|�|��|�|��|�|	��|�||d
||	|dd��|�	|j
dd
gdz��dS)Nc��eZdZd�Zd�ZdS)�QHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirectorc�<�tj|��g|_dSr�)r	r��recordedr�s r,r�zZHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.__init__9s���'��-�-�-� "��
�
�
r.c�:�|j�|��dSr�)r�r)r&r�s  r,�recordzXHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.record=s���
�$�$�T�*�*�*�*�*r.N)rUr$rVr�r�rWr.r,�RecordingOpenerDirectorr�8s2������
#�
#�
#�
+�
+�
+�
+�
+r.r�c��eZdZd�ZdS)�OHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandlerc�x�|j�d��tjjj|g|�Ri|��dS)Nr�)rr�r3r�HTTPDigestAuthHandler�http_error_401�r&r�rs   r,r�z^HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandler.http_error_401Asa����"�"�8�,�,�,���4�C�D�L�>B�L�L�L�FJ�L�L�L�L�Lr.N�rUr$rVr�rWr.r,�TestDigestAuthHandlerr�@s(������
L�
L�
L�
L�
Lr.r�c��eZdZd�ZdS)�NHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandlerc�x�|j�d��tjjj|g|�Ri|��dS)Nr�)rr�r3rr
r�r�s   r,r�z]HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandler.http_error_401Gsa����"�"�7�+�+�+���3�B�4�K�=A�K�K�K�EI�K�K�K�K�Kr.Nr�rWr.r,�TestBasicAuthHandlerr�Fs(������
K�
K�
K�
K�
Kr.r�r�r��&WWW-Authenticate: Basic realm="%s"

rWr�r�r�r)r	r3rr�r
rYr4r*r�r#r�)
r&r�r�r�r+r��digest_handler�
basic_handlerr[r�s
          r,�#test_basic_and_digest_auth_handlersz0HandlerTests.test_basic_and_digest_auth_handlers/s���	+�	+�	+�	+�	+�n�	+�	+�	+�	L�	L�	L�	L�	L�F�N�$H�	L�	L�	L�	K�	K�	K�	K�	K�6�>�#F�	K�	K�	K�)�(�*�*��.�0�0��.�.�/?�@�@��,�,�-=�>�>�
���&��=��E�G�G�����=�)�)�)����>�*�*�*����<�(�(�(�	
���f�m�_�#�\�3C�A�A�	 �	 �	 �	
�����8�W�*=�a�*?�@�@�@�@�@r.c��t��}tj�d��}t	dd��}|�|��|�|��|�t|jd��dS)Nr�zWWW-Authenticate: Kerberos

r-)	r	r3rr�r4r*r5r6r�)r&r+�digest_auth_handlerr�s    r,�$test_unsupported_auth_digest_handlerz1HandlerTests.test_unsupported_auth_digest_handleras����!�!��$�n�B�B�4�H�H��&��5�7�7�����.�/�/�/����<�(�(�(����*�f�k�3K�L�L�L�L�Lr.c��t��}tj�d��}t	dd��}|�|��|�|��|�t|jd��dS)Nr�zWWW-Authenticate: NTLM

r-)	r	r3rr
r4r*r5r6r�)r&r+�basic_auth_handlerr�s    r,�#test_unsupported_auth_basic_handlerz0HandlerTests.test_unsupported_auth_basic_handlerks����!�!��#�^�@�@��F�F��&��1�3�3�����-�.�.�.����<�(�(�(����*�f�k�3K�L�L�L�L�Lr.c	���ddl}	d\}
}|�|||
|��|�||j��|�||j��|�|
|j��|�||j��|�|��|�|j|��|�|j	|��|�t|j��d��|�|jd�
|����t|
�d|��d��}d|	�|��������z}
|�|jd�|��|
��|�|jdj||
��dx|_|_|���|�|��|�t|j��d��|�|jd�
|����dS)Nr��wile�coyoter�:�asciizBasic r)�base64r�r#r[r`r\rur�r_r`rr9rkrg�bytes�encodebytesrw�decodermr�r6)r&r+r��auth_headerr[r�r��request_url�
protected_urlr
r\ru�userpass�auth_hdr_values              r,r�zHandlerTests._test_basic_authusf��	�
�
�
�)���h�	�!�!�%��d�H�E�E�E����� 0� 6�7�7�7�����&6�&:�;�;�;�����/�4�5�5�5�����#3�#<�=�=�=����K� � � �	
���)�6��>�>�>����)�4�m�D�D�D�	
����\�2�3�3�Q�7�7�7�����.�q�1�<�<�[�I�I�J�J�J��D�D�D�(�(�3�W�=�=��"����x�(�(�.�.�0�0�7�7�9�9�:������.�q�1�<�<�[�I�I�'�	)�	)�	)�����.�q�1�C�K�P�'�	)�	)�	)�=A�@��� 0� 9����������K� � � �����\�2�3�3�Q�7�7�7�����.�q�1�<�<�[�I�I�J�J�J�J�Jr.c�j�d\}}d}td��}t��}t|��}|�d|||d���|�|�|����|�|�|dz����|�|�|dz����t��}|�|��|�|��|�	|��|�|j
��dS)Nrr�r�T)�is_authenticatedz/nested�plain)rQrr
r�rfrrkr	r*r�rT)r&r\rurr��pwd_manager�auth_prior_handlerr+s        r,�test_basic_prior_auth_auto_sendz,HandlerTests.test_basic_prior_auth_auto_send�s4��*���h�9��/��4�4��2�4�4��1�+�>�>���'�'��+�t�X��	(�	F�	F�	F�	
����4�4�[�A�A�B�B�B�����4�4�[�9�5L�M�M�N�N�N�����5�5�k�G�6K�L�L�M�M�M��!�!�����-�.�.�.����<�(�(�(����K� � � �	
����4�5�5�5�5�5r.c�
�d\}}d}d}t��}t|��}|�||||��|�|��}|�|��t��}|�|��tdddz��}	|�|	��|�|��|�|��}|�	|��td��}	|�|	j��t��}|�|��|�|	��|�|��|�	|	j��dS)Nrr��ACMEr�r�r�)rr
r�rrkr	r*r4r�rfrQrT)
r&r\rurr[rr�is_authr+r�s
          r,�.test_basic_prior_auth_send_after_first_successz;HandlerTests.test_basic_prior_auth_send_after_first_success�s���*���h�9����2�4�4��1�+�>�>���'�'��{�D�(�K�K�K��.�.�{�;�;������!�!�!��!�!�����-�.�.�.�&��=��D�F�F�����<�(�(�(����K� � � ��.�.�{�;�;������ � � �/��4�4������5�6�6�6��!�!�����-�.�.�.����<�(�(�(�	���K� � � �	
����4�5�5�5�5�5r.c���dD]�\}}d�|��}tj|���|z��}tj���}td��}d|_|�	||��5}|�
��ddd��n#1swxYwY|�|jj
d�|������dS)z=Test the connection is cleaned up when the response is closed))zConnection: close�data)zTransfer-Encoding: chunkeds4
data
0

)zContent-Length: 4r!zHTTP/1.1 200 OK
{}

�
http://dummy/NzConnection not closed with {!r})�formatrr�r�r3rrJrr�rMr=rf�fakesock�closed)r&�transferr��headerrr~rp�resps        r,�test_http_closedzHandlerTests.test_http_closed�s)��!
�
	D�
	D��X�t�
5�;�;�H�E�E�F��'��
�
���$�(>�?�?�D��n�8�8�:�:�G��/�*�*�C��C�K�����s�+�+�
�t��	�	����
�
�
�
�
�
�
�
�
�
�
����
�
�
�
��O�O�D�M�0�1�8�8��B�B�
D�
D�
D�
D�
	D�
	Ds�B1�1B5	�8B5	c�z�tjd��}tj���}td��}d|_|�tj	j
��5|�||��ddd��n#1swxYwY|�|j
jd��dS)z;Test the connection is cleaned up after an invalid responser.r"NzConnection not closed)rr�r3rrJrr�r5rr?�
BadStatusLinerMrfr$r%)r&rr~rps    r,�test_invalid_closedz HandlerTests.test_invalid_closed�s����#�C�(�(���.�4�4�6�6���o�&�&�����
�
�
�t�{�8�
9�
9�	'�	'��O�O�D�#�&�&�&�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'����	'�	'�	'�	'�����
�,�.E�F�F�F�F�Fs�-B�B�BN)2rUr$rVr�r�r�r�rrrrrrr%r+r.r4r;rArYreriruryr�r�r�r�r�r�r�r��
skipUnlessr r!r�r�platformr�r�r�r�rrrr�rrr)r,rWr.r,r�r��s������>H�>H�>H�@Z5�Z5�Z5�x@C�@C�@C�DE�E�E�2���.)�)�)�,O�O�O�(;�;�;�J�J�J�+�+�+�P�P�P�6M�M�M�.)�)�)�.�.�.�&C�C�C�2���"HR�HR�HR�T>�>�>�,:�:�:�
6�
6�
6�>�>�>�F�F�F�(!M�!M�!M�F<�<�<�$
#�
#�
#�	#�	#�	#�8�8�8� J�J�J�.�X����D��*E�F�F�$�$�G�F�$�.�X�����1�3J�K�K�D�D�L�K�D�BG�G�G�+2�+2�+2�Z � � �"0A�0A�0A�dM�M�M�M�M�M�#K�#K�#K�J6�6�6�6&6�&6�&6�PD�D�D�"G�G�G�G�Gr.r�c�2�eZdZd�Zd�Zd�Zd�Zd�Zd�ZdS)�	MiscTestsc�n��|�t�fd�|jD������dS)Nc3�.�K�|]}|j�kV��dSr�)r)rKrH�
handler_classs  �r,�	<genexpr>z/MiscTests.opener_has_handler.<locals>.<genexpr>�s>�����6�6� !��K�=�8�6�6�6�6�6�6r.)rf�anyr-)r&r+r3s  `r,�opener_has_handlerzMiscTests.opener_has_handler�sW�������6�6�6�6�%+�_�6�6�6�6�6�	7�	7�	7�	7�	7r.c�&�Gd�dtjj��}Gd�dtjj��}Gd�dtjj��}tjj}|||��}|�||��|�||��|||����}|�||��|�||��||��}|�||��|��}|�|tjj��|tjj��}|�|tjj��|tj�����}|�|tjj��Gd�dtjj��}|||��}|�||��|�||��dS)	Nc��eZdZdS)�2MiscTests.test_build_opener.<locals>.MyHTTPHandlerNr'rWr.r,�
MyHTTPHandlerr9r)r.r:c��eZdZd�ZdS)�/MiscTests.test_build_opener.<locals>.FooHandlerc��dSr�rWr�s r,�foo_openz8MiscTests.test_build_opener.<locals>.FooHandler.foo_openr�r.N)rUr$rVr>rWr.r,�
FooHandlerr<�#������
�
�
�
�
r.r?c��eZdZd�ZdS)�/MiscTests.test_build_opener.<locals>.BarHandlerc��dSr�rWr�s r,�bar_openz8MiscTests.test_build_opener.<locals>.BarHandler.bar_openr�r.N)rUr$rVrDrWr.r,�
BarHandlerrBr@r.rEc��eZdZdS)�7MiscTests.test_build_opener.<locals>.MyOtherHTTPHandlerNr'rWr.r,�MyOtherHTTPHandlerrG$r)r.rH)r3rr��BaseHandlerr�r6)r&r:r?rEr�rsrHs       r,�test_build_openerzMiscTests.test_build_opener�sI��	�	�	�	�	�F�N�6�	�	�	�	�	�	�	�	���3�	�	�	�	�	�	�	�	���3�	�	�	��~�2���L��Z�0�0������:�.�.�.�����:�.�.�.�
�L��Z�Z�\�\�2�2������:�.�.�.�����:�.�.�.�
�L��'�'������=�1�1�1�
�L�N�N������6�>�#=�>�>�>��L���3�4�4������6�>�#=�>�>�>��L���3�3�5�5�6�6������6�>�#=�>�>�>�	�	�	�	�	���!;�	�	�	�
�L��(:�;�;������=�1�1�1�����#5�6�6�6�6�6r.c�.�d}dx}x}}d}tj�|||||��}|�t	|d����|�|jd��|�t	|d����|�|jd��d|j�d|j	��}|�t|��|��d|j�d|j	�d	�}|�t|��|��dS)
z�
        Issue 13211 reveals that HTTPError didn't implement the URLError
        interface even though HTTPError is a subclass of URLError.
        zsomething bad happenedNzContent-Length: 42rOr_zHTTP Error z: z<HTTPError �>)r3rrQrfr!r#rOr_r�r�rRr�)r&r�r`r�r�r�rS�expected_errmsgs        r,�test_HTTPError_interfacez"MiscTests.test_HTTPError_interface+s��
'������d�R�#���l�$�$�S�$��T�2�>�>�������X�.�.�/�/�/������%=�>�>�>������Y�/�/�0�0�0������&:�;�;�;�;�14����3�7�7�C������S���?�3�3�3�3�25�(�(�(�C�G�G�G�D������c���O�4�4�4�4�4r.c��tj�ddddd��}|�t	|dd��d��|�|j���t��dS)Nr`i�zMETHOD NOT ALLOWED�	__notes__rW)	r3rrQr#rPr�r�r=r)r&rLs  r,�
test_gh_98778zMiscTests.test_gh_98778=sh���L�"�"�5�#�/C�T�4�P�P�������K��4�4�b�9�9�9����a�d�i�i�k�k�5�1�1�1�1�1r.c��gd�}|D](\}}|�t|��|���)|�ttd��fdS)N)�r�)NNNr��r�)NNNr�rSrT)zjoe:password@proxy.example.com)Nrtrur�)z#joe:password@proxy.example.com:3128)Nrtrur�)zhttp://proxy.example.com/)rNNr�)zhttp://proxy.example.com:3128/)rNNr�)z&http://joe:password@proxy.example.com/�rrtrur�)z*http://joe:password@proxy.example.com:3128)rrtrur�)z1ftp://joe:password@proxy.example.com/rubbish:3128)r�rtrur�)z%http://joe:password@proxy.example.comrU)z&http://user/name:password@localhost:22)r�	user/nameru�localhost:22)z&http://username:pass/word@localhost:22)r�username�	pass/wordrW)z'http://user/name:pass/word@localhost:22)rrVrYrWzfile:/ftp.example.com)r#rr5r6)r&�parse_proxy_test_cases�tcr|s    r,�test_parse_proxyzMiscTests.test_parse_proxyBsm��$"
�$"
�$"
��N3�	9�	9�L�B�����\�"�-�-�x�8�8�8�8����*�l�4K�L�L�M�M�M�Mr.c��t��}|�t��5}|�d��ddd��n#1swxYwY|�t|j��d��dS)N�invalidz5Unsupported digest authentication algorithm 'invalid')rr5r6�get_algorithm_implsr#rR�	exception)r&r~�excs   r,�test_unsupported_algorithmz$MiscTests.test_unsupported_algorithmos���+�-�-��
�
�
�z�
*�
*�	3�c��'�'�	�2�2�2�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3������
���C�	
�	
�	
�	
�	
s�A�A�AN)	rUr$rVr6rJrNrQr\rbrWr.r,r0r0�ss������7�7�7�*7�*7�*7�X5�5�5�$2�2�2�
+N�+N�+N�Z
�
�
�
�
r.r0c�~�eZdZGd�de��Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�ZdS)�RequestTestsc��eZdZdZdS)�RequestTests.PutRequest�PUTN)rUr$rVr�rWr.r,�
PutRequestrfzs���������r.rhc��td��|_tddddi���|_tdd���|_|�d��|_|�dd���|_dS)	N�http://www.python.org/~jeremy/r�zX-Testr�r^�HEAD)r�r�)rr��post�headrh�put�
force_postr�s r,�setUpzRequestTests.setUp}s����;�<�<����<�"�%-�v�$6�8�8�8��	��<�V�L�L�L��	��?�?�#C�D�D����/�/�*J��*������r.c���|�d|j�����|�d|j�����|�d|j�����|�d|j�����|�d|j�����dS)Nr�r�rkrg)r#rlrSr�rmrnror�s r,�test_methodzRequestTests.test_method�s���������!5�!5�!7�!7�8�8�8������� 3� 3� 5� 5�6�6�6�������!5�!5�!7�!7�8�8�8������� 3� 3� 5� 5�6�6�6�������!;�!;�!=�!=�>�>�>�>�>r.c�N�|�|jj��|�d|j�����d|j_|�|jj��|�d|j�����dS)Nr�r�r�)rkr�r�r#rSrfr�s r,�	test_datazRequestTests.test_data�s���������'�'�'������� 3� 3� 5� 5�6�6�6����
������
�&�&�&�������!4�!4�!6�!6�7�7�7�7�7r.c� �|�d|jj��|j�dd��|�d|jjd��d|j_|�d|jj��dS)Nr��*r�)r�r�r�ror#r�r�s r,�.test_setting_data_should_remove_content_lengthz;RequestTests.test_setting_data_should_remove_content_length�s������)�4�8�+E�F�F�F���(�(�)9�2�>�>�>�����T�X�7�8H�I�J�J�J����
����)�4�8�+E�F�F�F�F�Fr.c�.�|�d|jj��d|j_|j�dd��|�d|jjd��|j`|�d|jj��dS)Nr�r}r)r�r�r�r�ror#r�s r,�/test_deleting_data_should_remove_content_lengthz<RequestTests.test_deleting_data_should_remove_content_length�s������)�4�8�+E�F�F�F����
���(�(�)9�1�=�=�=�����D�H�6�7G�H�I�I�I��H�M����)�4�8�+E�F�F�F�F�Fr.c�`�|�d|j�����dS)Nrj)r#r�rBr�s r,�test_get_full_urlzRequestTests.test_get_full_url�s8�����9���.�.�0�0�	2�	2�	2�	2�	2r.c��|�d|jj��td��}|�d|j��dS)Nz	/~jeremy/zhttp://www.python.org/r0)r#r�r�rrNs  r,�
test_selectorzRequestTests.test_selector�sI������d�h�&7�8�8�8��.�/�/������c�l�+�+�+�+�+r.c�F�|�d|jj��dS)Nr)r#r�r�r�s r,�
test_get_typezRequestTests.test_get_type�s"���������/�/�/�/�/r.c�F�|�d|jj��dS)Nr0)r#r�r�r�s r,�
test_get_hostzRequestTests.test_get_host�s#�����)�4�8�=�9�9�9�9�9r.c�Z�td��}|�d|j��dS)Nzhttp://www.%70ython.org/r0�rr#r�rNs  r,�test_get_host_unquotez"RequestTests.test_get_host_unquote�s/���0�1�1�����)�3�8�4�4�4�4�4r.c�l�|�|j�����|j�dd��|�|j�����|�d|jj��|�d|jj��dS)Nr�rr0)rkr��	has_proxyrrfr#r>r�r�s r,r�zRequestTests.test_proxy�s��������+�+�-�-�.�.�.�����>�6�2�2�2������*�*�,�,�-�-�-����)�4�8�+C�D�D�D��������7�7�7�7�7r.c�Z�td��}|�d|j��dS)Nz<URL:http://www.python.org>r0r�rNs  r,�test_wrapped_urlzRequestTests.test_wrapped_url�s/���3�4�4�����)�3�8�4�4�4�4�4r.c� �td��}|�d|j��td��}|�d|j��d}t|��}|�|���|��dS)N�-http://www.python.org/?qs=query#fragment=truez
/?qs=queryzhttp://www.python.org/#fun=truer0�.http://docs.python.org/library/urllib2.html#OK)rr#r�rB)r&rpr`s   r,�test_url_fragmentzRequestTests.test_url_fragment�s����E�F�F������s�|�4�4�4��7�8�8������c�l�+�+�+�?���c�l�l������)�)�+�+�S�1�1�1�1�1r.c��gd�}|D]>}t|��}|�|���|j���?dS)N)zhttp://docs.python.orgr�r�)rr#rBr')r&r�r`rps    r,�test_url_fullurl_get_full_urlz*RequestTests.test_url_fullurl_get_full_url�sc��A�A�A���	?�	?�C��#�,�,�C����S�-�-�/�/���>�>�>�>�	?�	?r.N)rUr$rVrrhrprrrtrwryr{r}rr�r�r�r�r�r�rWr.r,rdrdys�����������W�������?�?�?�8�8�8�G�G�G�G�G�G�2�2�2�,�,�,�
0�0�0�:�:�:�5�5�5�8�8�8�5�5�5�	2�	2�	2�?�?�?�?�?r.rd�__main__)>r�r�r�test.supportrrrrr r�r�rrr�r�urllib.requestr3rr	r
rrr
rr�urllib.parserrq�http.clientr�requires_working_socket�TestCaserrYr�r�r�r�r�r�r�r��IOBaser�r�r�r/r2rrIr4rJrFrQrYrcr�r�r0rdrU�mainrWr.r,�<module>r�s5������������"�"�"�"�"�"�&�&�&�&�&�&�(�(�(�(�(�(�������	�	�	�	�	�	�	�	�
�
�
�
�����
�
�
�
�������������7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�
"�!�!�!�!�!������������t�,�,�,�,�1,�1,�1,�1,�1,�8�$�1,�1,�1,�hx'�x'�x'�x'�x'�x�(�x'�x'�x'�v,�,�,�,�,�,�,�,�
�
�
�
�
�
�
�
�#�#�#�#�#�$�#�#�#�
	�	�	�	�	�2�;�	�	�	�3�3�3�3�3�3�3�3�?�?�?�?�?�?�?�?������r�y����$*
�*
�*
�*
�*
�*
�*
�*
�Z38�38�38�38�38�38�38�38�l���D���H�H�H�H�H�f�n�0�H�H�H�8	0�	0�	0�	0�	0�v�~�9�	0�	0�	0�Q�Q�Q�Q�Q�v�~�9�Q�Q�Q�&
(�
(�
(�
(�
(�
(�
(�
(�NA�NA�NA�NA�NA�(�+�NA�NA�NA�b	�	�	�hG�hG�hG�hG�hG�8�$�hG�hG�hG�V!}
�}
�}
�}
�}
��!�}
�}
�}
�@^?�^?�^?�^?�^?�8�$�^?�^?�^?�B�z����H�M�O�O�O�O�O��r.

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists