Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_urllib2.cpython-310.opt-2.pyc

o

0�i�;�@s8ddlZddlmZddlmZddlmZddlmZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZmZmZmZmZmZmZddlmZddlZddlZGd	d
�d
ej�ZGdd�dej�Z Gd
d�d�Z!Gdd�d�Z"Gdd�de#�Z$Gdd�de	j%�Z&Gdd�d�Z'Gdd�d�Z(Gdd�de	j)�Z*Gdd�d�Z+Gdd�d�Z,dd �Z-d!d"�Z.Gd#d$�d$ej/j0�Z1Gd%d&�d&ej/j2�Z3Gd'd(�d(ej/j0�Z4Gd)d*�d*�Z5Gd+d,�d,ej�Z6d-d.�Z7Gd/d0�d0ej�Z8Gd1d2�d2ej�Z9Gd3d4�d4ej�Z:e;d5k�re�<�dSdS)6�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)�urlparsec@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TrivialTestsc
Cs�dD]I}i}td||�|d=|dkr2tjdkr2|�d�|�d�}}|�|jd�|�|jd�|��D]\}}|�|jd	|d
|||jf�q6qdS)N)�request�response�parse�errorZrobotparserzfrom urllib.%s import *�__builtins__r�ntZurl2pathname�pathname2urlZ
nturl2pathz	urllib.%sz.%r is exposed in 'urllib.%s' but defined in %r)�exec�os�name�pop�assertEqual�
__module__�items)�self�module�context�u�p�k�v�r'�8/opt/alt/python310/lib64/python3.10/test/test_urllib2.py�test___all__$s 
����zTrivialTests.test___all__cCs�|�tjj�|�ttjjd�tj�	tjj
��tjd�}tj
dkr'd|}nd|}tj�|��
}|��Wd�dS1sAwYdS)Nz	bogus url�/rz
file:///%s�	file://%s)�
addCleanup�urllibr�
urlcleanup�assertRaises�
ValueError�urlopenr�path�abspath�__file__�replace�sepr�read)r ZfnameZfile_url�fr'r'r(�test_trivial3s


"�zTrivialTests.test_trivialcCsRdgd�fdddgfdgd�fdgd	�fg}|D]\}}|�tj�|�|�qdS)
Nza,b,c)�a�b�czpath"o,l"og"i"cal, examplezpath"o,l"og"i"calZexampleza, b, "c", "d", "e,f", g, h)r:r;z"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")rr-rZparse_http_list)r �tests�string�listr'r'r(�test_parse_http_listFs

����z!TrivialTests.test_parse_http_listcCs"tj�d�}|�|jt|��dS)N�reason)r-r�URLError�assertInrC�str)r �errr'r'r(�test_URLError_reasonstrQsz$TrivialTests.test_URLError_reasonstrN)�__name__r�__qualname__r)r9rBrHr'r'r'r(r"s
rc@r)
�RequestHdrsTestscCsF	d}|�t|ddid�jdd�|�t|ddid�jdd�dS)N�http://example.com�	Spam-eggs�blah��headersz	spam-EggS)rrrP)r �urlr'r'r(�test_request_headers_dictXs ������z*RequestHdrsTests.test_request_headers_dictcCs�	d}t|ddid�}|�|�d��|�|��dg�|�dd�|�t|���ddg�|�|�d	��|�|�	d	��|�|�	d	d
�d
�|�
d�|�|�d��|�dd�|�|�d��|�
d�|�|�d��dS)
NrLrMrNrO)rMrNzFoo-Bar�baz)zFoo-barrSz	Not-there�defaultzUnredirected-spamZEggs)r�
assertTrue�
has_headerrZheader_items�
add_header�sorted�assertFalse�assertIsNone�
get_headerZ
remove_header�add_unredirected_header)r rQ�reqr'r'r(�test_request_headers_methodsms$�

z-RequestHdrsTests.test_request_headers_methodscCs`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�3r<z
d.example.com�4�dze.example.com:3128�5�e�example.com)r`rarLzhttp://example.com/spamzhttp://example.com/spam/spamzhttp://example.com/foo�foozhttp://example.com/bar�bar�ninizhttp://example.com/foo/barZfoobarZnibar)rirb)rjrkzhttp://example.com/foo/zhttp://example.com/foo/bazzhttp://example.com/foobar�NNzhttp://example.com/baz/rS�nininizhttp://example.com/baz)rSrmzhttp://example.com/baz/barr;�firstrN�second�spam)rorpr:�1)rqr:zhttp://a.example.com/z
c.example.comzc.example.com:3128)rcr<)rdre)rfrg�r-rZHTTPPasswordMgr�add_password�find_user_passwordr�r Zmgr�addZfind_user_passr'r'r(�test_password_manager�s�
�������������������������z&RequestHdrsTests.test_password_managercCst	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�dS)#Nr8zhttp://g.example.com:80�10�jr=zhttp://h.example.com�11r%r>zi.example.com:80�12�l�iz
j.example.com�13�mzg.example.com:100rlzg.example.com:80)rxryz
g.example.comzhttp://g.example.com:100zhttp://g.example.comz
h.example.com)rzr%zh.example.com:80zhttp://h.example.com:80z
i.example.com)r{r|zhttp://i.example.com:80)r~rzj.example.com:80zhttp://j.example.comzhttp://j.example.com:80rrrur'r'r(�"test_password_manager_default_port�s\
�����������z3RequestHdrsTests.test_password_manager_default_portN)rIrrJrRr^rwr�r'r'r'r(rKVs
$VrKc@s(eZdZgZdejfdd�Zdd�ZdS)�
MockOpenerNcCs||||_|_|_dS�N)r]�data�timeout)r r]r�r�r'r'r(�openszMockOpener.opencGs|||_|_dSr�)�proto�args)r r�r�r'r'r(r�zMockOpener.error)rIrrJ�
addheaders�socket�_GLOBAL_DEFAULT_TIMEOUTr�rr'r'r'r(r�sr�c@s(eZdZddd�Zddd�Zdd�ZdS)	�MockFileNcC�dSr�r'�r �countr'r'r(r7�z
MockFile.readcCr�r�r'r�r'r'r(�readliner�zMockFile.readlinecCr�r�r'�r r'r'r(�close"r�zMockFile.closer�)rIrrJr7r�r�r'r'r'r(r�s

r�c@�eZdZdd�ZdS)�MockHeaderscCst|���Sr�)rA�values)r rr'r'r(�
getheaders'szMockHeaders.getheadersN)rIrrJr�r'r'r'r(r�&�r�c@s&eZdZddd�Zdd�Zdd�ZdS)	�MockResponseNcCs.tj�||�||||f\|_|_|_|_dSr�)�io�StringIO�__init__�code�msgrPrQ)r r�r�rPr�rQr'r'r(r�,s zMockResponse.__init__cC�|jSr�rOr�r'r'r(�info0�zMockResponse.infocCr�r��rQr�r'r'r(�geturl3r�zMockResponse.geturlr�)rIrrJr�r�r�r'r'r'r(r�+s
r�c@�eZdZdd�Zdd�ZdS)�
MockCookieJarcC�
||_dSr�)�ach_req)r rr'r'r(�add_cookie_header8�
zMockCookieJar.add_cookie_headercCs|||_|_dSr�)�ec_req�ec_r)r rrr'r'r(�extract_cookies;r�zMockCookieJar.extract_cookiesN)rIrrJr�r�r'r'r'r(r�7sr�c@r�)�
FakeMethodcCs||_||_||_dSr�)�	meth_name�handle�action)r r�r�r�r'r'r(r�@s
zFakeMethod.__init__cGs|j|j|jg|�R�Sr�)r�r�r�)r r�r'r'r(�__call__EszFakeMethod.__call__N)rIrrJr�r�r'r'r'r(r�?sr�c@r)
�MockHTTPResponsecCs"||_||_||_||_d|_dS)N��)�fpr��statusrCr�)r r�r�r�rCr'r'r(r�Js

