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

�Ke�6���ddlZddlmZddlmZddlmZddlmZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZmZmZmZmZmZddlmZddlZddlZejd	�
��Gd�dej��ZGd
�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$ej/j0��Z1Gd%�d&ej/j2��Z3Gd'�d(ej/j0��Z4Gd)�d*��Z5Gd+�d,ej��Z6d-�Z7Gd.�d/ej��Z8Gd0�d1ej��Z9Gd2�d3ej��Z:e;d4krej<��dSdS)5�N)�support)�	os_helper)�
socket_helper)�warnings_helper)�test_urllib)�Request�OpenerDirector�HTTPBasicAuthHandler�HTTPPasswordMgrWithPriorAuth�_parse_proxy�_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/apps/python3/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_trivial4s	��	
�����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)rBrCz"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"r2r�parse_http_list)r%�tests�string�lists    r+�test_parse_http_listz!TrivialTests.test_parse_http_listGs���
�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)r2r�URLError�assertInrN�str)r%�errs  r+�test_URLError_reasonstrz$TrivialTests.test_URLError_reasonstrRs9���l�#�#�H�-�-���
�
�c�j�#�c�(�(�+�+�+�+�+r-N)�__name__r#�__qualname__r,r@rLrS�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_dictYs���#�������*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
        rZr[r\r])r[r\zFoo-Bar�baz)zFoo-barrbz	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_methodsns���#���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�3rDz
