Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_httpservers.cpython-34.pyo

�
g f���@sddZddlmZmZmZmZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlmZddlZddlmZejd�ZGdd	�d	�ZGd
d�dej�ZGdd
�d
ej�ZGdd�de�ZGdd�de�Z dZ!dZ"dZ#ej$e%ed�o�ej&�dkd�Gdd�de��Z'Gdd�de�Z(Gdd�de(�Z)Gdd�d�Z*Gdd �d ej�Z+Gd!d"�d"ej�Z,Gd#d$�d$ej�Z-dd%d&�Z.e/d'kr`e.�ndS)(z�Unittests for the various HTTPServer modules.

Written by Cody A.W. Somerville <cody-somerville@ubuntu.com>,
Josip Dzolonga, and Michael Otteneder for the 2007/08 GHOP contest.
�)�BaseHTTPRequestHandler�
HTTPServer�SimpleHTTPRequestHandler�CGIHTTPRequestHandler)�serverN)�BytesIO)�support�	threadingc@s+eZdZdd�Zddd�ZdS)�NoLogRequestHandlercGsdS)N�)�self�argsrr�:/opt/alt/python34/lib64/python3.4/test/test_httpservers.py�log_messageszNoLogRequestHandler.log_messageNcCsdS)N�r)r�nrrr�read szNoLogRequestHandler.read)�__name__�
__module__�__qualname__rrrrrrr
sr
c@s4eZdZdd�Zdd�Zdd�ZdS)�TestServerThreadcCs&tjj|�||_||_dS)N)r	�Thread�__init__�request_handler�test_object)rrrrrrr%s	zTestServerThread.__init__c
Cs{td|j�|_|jjj�\|j_|j_|jjj	�d|_z|jj
d�Wd|jj�XdS)N�	localhostrg�������?)rr)rrrZsocketZgetsocknamer�HOST�PORT�server_started�setZ
serve_foreverZserver_close)rrrr�run*s$	zTestServerThread.runcCs|jj�dS)N)rZshutdown)rrrr�stop4szTestServerThread.stopN)rrrrr r!rrrrr$s
rc@s=eZdZdd�Zdd�Zddidd�ZdS)	�BaseTestCasecCs`tj�|_tj�t_tj�|_t	||j
�|_|jj�|jj
�dS)N)rZthreading_setup�_threadsZEnvironmentVarGuard�os�environr	ZEventrrr�thread�start�wait)rrrr�setUp9s
zBaseTestCase.setUpcCs7|jj�d|_tjj�tj|j�dS)N)r&r!r$r%�__exit__rZthreading_cleanupr#)rrrr�tearDownAs
	
zBaseTestCase.tearDown�GETNcCsDtjj|j|j�|_|jj||||�|jj�S)N)�http�client�HTTPConnectionrrZ
connection�request�getresponse)rZuri�method�body�headersrrrr0GszBaseTestCase.request)rrrr)r+r0rrrrr"8sr"c@seZdZGdd�dee�Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'S)(�BaseHTTPServerTestCasec@speZdZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdS)z&BaseHTTPServerTestCase.request_handlerzHTTP/1.1cCs;|jd�|jdd�|jdd�|j�dS)N��zContent-Typez	text/html�
Connection�close)�
send_response�send_header�end_headers)rrrr�do_TESTRs
z.BaseHTTPServerTestCase.request_handler.do_TESTcCs;|jd�|jdd�|jdd�|j�dS)Nr6zContent-Typez	text/htmlr7z
keep-alive)r9r:r;)rrrr�do_KEEPXs
z.BaseHTTPServerTestCase.request_handler.do_KEEPcCs|jd�dS)Ni�)�
send_error)rrrr�do_KEYERROR^sz2BaseHTTPServerTestCase.request_handler.do_KEYERRORcCs|jd�dS)Ni�)r>)rrrr�do_NOTFOUNDasz2BaseHTTPServerTestCase.request_handler.do_NOTFOUNDcCs|jddd�dS)Ni�z
Short MessagezThis is a long 
 explaination)r>)rrrr�do_EXPLAINERRORdsz6BaseHTTPServerTestCase.request_handler.do_EXPLAINERRORcCs;|jd�|jdd�|jdd�|j�dS)Ni�zContent-Typez	text/htmlr7r8)r9r:r;)rrrr�	do_CUSTOMhs
z0BaseHTTPServerTestCase.request_handler.do_CUSTOMcCsa|jd�|jdd�|jdd�|j�|jdjd�}|jj|�dS)Ni�z	X-SpecialuDängerous Mindr7r8zx-special-incomingzutf-8)r9r:r;r4�encode�wfile�write)rr3rrr�do_LATINONEHEADERns

z8BaseHTTPServerTestCase.request_handler.do_LATINONEHEADERN)rrr�protocol_versionZdefault_request_versionr<r=r?r@rArBrFrrrrrNsrcCs<tj|�tjj|j|j�|_|jj�dS)N)	r"r)r-r.r/rr�conZconnect)rrrrr)vs
zBaseHTTPServerTestCase.setUpcCs9|jjdd�|jj�}|j|jd�dS)Nr,�/i�)rHr0r1�assertEqual�status)r�resrrr�test_command{sz#BaseHTTPServerTestCase.test_commandcCsRd|j_|jjdd�|jj�|jj�}|j|jd�dS)Nz	HTTP/1.1
ZXYZBOGUSrIi�)rH�
_http_vsn_str�
putrequest�
endheadersr1rJrK)rrLrrr�test_request_line_trimming�s

z1BaseHTTPServerTestCase.test_request_line_trimmingcCsRd|j_|jjdd�|jj�|jj�}|j|jd�dS)NZFUBARr,rIi�)rHrNrOrPr1rJrK)rrLrrr�test_version_bogus�s

z)BaseHTTPServerTestCase.test_version_boguscCsRd|j_|jjdd�|jj�|jj�}|j|jd�dS)Nz
HTTP/9.9.9r,rIi�)rHrNrOrPr1rJrK)rrLrrr�test_version_digits�s

z*BaseHTTPServerTestCase.test_version_digitscCsRd|j_|jjdd�|jj�|jj�}|j|jd�dS)Nrr,rIi�)rHrNrOrPr1rJrK)rrLrrr�test_version_none_get�s

z,BaseHTTPServerTestCase.test_version_none_getcCsRd|j_|jjdd�|jj�|jj�}|j|jd�dS)Nr�CUSTOMrIi�)rHrNrOrPr1rJrK)rrLrrr�test_version_none�s

z(BaseHTTPServerTestCase.test_version_nonecCs^d|j_d|j_|jjdd�|jj�|jj�}|j|jd�dS)N�czHTTP/9.9r,rIi�)rHZ	_http_vsnrNrOrPr1rJrK)rrLrrr�test_version_invalid�s
z+BaseHTTPServerTestCase.test_version_invalidcCsRd|j_|jjdd�|jj�|jj�}|j|jd�dS)Nri�)rHrNrOrPr1rJrK)rrLrrr�test_send_blank�s

z&BaseHTTPServerTestCase.test_send_blankcCsY|jjdd�|jjdd�|jj�|jj�}|j|jd�dS)Nr,rIr7r8i�)rHrO�	putheaderrPr1rJrK)rrLrrr�test_header_close�s

z(BaseHTTPServerTestCase.test_header_closecCsed|j_|jjdd�|jjdd�|jj�|jj�}|j|jd�dS)NzHTTP/1.1r,rIr7z
keep-alivei�)rHrNrOrZrPr1rJrK)rrLrrr�test_head_keep_alive�s
z+BaseHTTPServerTestCase.test_head_keep_alivecCs9|jjdd�|jj�}|j|jd�dS)N�TESTrIr6)rHr0r1rJrK)rrLrrr�test_handler�sz#BaseHTTPServerTestCase.test_handlercCse|jjdd�|jj�}|j|jd�d�|jjdd�|j|jj�dS)NZKEEPrIr7z
keep-aliver])rHr0r1rJ�	getheaderZ
addCleanupr8)rrLrrr�test_return_header_keep_alive�s
z4BaseHTTPServerTestCase.test_return_header_keep_alivecCs9|jjdd�|jj�}|j|jd�dS)NZKEYERRORrIi�)rHr0r1rJrK)rrLrrr�test_internal_key_error�sz.BaseHTTPServerTestCase.test_internal_key_errorcCs9|jjdd�|jj�}|j|jd�dS)NrUrIi�)rHr0r1rJrK)rrLrrr�test_return_custom_status�sz0BaseHTTPServerTestCase.test_return_custom_statuscCsU|jjdd�|jj�}|j|jd�|jt|jd���dS)NZEXPLAINERRORrIi�zContent-Length)rHr0r1rJrK�
assertTrue�intr_)rrLrrr�test_return_explain_error�sz0BaseHTTPServerTestCase.test_return_explain_errorcCsk|jjdddidd6�|jj�}|j|jd�d�|j|j�djd��dS)	NZLATINONEHEADERrIr4uÄrger mit UnicodezX-Special-Incomingz	X-SpecialuDängerous Mindzutf-8)rHr0r1rJr_rrC)rrLrrr�test_latin1_header�s
z)BaseHTTPServerTestCase.test_latin1_headercCsj|jjdd�|jj�}|j|jd�|j�}|jt|jd��t|��dS)NZNOTFOUNDrIi�zContent-Length)	rHr0r1rJrKrrdr_�len)rrL�datarrr�test_error_content_length�s
z0BaseHTTPServerTestCase.test_error_content_lengthN)rrrr
rrr)rMrQrRrSrTrVrXrYr[r\r^r`rarbrerfrirrrrr5Ms&(r5c@s�eZdZGdd�dee�Zdd�Zdd�Zddd	�Ze	j
d
d�eje	j
d�d
d���Zdd�Zdd�Zdd�ZdS)�SimpleHTTPServerTestCasec@seZdZdS)z(SimpleHTTPServerTestCase.request_handlerN)rrrrrrrr�src	Cs�tj|�tj�|_tj�}tj|�d|_tj	d|�|_
tjj|j
�|_
ttjj|j
d�d��}|j|j�WdQXdS)NsWe are the knights who say Ni!�dir�test�wb)r"r)r$�getcwd�cwd�tempfileZ
gettempdir�chdirrh�mkdtemp�tempdir�path�basename�tempdir_name�open�joinrE)rZbasetempdirZtemprrrr)�s

	$zSimpleHTTPServerTestCase.setUpcCsHz3tj|j�ytj|j�WnYnXWdtj|�XdS)N)r$rqro�shutilZrmtreersr"r+)rrrrr+�s	z!SimpleHTTPServerTestCase.tearDownNcCsY|j�}|j|�|j|j|�|j|j�|rU|j||�n|S)N)rrcrJrK�assertIsNotNone�reason)r�responserKrhr3rrr�check_status_and_reasons
