Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_wsgiref.cpython-34.pyc

�
g f�Y�@sddlmZddlmZddlmZddlmZmZddl	m
Z
ddlmZddl
mZmZddl
mZdd	lmZmZmZdd
lmZddlmZddlZddlZddlZddlZdd
lmZGdd�de�ZGdd�de�Zdd�Z dd�Z!e ddd�Z"dd�Z#Gdd�de�Z$Gdd�de�Z%Gdd �d e�Z&Gd!d"�d"e�Z'Gd#d$�d$e'�Z(Gd%d&�d&e�Z)d'd(�Z*e+d)kre*�ndS)*�)�TestCase)�setup_testing_defaults)�Headers)�BaseHandler�BaseCGIHandler)�util)�	validator)�
WSGIServer�WSGIRequestHandler)�make_server)�StringIO�BytesIO�BufferedReader)�
BaseServer)�python_implementationN)�supportc@s.eZdZdZdd�Zdd�ZdS)�
MockServerzNon-socket HTTP servercCs!tj|||�|j�dS)N)r�__init__�server_bind)�self�server_addressZRequestHandlerClass�r�6/opt/alt/python34/lib64/python3.4/test/test_wsgiref.pyrszMockServer.__init__cCs/|j\}}||_||_|j�dS)N)rZserver_nameZserver_port�
setup_environ)r�hostZportrrrrs		zMockServer.server_bindN)�__name__�
__module__�__qualname__�__doc__rrrrrrrsrc@s.eZdZdZdd�Zdd�ZdS)�MockHandlerzNon-socket HTTP handlercCs%|j|_|j\|_|_dS)N)�requestZ
connectionZrfileZwfile)rrrr�setup%szMockHandler.setupcCsdS)Nr)rrrr�finish)szMockHandler.finishN)rrrrr!r"rrrrr#srcCs|dddg�dgS)	Nz200 OK�Content-Type�
text/plain�Date�Mon, 05 Jun 2006 18:49:54 GMTs
Hello, world!)r#r$)r%r&r)�environ�start_responserrr�	hello_app-s
r)cCsA|dddg�dj|d|d|d	g�jd
�gS)
Nz200 OK�Content-Type�
text/plainr%�Mon, 05 Jun 2006 18:49:54 GMT�;ZHTTP_X_TEST_HEADER�QUERY_STRING�	PATH_INFOz
iso-8859-1)r*r+)zDater,)�join�encode)r'r(rrr�
header_app5s
r2sGET / HTTP/1.0

cCs�tdd|tt�}tt|��}t�}tj}t�}t_z|j||fd�Wd|t_X|j	�|j	�fS)N��P�	127.0.0.1�")r5r6)
rrrrr
�sys�stderrrZfinish_request�getvalue)�app�dataZserverZinp�outZolderr�errrrr�	run_amock@s		
r>cCs|�}d}x1|D])}|||ks5t�n|d7}qWy||Wntk
rcYnXtd|��yttfWntk
r�Yn�X|�}t|�|k	r�t�nx)|D]!}t|�|ks�t�q�q�Wyt|�Wntk
rYnXtd|��dS)aUtility to compare a generic 2.1/2.2+ iterator with an iterable

    If running under Python 2.2+, this tests the iterator using iter()/next(),
    as well as __getitem__.  'make_it' must be a function returning a fresh
    iterator to be tested (since this may test the iterator twice).r�zToo many items from __getitem__zToo many items from .__next__()N)�AssertionError�
IndexError�iter�
StopIteration�	NameError�next)�make_it�match�it�n�itemrrr�compare_generic_iterNs4	
	

		