d.example.com�4�dze.example.com:3128�5�e�example.com)rsrtrZzhttp://example.com/spamzhttp://example.com/spam/spamzhttp://example.com/foo�foozhttp://example.com/bar�bar�ninizhttp://example.com/foo/bar�foobar�nibar)r|ru)r}r~zhttp://example.com/foo/zhttp://example.com/foo/bazzhttp://example.com/foobar�NNzhttp://example.com/baz/rb�nininizhttp://example.com/baz)rbr�zhttp://example.com/baz/barrC�firstr\�second�spam)r�r�rB�1)r�rBzhttp://a.example.com/z
c.example.comzc.example.com:3128)rvrD)rwrx)ryrz�r2r�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�jrFzhttp://h.example.com�11r)rGzi.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)rTr#rUr`rpr�r�rVr-r+rXrXWsX������A�A�A�*">�">�">�HT%�T%�T%�l''�''�''�''�''r-rXc�.�eZdZgZdejfd�Zd�ZdS)�
MockOpenerNc�2�|||c|_|_|_dS�N)ro�data�timeout)r%ror�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-)rTr#rU�
addheaders�socket�_GLOBAL_DEFAULT_TIMEOUTr�rrVr-r+r�r�sD�������J�!�6�+I�?�?�?�?�,�,�,�,�,r-r�c�$�eZdZdd�Zdd�Zd�ZdS)�MockFileNc��dSr�rV�r%�counts  r+r<z
MockFile.read����r-c��dSr�rVr�s  r+�readlinezMockFile.readline r�r-c��dSr�rV�r%s r+�closezMockFile.close#r�r-r�)rTr#rUr<r�r�rVr-r+r�r�sK������
�
�
�
�
�
�
�
�
�
�
�
�
r-r�c��eZdZd�ZdS)�MockHeadersc�D�t|�����Sr�)rK�values)r%r s  r+�
getheaderszMockHeaders.getheaders(s���D�K�K�M�M�"�"�"r-N)rTr#rUr�rVr-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.info1s
���|�r-c��|jSr��r_r�s r+�geturlzMockResponse.geturl4�	���x�r-r�)rTr#rUr�r�r�rVr-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_header9s
������r-c�$�||c|_|_dSr�)�ec_req�ec_r)r%rrs   r+�extract_cookieszMockCookieJar.extract_cookies<s��!(�(����T�Y�Y�Yr-N)rTr#rUr�r�rVr-r+r�r�8s2���������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__As��"����������r-c�4�|j|j|jg|�R�Sr�)r�r�r�)r%r�s  r+�__call__zFakeMethod.__call__Fs"���t�{�4�>�4�;�>��>�>�>�>r-N)rTr#rUr�r�rVr-r+r�r�@s2���������
?�?�?�?�?r-r�c�&�eZdZd�Zd�Zd�Zd�ZdS)�MockHTTPResponsec�L�||_||_||_||_d|_dS)N��)�fpr��statusrNr�)r%r�r�r�rNs     r+r�zMockHTTPResponse.__init__Ks)����������������	�	�	r-c��dS)N�rVr�s r+r<zMockHTTPResponse.readRs���rr-c��iSr�rVr�s r+r�zMockHTTPResponse.infoUs���	r-c��|jSr�r�r�s r+r�zMockHTTPResponse.geturlXr�r-N)rTr#rUr�r<r�r�rVr-r+r�r�JsP�������������������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__es����	�����r-c��||_dSr�)r�)r%r�s  r+�set_debuglevelzMockHTTPClass.set_debugleveljs
����
�
�
r-Nc�j�||_||_|r	||_dS|j���dSr�)�_tunnel_host�_tunnel_portr��clear)r%r��portr^s    r+�
set_tunnelzMockHTTPClass.set_tunnelmsC�� ��� ����	)�#*�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.requestus|�������
�������
�
���/�����������	��D�I�,����#�	��)�)�O�	�	r-c�>�tt��idd��S)Nr��OK)r�r�r�s r+�getresponsezMockHTTPClass.getresponse�s����
�
�B��T�:�:�:r-c��dSr�rVr�s r+r�zMockHTTPClass.close�r�r-r�)rTr#rUr�r�r�r�r�r�rr�r�rVr-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�intr5rr2rO)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�
�
��,�'�'��/�/�/��s�B%�%
B2�1B2c��dSr�rVr�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)
rTr#rUrr�rr�r�rr"rVr-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�rTr#rUrVr-r+�MockHandlerSubclassr%���������Dr-r'r)r�rrr�add_handler)�opener�	meth_spec�handlersr��methsr'rGs       r+�add_ordered_mock_handlersr.�s���&�H�
�E��	�	��	�	�	�	�	�+�	�	�	�
 ���&�&��	���5� ���	���V������	������������1������Or-c�V�t��}|D]}|�|���|Sr�)r	r))�handler_instancesr*rGs   r+�build_test_openerr1�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+r5zMockHTTPHandler.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�copyr8r�deepcopyr7r�client�	responsesr��message_from_stringr^rrr�ror��get_full_url)r%ror;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�rTr#rUr�r5rBrVr-r+r3r3�sF���������
���H�H�H�H�Hr-r3c��eZdZdd�Zd�ZdS)�MockHTTPSHandlerrc�x�tjj�||���t	��|_dS)N��
debuglevel)r2r�AbstractHTTPHandlerr�r��httpconn)r%rHs  r+r�zMockHTTPSHandler.__init__s/����*�3�3�D�Z�3�P�P�P�%����
�
�
r-c�8�|�|j|��Sr�)�do_openrJ�r%ros  r+�
https_openzMockHTTPSHandler.https_opens���|�|�D�M�3�/�/�/r-N)r)rTr#rUr�rNrVr-r+rErEs7������(�(�(�(�0�0�0�0�0r-rEc� �eZdZd�Zd�Zd�ZdS)�MockHTTPHandlerCheckAuthc�"�||_d|_dS�NF)r��has_auth_header)r%r�s  r+r�z!MockHTTPHandlerCheckAuth.__init__s����	�$����r-c��d|_dSrR)rSr�s r+r5zMockHTTPHandlerCheckAuth.resets��$����r-c���|�d��rd|_tjj|j}t
|j|t��d|�����S)N�
AuthorizationTr�)	rfrSrr>r?r�r�r�rA)r%ror s   r+rBz"MockHTTPHandlerCheckAuth.http_opensW���>�>�/�*�*�	(�#'�D� ��{�$�T�Y�/���D�I�t�X�Z�Z��S�=M�=M�=O�=O�P�P�Pr-NrCrVr-r+rPrPsF������%�%�%�%�%�%�Q�Q�Q�Q�Qr-rPc��eZdZd�Zd�ZdS)�MockPasswordManagerc�>�||_||_||_||_dSr�)�realmr_�userrt)r%rZ�urir[rts     r+r�z MockPasswordManager.add_password$s"����
������	� ��
�
�
r-c�:�||_||_|j|jfSr�)�target_realm�
target_urlr[rt)r%rZ�authuris   r+r�z&MockPasswordManager.find_user_password*s ��!���!����y�$�-�'�'r-N)rTr#rUr�r�rVr-r+rXrX#s2������!�!�!�(�(�(�(�(r-rXc�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&rVr-r+�
NonHandlerre3r(r-rf)�objectr4�	TypeErrorr	r))r%rfs  r+�test_add_non_handlerz(OpenerDirectorTests.test_add_non_handler2si��	�	�	�	�	��	�	�	����)�(�*�*�6�
�
���	F�	F�	F�	F�	Fr-c��ddlm}t��}ddgdgg}t||��|�t
j�����dD]!}|�||j	|dz���"dS)Nr)rO)rLr)�
proxy_openr)�redirect_requestr)�do�proxy�redirectz://example.com/)
�urllib.errorrOr	r.r)r2r�UnknownHandlerr4r�)r%rO�or+�schemes     r+�test_badly_named_methodsz,OpenerDirectorTests.test_badly_named_methods8s���	*�)�)�)�)�)�����
'�)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)rB�ftp_open�http_error_302rv�rBrrrrrrB)r	r.rr�r"�zipr)
r%rrr+r,ro�rr�expected�got�handlerr r�rs
             r+�test_handledz OpenerDirectorTests.test_handledMs������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)	Nrxr�rBrc��eZdZdS)�COpenerDirectorTests.test_handler_order.<locals>.MockHandlerSubclassNr&rVr-r+r'r�ls�������r-r'rrr)r	r�rrr)r�r"r)r%rrr,r-rr'rGs       r+�test_handler_orderz&OpenerDirectorTests.test_handler_ordergs��������'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)rBrrxrrrrB)