z0SimpleHTTPServerTestCase.check_status_and_reason�
�zneed support.TESTFN_UNDECODABLEcCsatj�}tjtj�d}ttjj|j	|�d��}|j
tj�WdQX|j|jd�}tj
dkr�x3tj|j	�D]}|dkr�|}Pq�q�Wn|j|d�}tjj|dd�}|jd	|j|d
�|�|jdtj|�j|d
�|�|j|jd|�}|j|ddtj�dS)
Nz.txtrmrI�darwinrl���errors�
surrogatepassz	href="%s"�surrogateescapez>%s<rh)�sys�getfilesystemencodingr$�fsdecoder�TESTFN_UNDECODABLErwrtrxrsrEr0rv�platform�listdirr}�urllib�parseZquoteZassertInrC�html�escape)r�enc�filename�fr|�namer3Z
quotednamerrr�test_undecodable_filenames&$z2SimpleHTTPServerTestCase.test_undecodable_filenamec
Cs|j|jd�}|j|dd|j�|j|jd�}|j|d�|j|jd�}|j|d�|j|j�}|j|d�|j|jd�}|j|d�|j|jd	�}|j|d�|j|jd
�|jd�|jd�}|j|d�|jd�}|j|d�ttjj	|jd�d���}|jd|jd�}|j|d�tj
dkrtj�dkrtj|j
d�|j|jd�}|j|d�tj|j
d�nWdQXdS)Nz/testr�rhz/test/i�rIi-z/?hi=2z?hi=1ZLocationz/?hi=1z/ThisDoesNotExistZThisDoesNotExistz
index.html�w�posixri�z/ThisDoesNotExistz/ThisDoesNotExist/)r0rvr}rhrJr_rwr$rtrxr��geteuid�chmodrs)rr|r�rrr�test_get+s4$!z!SimpleHTTPServerTestCase.test_getcCsq|j|jddd�}|j|d�|j|jd�tt|j���|j|jd�d�dS)Nz/testr2ZHEADr�zcontent-lengthzcontent-typezapplication/octet-stream)r0rvr}rJr_�strrgrh)rr|rrr�	test_headKsz"SimpleHTTPServerTestCase.test_headcCss|jddd�}|j|d�|jddd�}|j|d�|jddd�}|j|d�dS)NrIr2ZFOOi�ZcustomZGETs)r0r})rr|rrr�test_invalid_requestsTsz.SimpleHTTPServerTestCase.test_invalid_requests)rrrr
rrr)r+r}rZrequires_mac_ver�unittestZ
skipUnlessr�r�r�r�r�rrrrrj�s
	 	rjzD#!%s