rKc@sseZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dS)�IntegrationTestsTcCsWt�dtjj�d}|j|d|d|r>dpAddjd��dS)	N�/rz(HTTP/1.0 200 OK
Server: WSGIServer/0.2 zA
Content-Type: text/plain
Date: Mon, 05 Jun 2006 18:49:54 GMT
zContent-Length: 13
r3z
Hello, world!z
iso-8859-1)rr7�version�split�assertEqualr1)rr<�
has_length�pyverrrr�check_hellous
	zIntegrationTests.check_hellocCs t�\}}|j|�dS)N)r>rS)rr<r=rrr�test_plain_hello�sz!IntegrationTests.test_plain_hellocCs9d}tt|�\}}|j|j�dd�dS)NsmGET /p%61th/?query=test HTTP/1.0
X-Test-Header: Python test 
X-Test-Header: Python test 2
Content-Length: 0

r?s+Python test,Python test 2;query=test;/path/���)r>r2rP�
splitlines)rr r<r=rrr�test_environ�s

zIntegrationTests.test_environcCs?tddddd�\}}|j|j�dd�dS)Nr;sGET �xis HTTP/1.0

rs!HTTP/1.0 414 Request-URI Too Long)r>rPrV)rr<r=rrr�test_request_length�s!z$IntegrationTests.test_request_lengthcCs/ttt��\}}|j|dd�dS)NrQF)r>rr)rS)rr<r=rrr�test_validated_hello�sz%IntegrationTests.test_validated_hellocCsXdd�}tt|��\}}|j|jd��|j|j�dd�dS)NcSs|dd�dgS)Nz200 OK�Content-Type�
text/plainz
Hello, world!)r[r\r)r'r(rrr�bad_app�s
z>IntegrationTests.test_simple_validation_error.<locals>.bad_apps;A server error occurred.  Please contact the administrator.�z^AssertionError: Headers (('Content-Type', 'text/plain')) must be of type list: <class 'tuple'>���)r>r�
assertTrue�endswithrPrV)rr]r<r=rrr�test_simple_validation_error�s

z-IntegrationTests.test_simple_validation_errorcCsXdd�}tt|��\}}|j|jd��|j|j�dd�dS)NcSs%|dj�|ddg�dgS)Nz
wsgi.inputz200 OK�Content-Type�text/plain; charset=utf-8sdata)rcrd)�read)�e�srrrr]�sz1IntegrationTests.test_wsgi_input.<locals>.bad_apps;A server error occurred.  Please contact the administrator.r^r@r_)r>rr`rarPrV)rr]r<r=rrr�test_wsgi_input�s
z IntegrationTests.test_wsgi_inputcCs�dd�}tt|��\}}|j|jd��tjj�djd�}t�jd�}|d|}|j	d|d|�dS)	NcSs|dddg�dgS)	Nz200 OK�Content-Type�text/plain; charset=utf-8r%�Wed, 24 Dec 2008 13:29:32 GMTsdata)rirj)zDaterkr)rfrgrrrr:�s
z3IntegrationTests.test_bytes_validation.<locals>.appz"GET / HTTP/1.0" 200 4
r�ascii�/s(HTTP/1.0 200 OK
Server: WSGIServer/0.2 sV
Content-Type: text/plain; charset=utf-8
Date: Wed, 24 Dec 2008 13:29:32 GMT

data)
r>rr`rar7rNrOr1rrP)rr:r<r=Zver�pyrRrrr�test_bytes_validation�sz&IntegrationTests.test_bytes_validationN)rrrrSrTrWrYrZrbrhrorrrrrLss


rLc@s�eZdZdd�Zddd�Zdd�Zdd	�Zd
dd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �ZdS)!�UtilityTestscCsfi|d6|d6}tj|�|jtj|�|�|j|d|�|j|d|�|S)N�SCRIPT_NAMEr/)rrrPZshift_path_info)rZsn_inZpi_in�partZsn_outZpi_out�envrrr�
checkShift�s
zUtilityTests.checkShiftNcCs�i}tj|�t|t�r9|j||t�n:t|t�r_|j||t�n|j|||�i||6}tj|�|j|||�dS)N)rr�
isinstancerZassertIsInstancer
rPZassertIs)r�key�value�altrsrrr�checkDefault�s