zMockHTTPResponse.__init__cCsdS)N�r'r�r'r'r(r7Qr�zMockHTTPResponse.readcCsiSr�r'r�r'r'r(r�Tr�zMockHTTPResponse.infocCr�r�r�r�r'r'r(r�Wr�zMockHTTPResponse.geturlN)rIrrJr�r7r�r�r'r'r'r(r�Is
r�c@sTeZdZdd�Zejfdd�Zdd�Zddd	�Zdd
d�dd
�Z	dd�Z
dd�ZdS)�
MockHTTPClasscCs(d|_g|_d|_d|_d|_i|_dS)NrF)�level�req_headersr��raise_on_endheadersZsock�_tunnel_headersr�r'r'r(r�\s
zMockHTTPClass.__init__cCs||_||_|Sr�)�hostr�)r r�r�r'r'r(r�dszMockHTTPClass.__call__cCr�r�)r�)r r�r'r'r(�set_debuglevelir�zMockHTTPClass.set_debuglevelNcCs(||_||_|r
||_dS|j��dSr�)�_tunnel_hostZ_tunnel_portr��clear)r r��portrPr'r'r(�
set_tunnells

zMockHTTPClass.set_tunnelF)�encode_chunkedcCsP||_||_|dur|j|��7_|j��|r||_||_|jr&t��dSr�)	�method�selectorr�r�sortr�r�r��OSError)r r�rQ�bodyrPr�r'r'r(rts
�zMockHTTPClass.requestcCstt�idd�S)Nr��OK)r�r�r�r'r'r(�getresponse��zMockHTTPClass.getresponsecCr�r�r'r�r'r'r(r��r�zMockHTTPClass.closerl)rIrrJr�r�r�r�r�r�rr�r�r'r'r'r(r�[s
�
r�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�MockHandler��cCs|�|�dSr�)�_define_methods)r �methodsr'r'r(r���zMockHandler.__init__cCsJ|D] }t|�dkr|\}}n|d}}t|||j�}t|j||�qdS)N�)�lenr�r��setattr�	__class__)r r��specrr�Zmethr'r'r(r��s

�zMockHandler._define_methodscOs�|jj�||||f�|durdS|dkr|S|dkr$tddid�}|S|dkr,td�S|�d�r`||�d	�d
d�}zt|�}Wn	tyKYnwtddid�}|j�	d|d||di�S|d
krjt
j	�d��dS)N�return self�return responser�r�r��return requestzhttp://blah/r� ��httpr�raiserN)�parent�calls�appendr�r�
startswith�rfind�intr0rr-rD)r Zfn_namer�r��kwds�resr�r'r'r(r��s,
��zMockHandler.handlecCr�r�r'r�r'r'r(r��r�zMockHandler.closecCs||_g|j_dSr�)r�r�)r r�r'r'r(�
add_parent�szMockHandler.add_parentcCst|d�sdS|j|jkS)N�
handler_orderT)�hasattrr�)r �otherr'r'r(�__lt__�s
zMockHandler.__lt__N)
rIrrJr�r�r�r�r�r�r�r'r'r'r(r��s	r�cCsd	g}d}|D](}Gdd�dt�}||�}|j|7_|�|�|d}|�|�|�|�q|S)Nrc@�eZdZdS)z6add_ordered_mock_handlers.<locals>.MockHandlerSubclassN�rIrrJr'r'r'r(�MockHandlerSubclass��r�r�)r�r�r�r��add_handler)�opener�	meth_spec�handlersr��methsr�r>r'r'r(�add_ordered_mock_handlers�s

r�cGst�}|D]}|�|�q|Sr�)rr�)Zhandler_instancesr�r>r'r'r(�build_test_opener�sr�c@�$eZdZdd�Zdd�Zdd�ZdS)�MockHTTPHandlercCs||_||_|��dSr�)r�rP�reset)r r�rPr'r'r(r���zMockHTTPHandler.__init__cCsd|_g|_dS)Nr)�_count�requestsr�r'r'r(r���
zMockHTTPHandler.resetcCs�ddl}ddl}|j�|�|��|jdkr6|jd|_tjj|j	}|�
|j�}|j�
d|t�|j	||�S||_|�
d�}tdd|d|���S)Nrr�r��

r�r�r�)�email�copyr�r�Zdeepcopyr�r��client�	responsesr�Zmessage_from_stringrPr�rr�r]r��get_full_url)r r]r�r�rr�r'r'r(�	http_open�s
�
zMockHTTPHandler.http_openN�rIrrJr�r�rr'r'r'r(r��sr�c@seZdZddd�Zdd�ZdS)�MockHTTPSHandlerrcCstjjj||d�t�|_dS)N��
debuglevel)r-r�AbstractHTTPHandlerr�r��httpconn)r rr'r'r(r�szMockHTTPSHandler.__init__cCs|�|j|�Sr�)�do_openr�r r]r'r'r(�
https_openr�zMockHTTPSHandler.https_openN)r)rIrrJr�r
r'r'r'r(rs
rc@r�)�MockHTTPHandlerCheckAuthcCs||_d|_dS�NF)r��has_auth_header)r r�r'r'r(r�r�z!MockHTTPHandlerCheckAuth.__init__cCs
d|_dSr)r
r�r'r'r(r�r�zMockHTTPHandlerCheckAuth.resetcCs6|�d�rd|_tjj|j}t|j|t�d|���S)N�
AuthorizationTr�)	rVr
r�r�r�r�r�r�r)r r]rr'r'r(rs
z"MockHTTPHandlerCheckAuth.http_openNrr'r'r'r(rsrc@r�)�MockPasswordManagercCs||_||_||_||_dSr�)�realmrQ�userra)r rZurirrar'r'r(rs#s
z MockPasswordManager.add_passwordcCs||_||_|j|jfSr�)�target_realm�
target_urlrra)r rZauthurir'r'r(rt)r�z&MockPasswordManager.find_user_passwordN)rIrrJrsrtr'r'r'r(r"src@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�OpenerDirectorTestscCs(Gdd�dt�}|�tt�j|��dS)Nc@r�)z<OpenerDirectorTests.test_add_non_handler.<locals>.NonHandlerNr�r'r'r'r(�
NonHandler2r�r)�objectr/�	TypeErrorrr�)r rr'r'r(�test_add_non_handler1s
�z(OpenerDirectorTests.test_add_non_handlercCs\ddlm}t�}ddgdgg}t||�|�tj���dD]}|�||j	|d�qdS)Nr)rD)rr�)Z
proxy_openr�)Zredirect_requestr�)Zdo�proxy�redirectz://example.com/)
�urllib.errorrDrr�r�r-rZUnknownHandlerr/r�)r rD�or��schemer'r'r(�test_badly_named_methods7s	�
�z,OpenerDirectorTests.test_badly_named_methodsc
Cs�t�}gd�dgdgdgg}t||�}td�}|�|�}|�||d�|ddf|ddfg}t||j�D]\}}|\}	}
}}|�|	|
f|�|�||f�q6dS)N)r�ftp_open�http_error_302r�rr�r_r�rr)rr�rr�r�zipr�)
r rr�r�r]�rr��expected�got�handlerrr�r�r'r'r(�test_handledLs �

�z OpenerDirectorTests.test_handledcCs�t�}g}dgdfdgdffD]\}}Gdd�dt�}||�}||_|�|�|�|�q|�d�|�|jdd|d�|�|jdd|d�dS)	Nr!r�rrc@r�)zCOpenerDirectorTests.test_handler_order.<locals>.MockHandlerSubclassNr�r'r'r'r(r�kr�r�r_r�)rr�r�r�r�r�rr�)r rr�r�r�r�r>r'r'r(�test_handler_orderfs�

z&OpenerDirectorTests.test_handler_ordercCsZt�}dgdgg}t||�}td�}|�tjj|j|�|�|j	|dd|fifg�dS)N)rr�r!r_rr)
rr�rr/r-rrDr�rr�)r rr�r�r]r'r'r(�
test_raisexs�
"zOpenerDirectorTests.test_raisecCs�t�}dgddggd�dgg}t||�}td�}|�|�|dd|ff|dd|tjd	d
iffg}t||j�D]\}}|\}}	}
|�||	f|dd��|�|
|d�q8dS)N)rz	error 302)Zhttp_error_400r�r))r r�Zhttp_error_303Z
http_errorr r_rr��.r�)	rr�rr�rZ	ALWAYS_EQr"r�r)r rr�r�r]r�r$r%r&Zmethod_namer�r'r'r(�test_http_error�s&�

��
�z#OpenerDirectorTests.test_http_errorcCst�}ddgddgg}t||�}td�}|�|�|ddf|ddf|ddf|ddfg}t|j�D]O\}\}}}	}
|dkr[|�||f||�|�t|	�d�|�|	dt�q4|�||f||�|�t|	�d�|�|	dt�|	ddur�|�|	dt	�q4dS)	N)�http_requestr�)�
http_responser�r_rr,r�r-r�)
rr�rr��	enumerater�rr��assertIsInstancer�)r rr�r�r]r�r}r&rr�r�r'r'r(�test_processors�s4���

���z#OpenerDirectorTests.test_processorsN)
rIrrJrrr'r(r)r+r0r'r'r'r(r/s
rcCsXz|�d�Wntyt�d��wtj�|�}tjdkr*|�	d�r*|dd�}|S)Nzutf-8zpath is not encodable to utf8rz///r�)
�encode�UnicodeEncodeError�unittestZSkipTestr-rrrrr�)r2�urlpathr'r'r(�sanepathname2url�s
�r5c@sxeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Ze� e!j"d9kd:�d;d<��Z#e� e$j%d=kd>�d?d@��Z&dAdB�Z'dCdD�Z(dEdF�Z)dGdH�Z*dIdJ�Z+dKdL�Z,dMdN�Z-dOdP�Z.dQdR�Z/dSdT�Z0dUdV�Z1dWS)X�HandlerTestscs�Gdd�d��G�fdd�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]f\	}}}}}	}
}}}
t|�}d|_|�	|�}|�
|j|�|�
|j|	�|�
|j
t�|��|�
|j|�|�
|j|�|�
|jj|�|�
|jj|
�|��}|�
|�d�|
�|�
t|d�t|��qndS)Nc@r�)z-HandlerTests.test_ftp.<locals>.MockFTPWrappercSr�r��r��r r�r'r'r(r��r�z6HandlerTests.test_ftp.<locals>.MockFTPWrapper.__init__cSs$|||_|_t�|j�t|j�fSr�)�filename�filetyper�r�r�r�)r r9r:r'r'r(�retrfile�sz6HandlerTests.test_ftp.<locals>.MockFTPWrapper.retrfilecSr�r�r'r�r'r'r(r��r�z3HandlerTests.test_ftp.<locals>.MockFTPWrapper.closeN)rIrrJr�r;r�r'r'r'r(�MockFTPWrapper�sr<cs&eZdZdd�Zejf�fdd�	ZdS)z-HandlerTests.test_ftp.<locals>.NullFTPHandlercSr�r�r7r8r'r'r(r��r�z6HandlerTests.test_ftp.<locals>.NullFTPHandler.__init__cs4|||_|_|||_|_||_�|j�|_|jSr�)r�passwdr�r��dirsr��
ftpwrapper)r rr=r�r�r>r��r<r'r(�connect_ftp�s
z9HandlerTests.test_ftp.<locals>.NullFTPHandler.connect_ftpN)rIrrJr�r�r�rAr'r@r'r(�NullFTPHandler�s�rBrzrheum rhaponicumz ftp://localhost/foo/bar/baz.html�	localhostr��Irirjzbaz.htmlz	text/htmlz'ftp://parrot@localhost/foo/bar/baz.htmlZparrotz*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)r-rZ
FTPHandler�ftplibr�r�ZFTP_PORTrr�rrrr=r�r��
gethostbynamer�r>r?r9r:r��getr�r�)r rBrJr�r>rQr�r�rr=Ztype_r>r9Zmimetyper]r#rPr'r@r(�test_ftp�sZ
�
�
�
�

���
�zHandlerTests.test_ftpc
Cs�ddl}tj��}t�}|_tj}tt	j
�|��}d}d|d|dt�
d�|fg}z	t�
t���}WntjyAd}Ynw|rM|�d||f�|D]w}	t|d�}
zEz|
�|�W|
��n|
��w|�t|	��}z|��}|��}
|��}W|��n|��wt	�|�}|jj|jd	d
�}Wt	�|�nt	�|�w|�||�|�|
dd�|�|
d
d�|�|
d|�|�||	�qOd|dddt�
d�t	��|fdt	��|ffD]1}	z)t|d�}
z|
�|�W|
��n|
��w|� tj!j"|jt|	��Wt	�|�q�t	�|�wtj��}t�}|_dD]9\}	}t|	�}z|�|�Wntj!j"�y?|�#|�Ynw|�$|j%|�|�|j&d�|�|j&dk|��qdS)Nrs
hello, world
zfile://localhost%sr+zfile://%s%srCr��wbT)ZusegmtrHz
text/plainrIr~z
Last-modifiedzfile://localhost:80%szfile:///file_does_not_exist.txtz)file://not-a-local-host.com//dir/file.txtzfile://%s:80%s/%sz,file://somerandomhost.ontheinternet.com%s/%s))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)'Zemail.utilsr-rZFileHandlerr�r�r�TESTFNr5rr2r3r�rKZgethostnameZgaierrorr�r��writer�Z	file_openrr7r�r��statZutilsZ
formatdate�st_mtime�remover�getcwdr/rrDrY�assertIsr]�type)r r�r>rrPr4Ztowrite�urlsZ	localaddrrQr8r#r�rPZrespurlZstatsZmodifiedrOr]r'r'r(�	test_files�
��



�
��	


�
��zHandlerTests.test_filecCs`tj��}t�}|_d}dD]q\}}t||ddi�}d|_|�dd�t�}|�	||�}|j
|j|j|j
|j|jdkdf|��}	|	j|	j|�|�
�|�|�|jd	�|�|jd
�|�|j|�|�|jd�|�|jgd��|�|j|�qd
|_|�tjj|j	||�tdd�}|�t|j|�dg|_dD]�}td|�}t ddid�}|�|�}
|dur�|�!d|j"�|�!d|j"�n|�|j"dd�|�|j"dd�|�|j"dd	�|�|j"dd�|�dd�|�dd�|�dd�|�dd�|�|�}
|�|j"dd�|�|j"dd�|�|j"dd�|�|j"dd�q�dS)Nr_))�GETN)�POSTsblah�Foorj�Spam�eggsr�r�rhrr*))Z
Connectionr�)r\rj�r]r^TZbadpostr_)�Nr�rIrH�0z!application/x-www-form-urlencoded�HostrirS)#r-rrr�r�rr�r\r�rr7r�r�r�r�r�rL�__contains__rr�r�r�r�r�r�r�r/rrDr�do_request_r�r��assertNotIn�unredirected_hdrs)r r>rrQr�r�r]r�r#�hdrs�newreqr'r'r(�	test_httpjsf
�


�
�zHandlerTests.test_httpc	Cstj��}t�}|_tjddd�}|j}|��|�	t
j|�t|d��&}t
d|i�}|�|�}|�d�}|�|d�|�|�d��Wd�n1sNwYt|d��)}t
d|d	d
i�}|�|�}|�t|�d��d
�|�|�d��Wd�dS1s�wYdS)Nzw+bF)�mode�delete�rbr_�Transfer-encoding�chunkedrI�Content-Length�)r-rrr�r��tempfileZNamedTemporaryFilerr�r,r�unlinkr�rrdr[rrYrVr�)	r r>r�file_objZ	file_pathr8r]rh�ter'r'r(�test_http_body_file�s&


�
"�z HandlerTests.test_http_body_filecCs�tj��}t�}|_t��}td|i�}|�|�}|�	|�
d�d�|�|�d��ddi}td||�}|�|�}|�	t
|�
d��d�|�|�d��|��dS)Nr_rmrnrIrorp)r-rrr�r�r��BytesIOrrdrr[rYrVr�r�)r r>rrsr]rhrPr'r'r(�test_http_body_fileobj�s


z#HandlerTests.test_http_body_fileobjc	Cs�tj��}t�}|_tjddg}iddifD]F}tj|tj	d��4}t
d|j|�}|�|�}|sC|�
|�d�d�|�
|�d�d	�n|�
t|�d��d�Wd�n1sXwYqdS)
Nz-c�passrorp)�stdoutr_rIrmrn)r-rrr�r��sys�
executable�
subprocess�Popen�PIPErryrdrr[r�)r r>r�cmdrP�procr]rhr'r'r(�test_http_body_pipe�s&

������z HandlerTests.test_http_body_pipecCs�tj��}t�}|_dd�}iddifD].}td|�|�}|�|�}|s8|�|�d�d�|�|�d�d�q|�t	|�d��d�qdS)	Ncss�dVdS)Nsoner'r'r'r'r(�
iterable_body�s�
z;HandlerTests.test_http_body_iterable.<locals>.iterable_bodyro�r_rIrmrn)
r-rrr�r�rrdrr[r�)r r>rr�rPr]rhr'r'r(�test_http_body_iterable�s

��z$HandlerTests.test_http_body_iterablecCsHtj��}t�|_|�tdd��}|�|�d�d�|�	|�
d��dS)Nr_r'rmrnrI)r-rrr�r�rdrrr[rYrV)r r>r]r'r'r(�test_http_body_empty_seqs