print("Content-type: text/html")
print()
print("Hello World")
z�#!%s
import cgi

print("Content-type: text/html")
print()

form = cgi.FieldStorage()
print("%%s, %%s, %%s" %% (form.getfirst("spam"), form.getfirst("eggs"),
                          form.getfirst("bacon")))
zR#!%s
import os

print("Content-type: text/html")
print()

print(os.environ["%s"])
r�z7This test can't be run reliably as root (issue #13308).c@s�eZdZGdd�dee�Zejjd�Zdd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd S)!�CGIHTTPServerTestCasec@seZdZdS)z%CGIHTTPServerTestCase.request_handlerN)rrrrrrrr�sr�asciic+Cs=tj|�tj�|_tj�|_tjj	|jd�|_
tjj	|j
d�|_tj|j
�tj|j�d|_
d|_d|_d|_d|_tj�r�tjj	|jd�|_tjtj|j�ntj|_y|jjd�Wn)tk
r9|j�|jd�YnXtjj	|jd�|_
t|j
d��}|jt|j�WdQXtj|j
d�tjj	|j
d	�|_t|jdd
d��}|jt|j�WdQXtj|jd�tjj	|j
d�|_t|jdd
d��}|jt |j�WdQXtj|jd�tjj	|jd�|_t|jdd
d��}|jt|j�WdQXtj|jd�tjj	|j
d
�|_t|jdd
d��!}|jt!|jdf�WdQXtj|jd�tj"|j�dS)Nzcgi-binz	child-dir�pythonzutf-8z0Python executable path is not encodable to utf-8znocgi.pyr�i�zfile1.py�encodingzfile2.pyzfile3.pyzfile4.pyZQUERY_STRING)#r"r)r$rnrorprr�
parent_dirrtrx�cgi_dir�
cgi_child_dir�mkdir�
nocgi_path�
file1_path�
file2_path�
file3_path�
file4_pathrZcan_symlink�	pythonexe�symlinkr��
executablerC�UnicodeEncodeErrorr+ZskipTestrwrE�	cgi_file1r��	cgi_file2�	cgi_file4rq)r�fpZfile1Zfile2Zfile3Zfile4rrrr)�sT
					

 zCGIHTTPServerTestCase.setUpcCs