r	r.rr4r2rrOr�r"r)r%rrr+r,ros     r+�
test_raisezOpenerDirectorTests.test_raiseys�������
#�$�
)�*��	�-�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)rBz	error 302)�http_error_400rrB))rwr�http_error_303�
http_errorrwrrrr�.r�)
r	r.rr�rrr�	ALWAYS_EQryr")r%rrr+r,rorr{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rrrr�rr�r)
r	r.rr��	enumeraterr"r�assertIsInstancer�)r%rrr+r,rorr�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)
rTr#rUrirtr~r�r�r�r�rVr-r+rbrb0s�������F�F�F�J�J�J�*+�+�+�45�5�5�$L�L�L�+�+�+�.!A�!A�!A�!A�!Ar-rbc��	|�d��n"#t$rtjd���wxYwtj�|��}tjdkr|�	d��r
|dd�}|S)Nzutf-8zpath is not encodable to utf8rz///r)
�encode�UnicodeEncodeError�unittest�SkipTestr2rrrr r)r7�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#d �Z$d!�Z%d"�Z&d#�Z'd$�Z(d%�Z)d&�Z*d'�Z+d(�Z,d)�Z-d*�Z.d+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�rVr�s r+r�z3HandlerTests.test_ftp.<locals>.MockFTPWrapper.close�����r-N)rTr#rUr�r�r�rVr-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)rTr#rUr�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.gif�Content-type�Content-length)r2r�
FTPHandler�ftplibr�r�FTP_PORTrr�rvr"r[r�r�r��
gethostbynamer�r�r�r�r�r��getrr)r%r�r�r�rGr_r�r�r[r��type_r�r��mimetyperorzr^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�
��D�
"�!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%sr0zfile://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:80r/z'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.utilsr2r�FileHandlerr�rr�TESTFNr�rr7r8r�r��gethostname�gaierrorrr��writer��	file_openrr<r�r��stat�utils�
formatdate�st_mtime�remover"�getcwdr4rrO�assertIsro�typerj)r%r;rGrrr�r��towrite�urls�	localaddrr_r?rzr�r^�respurl�stats�modifiedr�ros                   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)Nrr))�GETN)�POSTsblah�Foor}�Spam�eggsr�r�r{rr/))�
Connectionr�)r�r}�r�r�T�badpostr�)r-Nr�r�r��0z!application/x-www-form-urlencoded�Hostr|rb)#r2rrIr�rrr�rnr�rLr<r�r�r�r�r�r��__contains__r"r�r�r�r�r�r�r�r4rrOrh�do_request_r�r��assertNotIn�unredirected_hdrs)r%rGrrr_r�r�rorrz�hdrs�newreqs           r+�	test_httpzHandlerTests.test_httpks���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�rbrr�Transfer-encoding�chunkedr��Content-Length�)r2rrIr�r�tempfile�NamedTemporaryFiler r�r1r�unlinkr�rr�rlr"rjrfr)	r%rGrr�file_obj�	file_pathr?ror��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)Nrrr�r�r�r�r�)r2rrIr�rr��BytesIOrr�r"rlrjrfrr�)r%rGrrr�ror�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�)�stdoutrrr�r�r�)r2rrIr�r�sys�
executable�
subprocess�Popen�PIPErrr�r"rlr)r%rGrr�cmdr^�procror�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)NsonerVrVr-r+�
iterable_bodyz;HandlerTests.test_http_body_iterable.<locals>.iterable_body�s�����L�L�L�L�Lr-r��rrr�r�r�)
r2rrIr�rrr�r"rlr)r%rGrrrr^ror�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)NrrrVr�r�r�)r2rrIr�rr�rr"rlrjrf)r%rGros   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��rrr�)r2rrIr�r�arrayrr�r"rrl)r%rGrr�iterable_arrayr^ror�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)NrrGzhttps://www.example.com)r	rEr)r�r"�_debuglevel)r%rrrGs   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)
r2rrIr�rrr�r"r��	set_proxy)r%rGr��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#bashrZrZr�)r�full_urlrr"rA�fragment�query)r%r�rzr_�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&rkr'r"r�)r%rzs  r+�test_full_url_deleterz"HandlerTests.test_full_url_deleterUs_���,�-�-��
�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�)
r2rrIr�rrr�r"r�r�)r%rG�	weird_urlror��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)
Nrrr�r�r�r����Accepted��zPartial contenti�zBad gatewayr)r2r�HTTPErrorProcessorr�rrr�r�r�rjr rkr"r�r�)r%rGrrr_rorz�newrs       r+�test_errorszHandlerTests.test_errorsos����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)Nrrr�r�r�r{)r�r2r�HTTPCookieProcessorr�rrr�r�r�r�r"�origin_req_hostrj�unverifiabler�r�r�)r%�cjrGrorzr�r9s       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)rCrDr�c�6�g|]}|�����SrV)�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�rFrG)rwr�r�)rGror_s   r+roz,HandlerTests.test_redirect.<locals>.redirect�s@��
���S�(�*�*�c�6�(�*�c�):�;�;�
=�
=�
=�
=�
=r-r{)r=rrrrzhttp://example.com/%d) r2r�HTTPRedirectHandlerr�r�getattrrr�r�r�rhrQrrnr�r�r�	HTTPErrorrP�assertIsNotNoner"rorA�
get_method�AttributeErrorrjr�r^r�r��max_repeats�max_redirections)r%�from_url�to_urlrGrrr�r�r�ror^ror�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)
NrB)r�httpsr�)�file�imap�ldapzexample.com/b.htmlz://r�zSecurity LoopholerG�That's fine)r2rrNr�rrr�r�r�r4rrPrwr�r�r"rorA)r%rV�
valid_schemes�invalid_schemes�schemeless_urlrGrrrors�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)NrBz/b.htmlr�r^rG)r2rrNr�rrr�r�r�r�urljoinrwr�r�r"rorA)r%rV�relative_urlrGrrrorcs       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.cookiejarrj�test.test_http_cookiejarrkr3r2r�HTTPDefaultErrorHandlerrNr<r1r�rjrorf)	r%rjrkr?�hh�hdeh�hrh�cprrs	         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,)
r3r2rrorNr1r�r"r��strip)r%�redirected_urlrprqrrrrr�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)r1r2rr3rr>rzr�fakehttpr�iterr6r"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)rL�
connection�buf�last_bufrr�)r%ro�results   r+rBz>HandlerTests.test_redirect_encoding.<locals>.Handler.http_open6sC�����d�o�s�;�;�� $�� 3��
�"-�"6��#�#����
r-N)rTr#rUrBrVr-r+�Handlerr�5s#������

�

�

�

�

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

rrsGET � )
r2r�HTTPHandler�build_opener�subTest�reprrr�r�r�r�rer)
r%r�r}r*rIrGr�rr{rs
          r+�test_redirect_encodingz#HandlerTests.test_redirect_encoding2s|��	�	�	�	�	�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)rBrzhttp://acme.example.com/zacme.example.comrrBc�"�g|]}|dd���
S�rrrV�rJ�tups  r+rLz+HandlerTests.test_proxy.<locals>.<listcomp>es ��:�:�:�3�c�!�A�#�h�:�:�:r-)�dictr	r2r�ProxyHandlerr)r.rr"r�r�r)r%r'rxrr�phr+r,ros        r+�
test_proxyzHandlerTests.test_proxyUs��$���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.orgr0r/�r�environr	r2rr�r�r)rr"r�r��r%rrr�ros    r+�test_proxy_no_proxyz HandlerTests.test_proxy_no_proxygs���!-��
�:������
�^�
(�
(��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�r0r/r�r�s    r+�test_proxy_no_proxy_allz$HandlerTests.test_proxy_no_proxy_allvs���!$��
�:������
�^�
(�
(��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��rZ)rNr�https://www.example.com/�www.example.comrrNc�"�g|]}|dd���
Sr�rVr�s  r+rLz1HandlerTests.test_proxy_https.<locals>.<listcomp>�s ��6�6�6�s�#�a��c�(�6�6�6r-)r	r2rr�r�r)r.rr"r�r�r)r%rrr�r+r,ros      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	r2rr�r�r)rErrhr"r�rkr�r�r�rJr�rPrQrl)r%rrr��
https_handlerros     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-�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�notinbypassz!expected bypass of %s to be FalseT�testz10.0.0.0/40z172.19.10.0/24z172.19.10.5z10.0.1.5)rer
rj)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)rZr^z
r:�rV�!http://acme.example.com/protected)
r�r	rXr2rr
�joinr3r)�_test_basic_auth)r%r^rZr*�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�rV)rJ�	challenges  r+rLz0HandlerTests.test_basic_auth.<locals>.<listcomp>s0��4�4�4�$�8�I�7�7�4�4�4r-)r�r�check_warnings�UserWarning)
r%rZ�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	r2rr�r�r)rX�ProxyBasicAuthHandlerr3r�)r%r*r�r�r�rZr�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__ s���'��-�-�-� "��
�
�
r-c�:�|j�|��dSr�)r�r)r%r�s  r+�recordzXHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.record$s���
�$�$�T�*�*�*�*�*r-N)rTr#rUr�r�rVr-r+�RecordingOpenerDirectorr�s2������
#�
#�
#�
+�
+�
+�
+�
+r-r�c��eZdZd�ZdS)�OHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandlerc�x�|j�d��tjjj|g|�Ri|��dS)Nr�)rr�r2r�HTTPDigestAuthHandler�http_error_401�r%r�rs   r+r�z^HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandler.http_error_401(sa����"�"�8�,�,�,���4�C�D�L�>B�L�L�L�FJ�L�L�L�L�Lr-N�rTr#rUr�rVr-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�r2rr
r�r�s   r+r�z]HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandler.http_error_401.sa����"�"�7�+�+�+���3�B�4�K�=A�K�K�K�EI�K�K�K�K�Kr-Nr�rVr-r+�TestBasicAuthHandlerr�-s(������
K�
K�
K�
K�
Kr-r�r�r��&WWW-Authenticate: Basic realm="%s"

rVr�r�r�r)r	r2rr�r
rXr3r)r�r"r�)
r%r�r�r�r*r��digest_handler�
basic_handlerrZr�s
          r+�#test_basic_and_digest_auth_handlersz0HandlerTests.test_basic_and_digest_auth_handlerss���	+�	+�	+�	+�	+�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	r2rr�r3r)r4r5r�)r%r*�digest_auth_handlerr�s    r+�$test_unsupported_auth_digest_handlerz1HandlerTests.test_unsupported_auth_digest_handlerHs����!�!��$�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	r2rr