z%HandlerTests.test_http_body_empty_seqcCshtj��}t�}|_t�dgd��}iddifD]}td||�}|�|�}|�t	|�
d��d�qdS)NrD)r�r���ro�r_rI)r-rrr�r��arrayrrdrr�r[)r r>rZiterable_arrayrPr]rhr'r'r(�test_http_body_arrays

�z!HandlerTests.test_http_body_arraycCs6t�}tdd�}|�|�|�d�|�|jd�dS)Nr�rzhttps://www.example.com)rrr�r�rZ_debuglevel)r rr>r'r'r(�test_http_handler_debuglevels



z)HandlerTests.test_http_handler_debuglevelcCsztj��}t�|_d}gd�}|D])}t||�}|�|�}|�|jdd�|�	dd�|�|�}|�|jdd�qdS)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.htmlrbrhzsomeproxy:3128)
r-rrr�r�rrdrrf�	set_proxy)r r>r�Zds_urlsZds_urlZds_reqZ	np_ds_reqZp_ds_reqr'r'r(�test_http_doubleslash"s



�z"HandlerTests.test_http_doubleslashcCshgd�}td�}|D]'}||_t|�}|�|��|�|�|jp!d|j�|�t|���j|j�q
dS)N)zhttp://example.com?foo=bar#bazz)http://example.com?foo=bar&spam=eggs#bashrLrLr�)r�full_urlrrr�fragmentZquery)r rXr#rQZparsedr'r'r(�test_full_url_setter=s�z!HandlerTests.test_full_url_settercCs6td�}|`|�|j�|�|j�|�|jd�dS)N�http://www.example.comr�)rr�rZr�rr�)r r#r'r'r(�test_full_url_deleterTs
z"HandlerTests.test_full_url_deletercCsztj��}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�)
r-rrr�r�rrdrr�r�)r r>Z	weird_urlr]rhZurl_without_pathr'r'r(�test_fixpath_in_weirdurls[s


z&HandlerTests.test_fixpath_in_weirdurlscCstj��}t�}|_d}t|�}tddid|�}|�||�}|�||�|�	t
|d��tddid|�}|�||�}|�||�|�	t
|d��tdd	id|�}|�||�}|�||�|�	t
|d��td
did|�}|�|�||��|�|j
d�|�|j||d
dif�dS)
Nr_r�r�r�r���ZAccepted��zPartial contenti�zBad gatewayr�)r-rZHTTPErrorProcessorr�r�rr�r-rVrYr�rZrr�r�)r r>rrQr]r#�newrr'r'r(�test_errorsns(
zHandlerTests.test_errorscCs�t�}tj�|�}t�|_td�}tddid�}|�|�}|�	|j
|�|�	|j
|�|�|jd�|�
|j�|�||�}|�	|j|�|�	|j|�|�	||�dS)Nr_r�r�r�rh)r�r-r�HTTPCookieProcessorr�r�rr�r,rVr�r�origin_req_hostrYZunverifiabler-r�r�)r �cjr>r]r#rhr�r'r'r(�test_cookies�s
zHandlerTests.test_cookiesc
CsTd}d}tj��}t�}|_dD]�}dD]�}t|d|�}t||�}tj|_	|�
dd�|dur;|�
dtt|���|�
d	d
�z||t�|dtd|i��Wntjjyf|�|d
�|�|�Ynw|�|j��|�z|�|j��d�Wnty�|�|jj�Ynwdd�|jjD�}	|�d|	�|�d|	�|�|jjdd�|�d	|jj�|�d	|jj�qqt|�}tj|_	|fdd�}
t|dd�}d}tj|_	z	|
||d�|d}q�tjjy�|�|tjjj�Ynwt|dd�}d}tj|_	z	|
||d|�|d}�qtjj�y)|�|tjjj�YdSw)N�http://example.com/a.htmlzhttp://example.com/b.html)i-r*i/�3)Nz
blah
blah
z
http_error_%sZNonsensezviking=withholdror]rp�Blah�locationr�rZcSsg|]}|���qSr')�lower)�.0�xr'r'r(�
<listcomp>�sz.HandlerTests.test_redirect.<locals>.<listcomp>zcontent-lengthzcontent-typec	Ss |�|t�ddtd|i��dS)Nr*r�r�)r r�r�)r>r]rQr'r'r(r�s
�z,HandlerTests.test_redirect.<locals>.redirectrh)r�rr�r_zhttp://example.com/%d)r-r�HTTPRedirectHandlerr�r��getattrrr�r�r�rWrFr�r\r�r�r�	HTTPErrorr�assertIsNotNoner]r�
get_method�AttributeErrorrYr�rPrerfZmax_repeatsZmax_redirections)r �from_urlZto_urlr>rr�r�r�r]rPrr�r'r'r(�
test_redirect�s~


�����!���
��zHandlerTests.test_redirectcCs�d}gd�}gd�}d}tj��}t�}|_t|�}tj|_|D]}|d|}	|�	tj
j|j|t
�ddtd|	i��q!|D]}|d|}
|�|t
�dd	td|
i��|�|j��|
�q?dS)
Nr�)r��httpsrO)�fileZimapZldapzexample.com/b.htmlz://r*zSecurity Loopholer��That's fine)r-rr�r�r�rr�r�r�r/rr�r r�r�rr]r)r r�Z
valid_schemesZinvalid_schemesZschemeless_urlr>rr]rZinvalid_url�	valid_urlr'r'r(�test_invalid_redirect�s*


�
��z"HandlerTests.test_invalid_redirectc	Csnd}d}tj��}t�}|_t|�}tj|_tj	�
||�}|�|t�ddt
d|i��|�|j��|�dS)Nr�z/b.htmlr*r�r�)r-rr�r�r�rr�r�r�rZurljoinr r�r�rr]r)r r�Zrelative_urlr>rr]r�r'r'r(�test_relative_redirect�s

�z#HandlerTests.test_relative_redirectc	Cs�ddlm}ddlm}|�}||dd�tdd�}tj��}tj��}tj�	|�}t
||||�}|�d�|�|j
�d��dS)	Nr)�	CookieJar)�interact_netscapezhttp://www.example.com/z	spam=eggsr*z%Location: http://www.cracker.com/