zUtilityTests.checkDefaultcKs%tj|�|j|||�dS)N)rrrP)rrvrw�kwrrr�checkCrossDefault�s
zUtilityTests.checkCrossDefaultcKs*tj|�|jtj|�|�dS)N)rrrPZapplication_uri)r�urirzrrr�checkAppURI�s
zUtilityTests.checkAppURIr?cKs-tj|�|jtj||�|�dS)N)rrrPZrequest_uri)rr|Zqueryrzrrr�checkReqURI�s
zUtilityTests.checkReqURIcCs�||dd�}t||�|�}|j|jj�x|D]}qBW|j|jj�|j�|j|jj�dS)NcSstjt|�|�S)N)rZFileWrapperr)�text�sizerrrrF�sz%UtilityTests.checkFW.<locals>.make_it)rK�assertFalseZfilelike�closed�closer`)rrr�rGrFrHrJrrr�checkFW�s
	

zUtilityTests.checkFWcCs�|jddddd�|jddddd�|jddddd�|jddddd�|jdd	ddd�dS)
Nr3rMz/x�xz/az/x/yz/a/xz/yz/x/)rt)rrrr�testSimpleShiftss
zUtilityTests.testSimpleShiftscCs|jddddd�|jddddd�|jdddd	d�|jdd
dd	d�|jdddd	d�|jdd
dd	d�|jddddd�|jddddd�|jddddd�|jddddd�|jddddd�dS)Nz/a/bz/../yz..z/az/yr3z//y�yz/a/b/yz//y/rMz/./yz/./y/z///./..//y/.//z/y/z///z/a/b/z/.//z/x//r�z/a/b/xz/.)rt)rrrr�testNormalizedShifts
sz!UtilityTests.testNormalizedShiftscCsgx`dddddddd d!d"d#dt�fdt�fd$gD]\}}|j||�qCWdS)%N�SERVER_NAME�	127.0.0.1�SERVER_PORT�80�SERVER_PROTOCOL�HTTP/1.0�	HTTP_HOST�REQUEST_METHOD�GETrqr3r/rM�wsgi.versionr?r�
wsgi.run_once�wsgi.multithread�wsgi.multiprocessz
wsgi.inputzwsgi.errors�wsgi.url_scheme�http)zSERVER_NAMEr�)zSERVER_PORTr�)zSERVER_PROTOCOLr�)z	HTTP_HOSTr�)r�r�)zSCRIPT_NAMEr3)z	PATH_INFOrM�r?r)r�r�)r�r)r�r)r�r)r�r�)r
rry)rrvrwrrr�testDefaultss zUtilityTests.testDefaultscCs�|jdddd�|jdddd�|jdddd�|jdddd	�|jdd
dd�|jdd
dd�|jdddd�dS)Nr�zfoo.barr�zwsgi.url_scheme�https�HTTPS�on�1�yesr��foor�r�Z443)r{)rrrr�testCrossDefaults-szUtilityTests.testCrossDefaultscCs�|jtji�d�|jtjidd6�d�|jtjidd6�d�|jtjidd6�d�|jtjidd6�d�dS)Nr�r�r�r�r�r�r�)rPrZguess_scheme)rrrr�testGuessScheme6s
   zUtilityTests.testGuessSchemecCs�|jd�|jddd�|jddd�|jddd	d
d�|jdd
d�|jdddd
d�|jddd�|jdd
ddd�dS)Nzhttp://127.0.0.1/zhttp://127.0.0.1/spamrqz/spamzhttp://127.0.0.1/sp%E4mu/spämzhttp://spam.example.com:2071/r�zspam.example.com:2071r�Z2071zhttp://spam.example.com/r�zspam.example.comz	127.0.0.1zhttps://127.0.0.1/r�r�zhttp://127.0.0.1:8000/Z8000)r})rrrr�testAppURIs=s