r3r)r4r5r�)r%r*�basic_auth_handlerr�s    r+�#test_unsupported_auth_basic_handlerz0HandlerTests.test_unsupported_auth_basic_handlerRs����!�!��#�^�@�@��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"rZr_r[rtr�r^r_rr8rjrf�bytes�encodebytesrv�decoderlr�r5)r%r*r��auth_headerrZr�r��request_url�
protected_urlrr[rt�userpass�auth_hdr_values              r+r�zHandlerTests._test_basic_auth\sf��	�
�
�
�)���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)rPrr
r�rerrjr	r)r�rS)r%r[rtrr��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�rrjr	r)r3r�rerPrS)
r%r[rtrrZrr�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: 4rzHTTP/1.1 200 OK
{}

�
http://dummy/NzConnection not closed with {!r})�formatrr�r�r2rrIrr�rLr<re�fakesock�closed)r%�transferr��headerr~r}ro�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-rNzConnection not closed)rr�r2rrIrr�r4rr>�
BadStatusLinerLrerr)r%r~r}ros    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)/rTr#rUr�r�r�r�rrrrrrr$r*r-r3r:r@rXrdrhrtrxr�r�r�r�r�r�r�r��
skipUnlessr�platformr�r�r�r�r�r�r�r�rrr"r%rVr-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�����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)rJrG�
handler_classs  �r+�	<genexpr>z/MiscTests.opener_has_handler.<locals>.<genexpr>�s>�����6�6� !��K�=�8�6�6�6�6�6�6r-)re�anyr,)r%r*r,s  `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&rVr-r+�
MyHTTPHandlerr2�r(r-r3c��eZdZd�ZdS)�/MiscTests.test_build_opener.<locals>.FooHandlerc��dSr�rVr�s r+�foo_openz8MiscTests.test_build_opener.<locals>.FooHandler.foo_open�r�r-N)rTr#rUr7rVr-r+�
FooHandlerr5��#������
�
�
�
�
r-r8c��eZdZd�ZdS)�/MiscTests.test_build_opener.<locals>.BarHandlerc��dSr�rVr�s r+�bar_openz8MiscTests.test_build_opener.<locals>.BarHandler.bar_open�r�r-N)rTr#rUr=rVr-r+�
BarHandlerr;�r9r-r>c��eZdZdS)�7MiscTests.test_build_opener.<locals>.MyOtherHTTPHandlerNr&rVr-r+�MyOtherHTTPHandlerr@r(r-rA)r2rr��BaseHandlerr�r/)r%r3r8r>r�rrrAs       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: 42rNr^zHTTP Error z: z<HTTPError �>)r2rrPrer r"rNr^r�r�rQr�)r%r�r_r�r�r�rR�expected_errmsgs        r+�test_HTTPError_interfacez"MiscTests.test_HTTPError_interfaces��
'������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__rV)	r2rrPr"rOr�r�r<r)r%rKs  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�rLrM)zjoe:password@proxy.example.com)Nrsrtr�)z#joe:password@proxy.example.com:3128)Nrsrtr�)zhttp://proxy.example.com/)rNNr�)zhttp://proxy.example.com:3128/)rNNr�)z&http://joe:password@proxy.example.com/�rrsrtr�)z*http://joe:password@proxy.example.com:3128)rrsrtr�)z1ftp://joe:password@proxy.example.com/rubbish:3128)r�rsrtr�)z%http://joe:password@proxy.example.comrN)z&http://user/name:password@localhost:22)r�	user/namert�localhost:22)z&http://username:pass/word@localhost:22)r�username�	pass/wordrP)z'http://user/name:pass/word@localhost:22)rrOrRrPzfile:/ftp.example.com)r"rr4r5)r%�parse_proxy_test_cases�tcr{s    r+�test_parse_proxyzMiscTests.test_parse_proxy)sm��$"
�$"
�$"
��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')rr4r5�get_algorithm_implsr"rQ�	exception)r%r}�excs   r+�test_unsupported_algorithmz$MiscTests.test_unsupported_algorithmVs���+�-�-��
�
�
�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)	rTr#rUr/rCrGrJrUr[rVr-r+r)r)�ss������7�7�7�*7�*7�*7�X5�5�5�$2�2�2�
+N�+N�+N�Z
�
�
�
�
r-r)c�~�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)rTr#rUr�rVr-r+�
PutRequestr_as���������r-rac��td��|_tddddi���|_tdd���|_|�d��|_|�dd���|_dS)	N�http://www.python.org/~jeremy/r�zX-Testr�r]�HEAD)r�r�)rr��post�headra�put�
force_postr�s r+�setUpzRequestTests.setUpds����;�<�<����<�"�%-�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�rdr`)r"rerRr�rfrgrhr�s r+�test_methodzRequestTests.test_methodns���������!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�)rjr�r�r"rRrer�s r+�	test_datazRequestTests.test_dataus���������'�'�'������� 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�rnr"r�r�s r+�.test_setting_data_should_remove_content_lengthz;RequestTests.test_setting_data_should_remove_content_lengths������)�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�rnr"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)Nrc)r"r�rAr�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/r/)r"r�r�rrMs  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)Nr/)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/r/�rr"r�rMs  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�rr/)rjr��	has_proxyrrer"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>r/r|rMs  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=truer/�.http://docs.python.org/library/urllib2.html#OK)rr"r�rA)r%ror_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"rAr&)r%r�r_ros    r+�test_url_fullurl_get_full_urlz*RequestTests.test_url_fullurl_get_full_url�sc��A�A�A���	?�	?�C��#�,�,�C����S�-�-�/�/���>�>�>�>�	?�	?r-N)rTr#rUrrarirkrmrprrrtrvrxrzr}r�r�r�r�rVr-r+r]r]`s�����������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-r]�__main__)=r�r�r�test.supportrrrrrr�r�rrr�r�urllib.requestr2rr	r
rrr
r�urllib.parserrp�http.clientr�requires_working_socket�TestCaserrXr�r�r�r�r�r�r�r��IOBaser�r�r�r.r1rrBr3rIrErPrXrbr�r�r)r]rT�mainrVr-r+�<module>r�s+������������"�"�"�"�"�"�&�&�&�&�&�&�(�(�(�(�(�(�������	�	�	�	�	�	�	�	�
�
�
�
�����
�
�
�
�������������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	�	�	�PG�PG�PG�PG�PG�8�$�PG�PG�PG�f }
�}
�}
�}
�}
��!�}
�}
�}
�@^?�^?�^?�^?�^?�8�$�^?�^?�^?�B�z����H�M�O�O�O�O�O��r-