ZCookie)Zhttp.cookiejarr�Ztest.test_http_cookiejarr�r�r-r�HTTPDefaultErrorHandlerr�r�r�r�rYr]rV)	r r�r�r��hh�hdeh�hrhZcprr'r'r(�test_cookie_redirects



z!HandlerTests.test_cookie_redirectcCsTd}tdd|�}tj��}tj��}t|||�}|�d�}|�|��|�	��dS)Nz(http://www.example.com/index.html#OK

r*z
Location: r�)
r�r-rr�r�r�r�rr��strip)r Zredirected_urlr�r�r�rr�r'r'r(�test_redirect_fragments


z#HandlerTests.test_redirect_fragmentcs|��tjj�tjj�d}t�|�tj_��t	tjd��t
d�����fdd�}|tjj_tj�d�}��|�
�d�dS)Ns(HTTP/1.1 302 Found
Location: ?query

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

Hello!)r�nextrr�Zfakedata)�connr�rQ�pos�kw�Z
real_classr rXr'r(r(sz3HandlerTests.test_redirect_no_path.<locals>.requestzhttp://python.org/pathzhttp://python.org/path?query)r,r-rr.r�r�r�r�fakehttpr��iterr1rr�)r Z	response1rr�r'r�r(�test_redirect_no_paths
z"HandlerTests.test_redirect_no_pathc
	Cs�Gdd�dtjj�}|�}tj�|�}d}|D]>\}}|�t|���+t�d|d�|_|�	d�}d|d}|j
}	|�|	�|�t|	��Wd�n1sPwYqdS)	Nc@r�)z4HandlerTests.test_redirect_encoding.<locals>.HandlercSs(|�|j|�}|jj|_t�d�|_|S)Ns)HTTP/1.1 200 OK
Content-Length: 3