zUtilityTests.testAppURIsc	Cs�|jd�|jddd�|jddd�|jdddd	d�|jd
ddd	d�|jdddd	d�|jd
ddd	d�|jdddd	ddd�|jdddd	ddd�|jddddd	ddd�dS)Nzhttp://127.0.0.1/zhttp://127.0.0.1/spamrqz/spamzhttp://127.0.0.1/sp%E4mu/spämzhttp://127.0.0.1/spammity/spamz	/spammityr/z http://127.0.0.1/spammity/sp%E4mz"http://127.0.0.1/spammity/spam;hamz	/spam;hamz/http://127.0.0.1/spammity/spam;cookie=1234,5678z/spam;cookie=1234,5678z%http://127.0.0.1/spammity/spam?say=nir.zsay=niz'http://127.0.0.1/spammity/spam?s%E4y=nizs%E4y=nir)r~)rrrr�testReqURIsKs"




zUtilityTests.testReqURIscCs)|jdddddddg�dS)NZxyz�2�x�(�
)r�)rrrr�testFileWrapper^szUtilityTests.testFileWrappercCs�xYdj�D]K}xB||j�|j�|j�fD]}|jtj|��q8Wq
WxYdj�D]K}xB||j�|j�|j�fD]}|jtj|��q�WqiWdS)NzbConnection Keep-Alive Proxy-Authenticate Proxy-Authorization TE Trailers Transfer-Encoding Upgradez4Accept Cache-Control Date Pragma Trailer Via Warning)rO�title�upper�lowerr`rZ
is_hop_by_hopr�)rZhoprxrrr�testHopByHopas++zUtilityTests.testHopByHop)rrrrtryr{r}r~r�r�r�r�r�r�r�r�r�r�rrrrrp�s
	rpc@s4eZdZdd�Zdd�Zdd�ZdS)�HeaderTestscCs[dg}|jttg��d�|jtt|dd���d�|jt|dd��j�dg�|jt|dd��j�dg�|jt|dd��j�|�|jt|�j�|�tg�}|d=d|d<xr|j|j|j	|j
fD]R}|j|d��|j|d��|j|d��|j|d��qW|j|dd�d	|d<|j|dd	�|j|j	d�d	g�|j|jdd
�d	�|j|jdd
�d
�|j|j
dd
�d	�|j|j
dd
�d
�|j|dd	�|j|dd
�dS)
Nr�r�rr?r��bar�FooZFOO�bazZwheeZzoo)r�r�)rP�lenr�keys�values�itemsZassertIsNot�__contains__�get�get_all�__getitem__r`r��
setdefault)r�test�h�mrrr�testMappingInterfacers2	&))&
%
z HeaderTests.testMappingInterfacecCs|jttd�dS)Nr�)�assertRaises�	TypeErrorr)rrrr�testRequireList�szHeaderTests.testRequireListcCs�tg�}|jt|�d�|jdddd�|j|dd�|jt|�d�|jddd	d�|j|jd�dd
g�|jt|�d�dS)Nz
r�r�r�Zspamzbar; baz="spam"zfoo: bar; baz="spam"