z�tj|j�|jtjkr8tj|j�n|jrTtj|j�n|jrptj|j�n|j	r�tj|j	�n|j
r�tj|j
�n|jr�tj|j�ntj|j
�tj|j�tj|j�Wdtj|�XdS)N)r$rqror�r�r��remover�r�r�r�r��rmdirr�r�r�r"r+)rrrrr+�s$					zCGIHTTPServerTestCase.tearDownc	CsTidd6td6td6dd6dd6dd6dd6d	d
6d	d	6dd6dd
6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6td6dd6dd 6td!6dd"6dd#6}x�|j�D]u\}}t|t�rt|t�r|j|tj|�q�tj|�}|j	||d$d%|||f�q�WdS)&Nz//rz..z/.//..rIz//\z/\z/.//z/cgi-bin/file1.pyzcgi-bin/file1.pyz//a�az/az./az/C:/z./C:/z/a/bz/a/b/z/a/b/.z	/a/b/c/..z/a/b/dz/a/b/c/../dz/a/b/d/fz/a/b/c/../d/e/../fz/a/b/fz/a/b/c/../d/e/../../fz/a/b/c/../d/e/.././././..//fz../a/b/c/../d/e/.././././..//fz/a/fz/a/b/c/../d/e/../../../fz//fz/a/b/c/../d/e/../../../../fz/a/b/c/../d/e/../../../../../fz/a/b/c/../d/e/../../../../f/..z /a/b/c/../d/e/../../../../f/../.�msgzpath = %r
Got:    %r
Wanted: %r)
�
IndexError�items�
isinstance�type�
issubclass�	Exception�assertRaisesrZ_url_collapse_pathrJ)rZtest_vectorsrt�expectedZactualrrr�test_url_collapse_path�sJ
	z,CGIHTTPServerTestCase.test_url_collapse_pathcCsN|jd�}|jd|jddf|j�|jd�|jf�dS)Nz/cgi-bin/file1.pysHello Worldz	text/htmlr�zContent-type)r0rJ�lineseprr_rK)rrLrrr�test_headers_and_content�sz.CGIHTTPServerTestCase.test_headers_and_contentcCs&|jd�}|j|jd�dS)Nz)///////////nocgi.py/../cgi-bin/nothere.shi�)r0rJrK)rrLrrr�test_issue19435sz%CGIHTTPServerTestCase.test_issue19435cCsmtjjidd6dd6dd6�}idd6}|jd	d