123)r�
connectionZbuf�last_bufrr�)r r]�resultr'r'r(r5s
�z>HandlerTests.test_redirect_encoding.<locals>.Handler.http_openN)rIrrJrr'r'r'r(�Handler4r�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

r_sGET � )
r-r�HTTPHandler�build_opener�subTest�reprrr�r�r�r�rUr�)
r r�r&r�r?r�r�rr$rr'r'r(�test_redirect_encoding1s(���
���z#HandlerTests.test_redirect_encodingcCs�d}t|d�t|d�fD]A}t�}tj�|�}|�|�dgg}t||�}td�}|�|j	d�|�
|�|�|j	|�|�|ddfgd	d
�|jD��qdS)N�proxy.example.com:3128�r�)ZHTTP)rr�zhttp://acme.example.com/zacme.example.comrrcS�g|]}|dd��qS�rr�r'�r��tupr'r'r(r�d�z+HandlerTests.test_proxy.<locals>.<listcomp>)�dictrr-r�ProxyHandlerr�r�rrr�r�r�)r r#rer�phr�r�r]r'r'r(�
test_proxyTs 
�

��zHandlerTests.test_proxycCs�dtjd<t�}tj�tdd��}|�|�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.orgr�r��r�environrr-rr�r�r�rrr�r��r rr�r]r'r'r(�test_proxy_no_proxyfs



z HandlerTests.test_proxy_no_proxycCsfdtjd<t�}tj�tdd��}|�|�td�}|�	|j
d�|�|�|�	|j
d�tjd=dS)N�*r�r�r�r�r�r�r�r'r'r(�test_proxy_no_proxy_allus


z$HandlerTests.test_proxy_no_proxy_allcCs�t�}tj�tdd��}|�|�dgg}t||�}td�}|�|j	d�|�
|�|�|j	d�|�|ddfgdd	�|jD��dS)
Nr��r�)r
r��https://www.example.com/�www.example.comrr
cSr�r�r'r�r'r'r(r��r�z1HandlerTests.test_proxy_https.<locals>.<listcomp>)rr-rr�r�r�r�rrr�r�r�)r rr�r�r�r]r'r'r(�test_proxy_https�s
�

�zHandlerTests.test_proxy_httpscCs�t�}tj�tdd��}|�|�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)rr-rr�r�r�rrrWrr�rZr�r�rerr�rEr�r[)r rr�Z
https_handlerr]r'r'r(�$test_proxy_https_proxy_authorization�s(


��z1HandlerTests.test_proxy_https_proxy_authorizationrzonly relevant for WindowscCs�d}t}dD]
}|�|||�d|�qdD]
}|�|||�d|�qd}|�|d|�d|�|�|d|�d|�d	D]
}|�|||�d
|�q>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)rhzwww.example.org�example.netz192.168.0.2�!expected bypass of %s to be Falsezexample.com; <local>rhr�)�testrCz.expect <local> to bypass intranet address '%s')rrUrY)r Zproxy_overrideZproxy_bypassr�r'r'r(�test_winreg_proxy_bypass�s0�������z%HandlerTests.test_winreg_proxy_bypass�darwinzonly relevant for OSXcCs�dgd�d�}dD]
}|�t||�d|�q	dD]
}|�t||�d|�qdgd�}|�td	|��dd
dgd�}d}|�t||�d|�d
}|�t||�d|�dS)NF)�foo.barz	*.bar.com�	127.0.0.1z10.10z10.0/16)Zexclude_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.1Znotinbypassr�Tr�z10.0.0.0/40z172.19.10.0/24z172.19.10.5z10.0.1.5)rUr
rY)r Zbypassr�r'r'r(�test_osx_proxy_bypass�s0���
���z"HandlerTests.test_osx_proxy_bypasscCs�|j||d��7t�}t�}tj�|�}d�|�d}td|�}|�|�|�|�|�	||d|||dd�Wd�dS1sAwYdS)N)rrPz
r��r�!http://acme.example.com/protected)
r�rrr-rr	�joinr�r��_test_basic_auth)r rPrr��password_manager�auth_handlerr��http_handlerr'r'r(�check_basic_auth�s



�"�zHandlerTests.check_basic_authc

Cs,d}d}d|�d�}d|�d�}d}d|�d�}d|�d�d|�d�d|�d	�|�d
|��|�d
|��|�d
|��|�d
|��|�d
|��fD]}d|��g}|�||�qGt�dtf��d
|��g}|�||�Wd�n1stwY||g||g||gfD]}	dd�|	D�}|�||�q�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=cSsg|]}d|���qS)rr')r�Z	challenger'r'r(r�s�z0HandlerTests.test_basic_auth.<locals>.<listcomp>)r�rZcheck_warnings�UserWarning)
r rZrealm2�basicZbasic2Zother_no_realm�digestZ	realm_strrPZ
challengesr'r'r(�test_basic_auth�s@


������zHandlerTests.test_basic_authc
Csvt�}tj�tdd��}|�|�t�}tj�|�}d}tdd|�}|�|�|�|�|�	||d|||dd�dS)Nr�r��
ACME Networksi�z(Proxy-Authenticate: Basic realm="%s"

r�z&http://acme.example.com:3128/protected)
rr-rr�r�r�rZProxyBasicAuthHandlerr�r�)r r�r�r�r�rr�r'r'r(�test_proxy_basic_auths 
�


�z"HandlerTests.test_proxy_basic_authc

Cs�Gdd�dt�}Gdd�dtjj�}Gdd�dtjj�}|�}t�}||�}||�}d}tdd	|�}	|�|�|�|�|�|	�|�||d
||	|dd�|�	|j
dd
gd�dS)Nc@r�)zQHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirectorcSst�|�g|_dSr�)rr��recordedr�r'r'r(r�7s

zZHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.__init__cSs|j�|�dSr�)r	r�)r r�r'r'r(�record;r�zXHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.recordN)rIrrJr�r
r'r'r'r(�RecordingOpenerDirector6src@r�)zOHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandlerc_�,|j�d�tjjj|g|�Ri|��dS)Nr)r�r
r-r�HTTPDigestAuthHandler�http_error_401�r r�r�r'r'r(r?��
�z^HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandler.http_error_401N�rIrrJrr'r'r'r(�TestDigestAuthHandler>r�rc@r�)zNHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandlerc_r)Nr)r�r
r-rr	rrr'r'r(rErz]HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandler.http_error_401Nrr'r'r'r(�TestBasicAuthHandlerDr�rrr��&WWW-Authenticate: Basic realm="%s"

rr�rrr�)rr-rr
r	rr�r�r�rr	)
r rrrr�r�Zdigest_handlerZ
basic_handlerrr�r'r'r(�#test_basic_and_digest_auth_handlers-s(	�



�z0HandlerTests.test_basic_and_digest_auth_handlerscC�Dt�}tj�d�}tdd�}|�|�|�|�|�t|jd�dS)Nr�zWWW-Authenticate: Kerberos