r�Zcheesezbar; cheesez*foo: bar; baz="spam"
Foo: bar; cheese

)rrP�strZ
add_headerr�)rr�rrr�
testExtras�s
zHeaderTests.testExtrasN)rrrr�r�r�rrrrr�psr�c@s7eZdZdZeejj��Zdd�Z	dS)�ErrorHandlerz/Simple handler subclass for testing BaseHandlerc
Ks<t|�tj|t�t�t�|dddd�dS)N�multithreadT�multiprocess)rrrr
r)rrzrrrr�s
zErrorHandler.__init__N)
rrrr�dict�osr'r�Z
os_environrrrrrr��sr�c@s"eZdZdZdd�ZdS)�TestHandlerzASimple handler subclass for testing BaseHandler, w/error passthrucCs�dS)Nr)rrrr�handle_error�szTestHandler.handle_errorN)rrrrr�rrrrr��sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�HandlerTestscCss|j}xcdddddgD]L}|dkrF|jdkrFqn|jt|d|�|d|�qWdS)NrNr�r�Zrun_onceZfile_wrapperZwsgi_zwsgi.)r'Zwsgi_file_wrapperrP�getattr)r�handlerrs�attrrrr�checkEnvironAttrs�s	zHandlerTests.checkEnvironAttrscCs�i}t|�|j}ddlm}x=|j�D]/\}}||kr6|j|||�q6q6Wx*|j�D]\}}|j||�qvWdS)Nr)r')rr'r�r�rP�assertIn)rr��emptyrsr'�k�vrrr�checkOSEnviron�s
	zHandlerTests.checkOSEnvironcCsNtdd�}|j�|j|�|j|�|j|jdd�dS)N�X�Y)r�rr�r�rPr')rr�rrr�testEnviron�s



zHandlerTests.testEnvironcCsGtdddi�}|j�x!dD]}|j||j�q&WdS)N�wsgi.url_scheme�
wsgi.input�wsgi.errors)r�r�r�)rrr�r')rr�rvrrr�testCGIEnviron�s

zHandlerTests.testCGIEnvironcCs^tdd�}|j�|j|jdd�t�}|j�|j|jdd�dS)Nr�r�zwsgi.url_schemer�r�)r�rrPr')rr�rrr�
testScheme�s
	
zHandlerTests.testSchemecCsYt�}x3ddddgD]}|jtt||��qW|jt|jd�dS)NZ_flushZ	get_stdinZ
get_stderrZadd_cgi_varsr�)rr��NotImplementedErrorr�Z_write)rr��namerrr�testAbstractMethods�s
	z HandlerTests.testAbstractMethodscCsdd�}dd�}dd�}dd�}t�}|j|�|j|jj�d	jd
��t�}|j|�|j|jj�djd
��t�}|j|�|j|jj�d�t�}|j|�|j|jj�d
�dS)NcSs!|dg�|djd�gS)Nz200 OKzwsgi.url_schemez
iso-8859-1)r1)rfrgrrr�trivial_app1�s
z4HandlerTests.testContentLength.<locals>.trivial_app1cSs$|dg�|djd��gS)Nz200 OKzwsgi.url_schemez
iso-8859-1)r1)rfrgrrr�trivial_app2�s z4HandlerTests.testContentLength.<locals>.trivial_app2cSs|dg�djd�gS)Nz200 OKuтестzutf-8)r1)rfrgrrr�trivial_app3�s
z4HandlerTests.testContentLength.<locals>.trivial_app3cSs|ddg�gS)Nz200 OK�Content-Length�12345)r�r�r)rfrgrrr�trivial_app4�sz4HandlerTests.testContentLength.<locals>.trivial_app4z)Status: 200 OK
Content-Length: 4

httpz
iso-8859-1zStatus: 200 OK

https-Status: 200 OK
Content-Length: 8

тестs)Status: 200 OK
Content-Length: 12345

)r��runrP�stdoutr9r1)rr�r�r�r�r�rrr�testContentLength�s,	

	

	
	
zHandlerTests.testContentLengthcCs�dd�}dd�}t�}|j|�|j|jj�djd��|j|jj�d�t�}|j|�|j|jj�d|jt|j	�fjd�|j	�|j
d	|jj��dS)
NcSs|dg�gS)Nz200 OKr)rfrgrrr�
non_error_app!s
z8HandlerTests.testBasicErrorOutput.<locals>.non_error_appcSstd��dS)Nz This should be caught by handler)r@)rfrgrrr�	error_app%sz4HandlerTests.testBasicErrorOutput.<locals>.error_appz%Status: 200 OK
Content-Length: 0

z
iso-8859-1r3z<Status: %s
Content-Type: text/plain
Content-Length: %d