||�}|j|j�d|j�dS)N�Zspamr�Zeggsi@�Zbaconz!application/x-www-form-urlencodedzContent-typez/cgi-bin/file2.pyZPOSTs1, python, 123456)r�r�Z	urlencoder0rJrr�)rZparamsr4rLrrr�	test_posts
	
zCGIHTTPServerTestCase.test_postcCs0|jd�}|j�|j|jd�dS)Nz/cgi-bin/invalidi�)r0rrJrK)rrLrrr�test_invaliduris
z%CGIHTTPServerTestCase.test_invaliduricCsqidtjd�d6}|jddd|�}|jd|jdd	f|j�|jd
�|jf�dS)NsBasic s
username:passs
Authorizationz/cgi-bin/file1.pyr,r4sHello Worldz	text/htmlr�zContent-type)�base64Z	b64encoder0rJr�rr_rK)rr4rLrrr�test_authorizations
z(CGIHTTPServerTestCase.test_authorizationcCsN|jd�}|jd|jddf|j�|jd�|jf�dS)Nzcgi-bin/file1.pysHello Worldz	text/htmlr�zContent-type)r0rJr�rr_rK)rrLrrr�test_no_leading_slashsz+CGIHTTPServerTestCase.test_no_leading_slashcCsxd}|tjd<|jd�}|jd|jddf|j�|jd�|jf�|jtjd|�dS)NzTest CGI ServerZSERVER_SOFTWAREz/cgi-bin/file1.pysHello Worldz	text/htmlr�zContent-type)r$r%r0rJr�rr_rK)rZ	signaturerLrrr�test_os_environ_is_not_altered!s
"z4CGIHTTPServerTestCase.test_os_environ_is_not_alteredcCsN|jd�}|jd|jddf|j�|jd�|jf�dS)Nz/cgi-bin%2ffile1.pysHello Worldz	text/htmlr�zContent-type)r0rJr�rr_rK)rrLrrr�#test_urlquote_decoding_in_cgi_check)sz9CGIHTTPServerTestCase.test_urlquote_decoding_in_cgi_checkcCsN|jd�}|jd|jddf|j�|jd�|jf�dS)Nz/cgi-bin/child-dir/file3.pysHello Worldz	text/htmlr�zContent-type)r0rJr�rr_rK)rrLrrr�test_nested_cgi_path_issue21323.sz5CGIHTTPServerTestCase.test_nested_cgi_path_issue21323cCsN|jd�}|jd|jddf|j�|jd�|jf�dS)Nz/cgi-bin/file4.py?a=b?c=dsa=b?c=dz	text/htmlr�zContent-type)r0rJr�rr_rK)rrLrrr�&test_query_with_multiple_question_mark3sz<CGIHTTPServerTestCase.test_query_with_multiple_question_markcCsN|jd�}|jd|jddf|j�|jd�|jf�dS)Nz0/cgi-bin/file4.py?k=aa%2F%2Fbb&//q//p//=//a//b//sk=aa%2F%2Fbb&//q//p//=//a//b//z	text/htmlr�zContent-type)r0rJr�rr_rK)rrLrrr�"test_query_with_continuous_slashes9s

	z8CGIHTTPServerTestCase.test_query_with_continuous_slashesN)rrrr