r�)	rr-rr
r�r�r/r0r�)r r�Zdigest_auth_handlerr�r'r'r(�$test_unsupported_auth_digest_handler_s�

z1HandlerTests.test_unsupported_auth_digest_handlercCr)Nr�zWWW-Authenticate: NTLM

r�)	rr-rr	r�r�r/r0r�)r r�Zbasic_auth_handlerr�r'r'r(�#test_unsupported_auth_basic_handleris�

z0HandlerTests.test_unsupported_auth_basic_handlerc	CsHddl}	d\}
}|�|||
|�|�||j�|�||j�|�|
|j�|�||j�|�|�|�|j|�|�|j	|�|�t
|j�d�|�|jd�
|��td|
|fd�}d|	�|�����}
|�|jd�|�|
�|�|jdj||
�d|_|_|��|�|�|�t
|j�d�|�|jd�
|��dS)Nr�ZwileZcoyoter�z%s:%s�asciizBasic r�)�base64rsrrrQrrar�rrr�r�rYrV�bytesZencodebytesr��decoder[rfr�)r r�r�Zauth_headerrr�r��request_urlZ
protected_urlrrraZuserpassZauth_hdr_valuer'r'r(r�ss6
���
zHandlerTests._test_basic_authcCs�d\}}d}td�}t�}t|�}|jd|||dd�|�|�|��|�|�|d��|�|�|d��t�}|�|�|�|�|�	|�|�|j
�dS)Nrr�r�T)�is_authenticatedz/nestedZplain)rr
r	rsrUrrYrr�r�r
)r rrarr��pwd_manager�auth_prior_handlerr�r'r'r(�test_basic_prior_auth_auto_send�s 
�


z,HandlerTests.test_basic_prior_auth_auto_sendc
Cs�d\}}d}d}t�}t|�}|�||||�|�|�}|�|�t�}|�|�tddd�}	|�|	�|�|�|�|�}|�	|�t
d�}	|�|	j�t�}|�|�|�|	�|�|�|�	|	j�dS)Nrr�ZACMEr�rr�)r
r	rsrrYrr�r�r�rUrr
)
r rrarrr r!Zis_authr�r�r'r'r(�.test_basic_prior_auth_send_after_first_success�s0


�






z;HandlerTests.test_basic_prior_auth_send_after_first_successc	Cs�	dD]C\}}d�|�}t�|��|�}tj��}td�}d|_|�	||��}|�
�Wd�n1s6wY|�|jj
d�|��qdS)N))zConnection: close�data)zTransfer-Encoding: chunkeds4
data
0

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

�
http://dummy/zConnection not closed with {!r})�formatrr�r1r-rrrr�rr7rU�fakesock�closed)r Ztransferr��headerr�r&r]Zrespr'r'r(�test_http_closed�s