r@)r�r�rPr�r9r1r8Zerror_statusr�Z
error_bodyr�)rr�r�r�rrr�testBasicErrorOutputs	

	
z!HandlerTests.testBasicErrorOutputcsqd��fdd�}t�}|j|�|j|jj�djd���|jd|jj��dS)NsSome output has been sentcs#|dg���td��dS)Nz200 OKz This should be caught by handler)r@)rfrg)�MSGrrr�=sz4HandlerTests.testErrorAfterOutput.<locals>.error_appzStatus: 200 OK

z
iso-8859-1r@)r�r�rPr�r9r1r�r8)rr�r�r)r�r�testErrorAfterOutput;s	
z!HandlerTests.testErrorAfterOutputc	Cswdd�}d}djd�}xOdD]G}|r>d|pAd}x(dD] }xdD]}td|�}d|_||_||_|j|�|j||jj��td|�}d|_||_||_|j|�|dkr
|j|jj�d�qX|j	t
j|||fjd�|jj��|||fjd�|jj�f�qXWqKWq(WdS)NcSs|dg�gS)Nz200 OKr)rfrgrrrr�Js
z5HandlerTests.testHeaderFormats.<locals>.non_error_appzfHTTP/%s 200 OK\r\nDate: \w{3}, [ 0123]\d \w{3} \d{4} \d\d:\d\d:\d\d GMT\r\n%sContent-Length: 0\r\n\r\nz%Status: 200 OK
Content-Length: 0

z
iso-8859-1�
FooBar/1.0zServer: %s
r3�1.0�1.1�HTTP/0.9�HTTP/1.0�HTTP/1.1r�FT�)r�N)r�r�)r�r�r�)r1r�Z
origin_serverZhttp_versionZserver_softwarer�rPr�r9r`�rerG)	rr�ZstdpatZshortpatZsswZswrN�protor�rrr�testHeaderFormatsHs4	


			
			
zHandlerTests.testHeaderFormatscCs?dd�}t�}|j|�|jd|jj��dS)NcSs|ddg�dgS)Nz200 OK�Content-Type�text/plain; charset=utf-8sdata)r�r�r)rfrgrrrr:ts
z'HandlerTests.testBytesData.<locals>.appsRStatus: 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 4

data)r�r�rPr�r9)rr:r�rrr�
testBytesDatass
	
	zHandlerTests.testBytesDatacsVidd6�d���fdd�}t�}|j|�|j�dd�dS)NF�close_calledsSome output has been sentcs6|dg���G�fdd�dt�}|�S)Nz200 OKcs.eZdZdd�Z�fdd�ZdS)zHHandlerTests.testCloseOnError.<locals>.error_app.<locals>.CrashyIterablecssxdVtd��qWdS)Nsblahz This should be caught by handler)r@)rrrr�__iter__�szQHandlerTests.testCloseOnError.<locals>.error_app.<locals>.CrashyIterable.__iter__csd�d<dS)NTr�r)r)�side_effectsrrr��szNHandlerTests.testCloseOnError.<locals>.error_app.<locals>.CrashyIterable.closeN)rrrr�r�r)r�rr�CrashyIterable�sr�)�object)rfrgr�)r�r�rrr��sz0HandlerTests.testCloseOnError.<locals>.error_appT)r�r�rP)rr�r�r)r�r�r�testCloseOnError�s
	
zHandlerTests.testCloseOnErrorN)rrrr�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s	
2
+r�cCstjt�dS)N)rZrun_unittestrrrrr�	test_main�sr�__main__),ZunittestrZwsgiref.utilrZwsgiref.headersrZwsgiref.handlersrrZwsgirefrZwsgiref.validaterZwsgiref.simple_serverr	r
r�iorr
rZsocketserverr�platformrr�r�r7r�rrrr)r2r>rKrLrpr�r�r�r�rrrrrr�<module>s<
%[�7