rrr$r�rCr)r+r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�}s :*r�c@s4eZdZdd�Zdd�Zdd�ZdS)�SocketlessRequestHandlercCsd|_d|_dS)NFzHTTP/1.1)�
get_calledrG)rrrrrBs	z!SocketlessRequestHandler.__init__cCsDd|_|jd�|jdd�|j�|jjd�dS)NTr�zContent-Typez	text/htmls <html><body>Data</body></html>
)r�r9r:r;rDrE)rrrr�do_GETFs
	

zSocketlessRequestHandler.do_GETcGsdS)Nr)r�formatr
rrrrMsz$SocketlessRequestHandler.log_messageN)rrrrr�rrrrrr�Asr�c@seZdZdd�ZdS)�!RejectingSocketlessRequestHandlercCs|jd�dS)Ni�F)r>)rrrr�handle_expect_100Qs
z3RejectingSocketlessRequestHandler.handle_expect_100N)rrrr�rrrrr�Psr�c@sFeZdZdd�Zdd�Zdd�Zedd��Zd	S)
�AuditableBytesIOcCs
g|_dS)N)�datas)rrrrrXszAuditableBytesIO.__init__cCs|jj|�dS)N)r��append)rrhrrrrE[szAuditableBytesIO.writecCsdj|j�S)N�)rxr�)rrrr�getData^szAuditableBytesIO.getDatacCs
t|j�S)N)rgr�)rrrr�	numWritesaszAuditableBytesIO.numWritesN)rrrrrEr��propertyr�rrrrr�Vsr�c@s�eZdZdZejd�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'S)(�BaseHTTPRequestHandlerTestCasezrTest the functionality of the BaseHTTPServer.

       Test the support for the Expect 100-continue header.
       sHTTP/1.[0-9]+ 200 OKcCst�|_dS)N)r��handler)rrrrr)nsz$BaseHTTPRequestHandlerTestCase.setUpcCsQt|�}t�}||j_||j_|jj�|jd�|j�S)Nr)rr��rfilerD�handle_one_request�seek�	readlines)r�message�input�outputrrr�send_typical_requestqs	

z3BaseHTTPRequestHandlerTestCase.send_typical_requestcCs|j|jj�dS)N)rcr�r�)rrrr�verify_get_calledzsz0BaseHTTPRequestHandlerTestCase.verify_get_calledcs>x7dD]/�|jt�fdd�|D��d�qWdS)N�Server: �Date: �Content-Type: c3s|]}|j��VqdS)N)�
startswith)�.0�h)�	fieldNamerr�	<genexpr>szIBaseHTTPRequestHandlerTestCase.verify_expected_headers.<locals>.<genexpr>r�)r�r�r�)rJ�sum)rr4r)r�r�verify_expected_headers}s
z6BaseHTTPRequestHandlerTestCase.verify_expected_headerscCs#|jj|�}|j|�dS)N)�HTTPResponseMatch�searchrz)rr|�matchrrr�verify_http_server_response�sz:BaseHTTPRequestHandlerTestCase.verify_http_server_responsecCs�|jd�}|j|d�|j|dd	��|j�|j|d
d�|j|jjd�|j|jjd�|j|jjd�|j|jj	d�|j
|jjj�f�dS)NsGET / HTTP/1.1

rr�s <html><body>Data</body></html>
zGET / HTTP/1.1r,rIzHTTP/1.1���r�)
r�r�r�r�rJr��requestline�commandrt�request_version�assertSequenceEqualr4r�)r�resultrrr�
test_http_1_1�s
z,BaseHTTPRequestHandlerTestCase.test_http_1_1cCs�|jd�}|j|d�|j|dd	��|j�|j|d
d�|j|jjd�|j|jjd�|j|jjd�|j|jj	d�|j
|jjj�f�dS)NsGET / HTTP/1.0