�
��zHandlerTests.test_http_closedcCsr	t�d�}tj��}td�}d|_|�tj	j
��|�||�Wd�n1s*wY|�|j
jd�dS)Nr`r%zConnection not closed)rr�r-rrrr�r/r�r�Z
BadStatusLinerrUr'r()r r�r&r]r'r'r(�test_invalid_closed�s

�z HandlerTests.test_invalid_closedN)2rIrrJrMrYrirurwr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3Z
skipUnlessrrr�rz�platformr�r�rrrrrr�r"r#r*r+r'r'r'r(r6�sX@\B
J
	#

!-2

%(r6c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�	MiscTestscs"|�t�fdd�|jD���dS)Nc3s�|]}|j�kVqdSr�)r�)r�r>��
handler_classr'r(�	<genexpr>�s��z/MiscTests.opener_has_handler.<locals>.<genexpr>)rU�anyr�)r r�r/r'r.r(�opener_has_handler�s�zMiscTests.opener_has_handlercCs(Gdd�dtjj�}Gdd�dtjj�}Gdd�dtjj�}tjj}|||�}|�||�|�||�|||��}|�||�|�||�||�}|�||�|�}|�|tjj�|tjj�}|�|tjj�|tj���}|�|tjj�Gdd�dtjj�}|||�}|�||�|�||�dS)	Nc@r�)z2MiscTests.test_build_opener.<locals>.MyHTTPHandlerNr�r'r'r'r(�
MyHTTPHandler�r�r3c@r�)z/MiscTests.test_build_opener.<locals>.FooHandlercSr�r�r'r�r'r'r(�foo_openr�z8MiscTests.test_build_opener.<locals>.FooHandler.foo_openN)rIrrJr4r'r'r'r(�
FooHandlerr�r5c@r�)z/MiscTests.test_build_opener.<locals>.BarHandlercSr�r�r'r�r'r'r(�bar_openr�z8MiscTests.test_build_opener.<locals>.BarHandler.bar_openN)rIrrJr6r'r'r'r(�
BarHandlerr�r7c@r�)z7MiscTests.test_build_opener.<locals>.MyOtherHTTPHandlerNr�r'r'r'r(�MyOtherHTTPHandler"r�r8)r-rr��BaseHandlerr�r2)r r3r5r7r�rr8r'r'r(�test_build_opener�s,

zMiscTests.test_build_openercCs�	d}d}}}d}tj�|||||�}|�t|d��|�|jd�|�t|d��|�|jd�d|j|j	f}|�t
|�|�d|j|j	f}|�t|�|�dS)Nzsomething bad happenedzContent-Length: 42rCrPzHTTP Error %s: %sz<HTTPError %s: %r>)r-rr�rUr�rrCrPr�r�rFr�)r r�rQr�r�rgrGZexpected_errmsgr'r'r(�test_HTTPError_interface)sz"MiscTests.test_HTTPError_interfacecCs>tj�ddddd�}|�t|dd�d�|�|j��t�dS)NrQi�zMETHOD NOT ALLOWEDZ	__notes__r')	r-rr�rr�r/r�r7r)r r�r'r'r(�
test_gh_98778;szMiscTests.test_gh_98778cCs:gd�}|D]\}}|�t|�|�q|�ttd�fdS)N)�r�)NNNr��r�)NNNr�r=r>)zjoe:password@proxy.example.com)Nr`rar�)z#joe:password@proxy.example.com:3128)Nr`rar�)zhttp://proxy.example.com/)r�NNr�)zhttp://proxy.example.com:3128/)r�NNr�)z&http://joe:password@proxy.example.com/�r�r`rar�)z*http://joe:password@proxy.example.com:3128)r�r`rar�)z1ftp://joe:password@proxy.example.com/rubbish:3128)rOr`rar�)z%http://joe:password@proxy.example.comr?)z&http://user/name:password@localhost:22)r��	user/namera�localhost:22)z&http://username:pass/word@localhost:22)r�Zusername�	pass/wordrA)z'http://user/name:pass/word@localhost:22)r�r@rBrAzfile:/ftp.example.com)rrr/r0)r Zparse_proxy_test_casesZtcr$r'r'r(�test_parse_proxy@s'zMiscTests.test_parse_proxycCsPt�}|�t��
}|�d�Wd�n1swY|�t|j�d�dS)NZinvalidz5Unsupported digest authentication algorithm 'invalid')rr/r0Zget_algorithm_implsrrFZ	exception)r r&�excr'r'r(�test_unsupported_algorithmms��z$MiscTests.test_unsupported_algorithmN)	rIrrJr2r:r;r<rCrEr'r'r'r(r-�s,-r-c@s�eZdZGdd�de�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS) �RequestTestsc@seZdZdZdS)zRequestTests.PutRequest�PUTN)rIrrJr�r'r'r'r(�
PutRequestxsrHcCsLtd�|_tddddid�|_tddd�|_|�d�|_|jddd�|_dS)	N�http://www.python.org/~jeremy/r�zX-Testr�rO�HEAD)r�r[)rrL�post�headrH�put�
force_postr�r'r'r(�setUp{s
��zRequestTests.setUpcCs^|�d|j���|�d|j���|�d|j���|�d|j���|�d|j���dS)Nr[rZrJrG)rrKr�rLrLrMrNr�r'r'r(�test_method�s
zRequestTests.test_methodcCsL|�|jj�|�d|j���d|j_|�|jj�|�d|j���dS)NrZrpr[)rYrLr�rr�rUr�r'r'r(�	test_data�s
zRequestTests.test_datacCsN|�d|jj�|j�dd�|�d|jjd�d|j_|�d|jj�dS)NrI�*rp)rerLrfr\rr�r�r'r'r(�.test_setting_data_should_remove_content_length�s
z;RequestTests.test_setting_data_should_remove_content_lengthcCsT|�d|jj�d|j_|j�dd�|�d|jjd�|j`|�d|jj�dS)NrIrir�)rerLrfr�r\rr�r'r'r(�/test_deleting_data_should_remove_content_length�sz<RequestTests.test_deleting_data_should_remove_content_lengthcCs|�d|j���dS)NrI)rrLrr�r'r'r(�test_get_full_url�s�zRequestTests.test_get_full_urlcCs*|�d|jj�td�}|�d|j�dS)Nz	/~jeremy/zhttp://www.python.org/r*)rrLr�rr	r'r'r(�
test_selector�szRequestTests.test_selectorcC�|�d|jj�dS)Nr�)rrLrWr�r'r'r(�
test_get_type��zRequestTests.test_get_typecCrW)Nr�)rrLr�r�r'r'r(�
test_get_host�rYzRequestTests.test_get_hostcC�td�}|�d|j�dS)Nzhttp://www.%70ython.org/r��rrr�r	r'r'r(�test_get_host_unquote��z"RequestTests.test_get_host_unquotecCsR|�|j���|j�dd�|�|j���|�d|jj�|�d|jj�dS)Nr�r�r�)rYrLZ	has_proxyr�rUrr�r�r�r'r'r(r��s
zRequestTests.test_proxycCr[)Nz<URL:http://www.python.org>r�r\r	r'r'r(�test_wrapped_url�r^zRequestTests.test_wrapped_urlcCsLtd�}|�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)rrr�r)r r]rQr'r'r(�test_url_fragment�szRequestTests.test_url_fragmentcCs0gd�}|D]}t|�}|�|��|j�qdS)N)zhttp://docs.python.orgrar`)rrrr�)r rXrQr]r'r'r(�test_url_fullurl_get_full_url�s
�z*RequestTests.test_url_fullurl_get_full_urlN)rIrrJrrHrOrPrQrSrTrUrVrXrZr]r�r_rbrcr'r'r'r(rFws 

rF�__main__)=r3r�rZtest.supportrrrrrr�r�r�rzrqr|Zurllib.requestr-rrr	r
rrr
rZurllib.parserrZhttp.clientr�ZTestCaserrKr�r�r�r�r�r�r�r��IOBaser�r�r�r�r�rr9r�rrrrrr5r6r-rFrI�mainr'r'r'r(�<module>sl(4<

-6"
3
a