rr�s <html><body>Data</body></html>
zGET / HTTP/1.0r,rIzHTTP/1.0r�r�)
r�r�r�r�rJr�r�r�rtr�r�r4r�)rr�rrr�
test_http_1_0�s
z,BaseHTTPRequestHandlerTestCase.test_http_1_0cCsG|jd�}|jt|�d�|j|dd�|j�dS)NsGET / HTTP/0.9

r�rs <html><body>Data</body></html>
)r�rJrgr�)rr�rrr�
test_http_0_9�sz,BaseHTTPRequestHandlerTestCase.test_http_0_9cCs�|jd�}|j|d�|j|dd��|j�|j|dd�|j|jjd�|j|jjd�|j|jjd�|j|jj	d�d}|j
|jjj�|�dS)Ns(GET / HTTP/1.0
Expect: 100-continue

rr�s <html><body>Data</body></html>
zGET / HTTP/1.0r,rIzHTTP/1.0�Expect�100-continuer�r��r�r�)r�)
r�r�r�r�rJr�r�r�rtr�r�r4r�)rr�r4rrr�test_with_continue_1_0�s
z5BaseHTTPRequestHandlerTestCase.test_with_continue_1_0cCs�|jd�}|j|dd�|j|dd�|j|dd�|j|dd��|j�|j|dd�|j|jjd	�|j|jjd
�|j|jjd�|j|jjd�d}|j	|jj
j�|�dS)Ns(GET / HTTP/1.1
Expect: 100-continue

rsHTTP/1.1 100 Continue
r�s
�sHTTP/1.1 200 OK
s <html><body>Data</body></html>
zGET / HTTP/1.1r,rIzHTTP/1.1r��100-continuer�r��zExpectr)r)r�rJr�r�r�r�r�rtr�r�r4r�)rr�r4rrr�test_with_continue_1_1�s
z5BaseHTTPRequestHandlerTestCase.test_with_continue_1_1cCsotd�}t�}t�}||_||_d|_d|_d|_|jd�|j	|j
d�dS)NsGET / HTTP/1.1

zHTTP/1.1ri�r)rr�r�r�rDr�r�r�r>rJr�)rr�r�r�rrr�#test_header_buffering_of_send_error�s							
zBBaseHTTPRequestHandlerTestCase.test_header_buffering_of_send_errorcCsztd�}t�}t�}||_||_d|_|jd�|j|jd�|j	�|j|jd�dS)NsGET / HTTP/1.1

zHTTP/1.1i�rr�)
rr�r�r�rDr�Zsend_response_onlyrJr�r;)rr�r�r�rrr�+test_header_buffering_of_send_response_only�s					

zJBaseHTTPRequestHandlerTestCase.test_header_buffering_of_send_response_onlycCs�td�}t�}t�}||_||_d|_|jdd�|jdd�|j|jd�|j	�|j|j
�d�|j|jd�dS)	NsGET / HTTP/1.1

zHTTP/1.1ZFooZfooZbarrsFoo: foo
bar: bar

r�)rr�r�r�rDr�r:rJr�r;r�)rr�r�r�rrr�$test_header_buffering_of_send_header�s					
zCBaseHTTPRequestHandlerTestCase.test_header_buffering_of_send_headercCs�dd�}td�}t�}||j_||j_d|j_|jj�|j||�d�||�jd�}|j|dd�|j|d	d�|j|d
d�dS)NcSs6|j�}|jd�|j�}|j|�|S)Nr)�tellr�r)r��posrhrrr�_readAndReseek�s


z[BaseHTTPRequestHandlerTestCase.test_header_unbuffered_when_continue.<locals>._readAndReseeks(GET / HTTP/1.1
Expect: 100-continue

zHTTP/1.1r�s
rsHTTP/1.1 100 Continuer�rsHTTP/1.1 200 OK)	rr�r�rDr�r�ZassertNotEqual�splitrJ)rr	r�r�r�rrr�$test_header_unbuffered_when_continue�s	
zCBaseHTTPRequestHandlerTestCase.test_header_unbuffered_when_continuecCs�|j}t�|_|jd�}|j|dd�|j|dd��|j|jj�|jtdd�|dd�D��d�||_dS)	Ns(GET / HTTP/1.1
Expect: 100-continue

rs!HTTP/1.1 417 Expectation Failed
r�css|]}|dkVqdS)sConnection: close
Nr)r��rrrrr�
szMBaseHTTPRequestHandlerTestCase.test_with_continue_rejected.<locals>.<genexpr>r�r�)r�r�r�rJr��assertFalser�r�)rZ
usual_handlerr�rrr�test_with_continue_rejecteds	-z:BaseHTTPRequestHandlerTestCase.test_with_continue_rejectedcCsX|jddd�}|j|dd�|j|jj�|j|jjt�dS)NsGET �xirs#HTTP/1.1 414 Request-URI Too Long
)r�rJr
r�r�ZassertIsInstancer�r�)rr�rrr�test_request_length
sz2BaseHTTPRequestHandlerTestCase.test_request_lengthcCs\|jdddd�}|j|dd�|j|jj�|j|jjd�dS)NsGET / HTTP/1.1
X-Foo: bar�ris

rsHTTP/1.1 400 Line too long
zGET / HTTP/1.1)r�rJr
r�r�r�)rr�rrr�test_header_lengths
z1BaseHTTPRequestHandlerTestCase.test_header_lengthcs}��fdd�}|�j_td���jj��jtt��td���jj��jtt��dS)Ncst���j_dS)N)�nextr�Zclose_connectionr)�close_valuesrrrr� szPBaseHTTPRequestHandlerTestCase.test_close_connection.<locals>.handle_one_requestTF)T)FFT)r�r��iterZhandler��
StopIterationr)rr�r)rrr�test_close_connections

z4BaseHTTPRequestHandlerTestCase.test_close_connectionN)rrr�__doc__�re�compiler�r)r�r�r�r�r�r�r�r�rrrrrrrrrrrrrr�fs(	
r�c@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)� SimpleHTTPRequestHandlerTestCasez Test url parsing cCs:tj�|_tjj|jd�|_t�|_dS)Nr�)r$rn�
translatedrtrxr�r�)rrrrr).sz&SimpleHTTPRequestHandlerTestCase.setUpcCss|jjd�}|j||j�|jjd�}|j||j�|jjd�}|j||j�dS)Nz	/filenamez/filename?foo=barz/filename?a=b&spam=eggs#zot)r��translate_pathrJr)rrtrrr�test_query_arguments3sz5SimpleHTTPRequestHandlerTestCase.test_query_argumentscCsN|jjd�}|j||j�|jjd�}|j||j�dS)Nz
//filenamez//filename?foo=bar)r�rrJr)rrtrrr�test_start_with_double_slash;sz=SimpleHTTPRequestHandlerTestCase.test_start_with_double_slashc
Cstjtjdt���|jjd�}|jtjtj�}|j	||j
�|jjd�}|jtjtj�}|j	||j
�|jjd�}|jtjtj�}|j	||j
�|jjd�}|jtjtj�}|j	||j
�WdQXdS)Nrtzc:c:c:foo/filenamez\c:../filenamezc:\c:..\foo/filenamezc:c:foo\c:c:bar/filename)rZ	swap_attrrr$�ntpathr�r�replace�seprJr)rrtrrr�test_windows_colonAsz3SimpleHTTPRequestHandlerTestCase.test_windows_colonN)rrrrr)rrr#rrrrr,s
rc@seZdZdd�ZdS)�MiscTestCasecCs�g}dddh}xltt�D]^}|jd�s"||krIq"ntt|�}t|dd�dkr"|j|�q"q"W|jtj|�dS)Nr�Z
nobody_uidrl�_rzhttp.server)rkrr��getattrr�ZassertCountEqual�__all__)rr�Z	blacklistr�Z
module_objectrrr�test_allUszMiscTestCase.test_allN)rrrr(rrrrr$Tsr$c
CsAtj�}z tjtttttt	�Wdtj
|�XdS)N)r$rnrZrun_unittestr�r5rjr�rr$rq)�verboserorrr�	test_mainasr*�__main__)0rZhttp.serverrrrrr-rr$r�rr�r ryZurllib.parser�r�Zhttp.clientrp�iorr�rlr�
import_moduler	r
rrZTestCaser"r5rjr�r�r�ZskipIf�hasattrr�r�r�r�r�r�rr$r*rrrrr�<module>sH"	�u
$��(