Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/test/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/__pycache__/test_wsgiref.cpython-36.pyc

3

� fWl�@s�ddlmZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
mZddlmZdd	lmZdd
lmZmZddlmZddlmZdd
lmZmZmZddlmZddlm Z ddl!Z!ddl"Z"ddl#Z#ddl$Z$ddlZGdd�de�Z%Gdd�de�Z&dd�Z'dd�Z(e'dfdd�Z)dd�Z*Gdd�de�Z+Gd d!�d!e�Z,Gd"d#�d#e�Z-Gd$d%�d%e
�Z.Gd&d'�d'e.�Z/Gd(d)�d)e�Z0e1d*k�r�ej2�dS)+�)�mock)�support)�NoLogRequestHandler)�TestCase)�setup_testing_defaults)�Headers)�BaseHandler�BaseCGIHandler�
SimpleHandler)�util)�	validator)�
WSGIServer�WSGIRequestHandler)�make_server)�HTTPConnection)�StringIO�BytesIO�BufferedReader)�
BaseServer)�python_implementationNc@s eZdZdZdd�Zdd�ZdS)�
MockServerzNon-socket HTTP servercCstj|||�|j�dS)N)r�__init__�server_bind)�self�server_addressZRequestHandlerClass�r�6/opt/alt/python36/lib64/python3.6/test/test_wsgiref.pyrszMockServer.__init__cCs"|j\}}||_||_|j�dS)N)rZserver_nameZserver_port�
setup_environ)r�hostZportrrrrs
zMockServer.server_bindN)�__name__�
__module__�__qualname__�__doc__rrrrrrrsrc@s eZdZdZdd�Zdd�ZdS)�MockHandlerzNon-socket HTTP handlercCs|j|_|j\|_|_dS)N)�requestZ
connectionZrfileZwfile)rrrr�setup(szMockHandler.setupcCsdS)Nr)rrrr�finish,szMockHandler.finishN)rr r!r"r%r&rrrrr#&sr#cCs|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_app0sr-cCs2|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/)r)r0)�join�encode)r+r,rrr�
header_app8sr6sGET / HTTP/1.0

cCsbtdd|tt�}tt|��}t�}tj}t�}t_z|j||fd�Wd|t_X|j	�|j	�fS)N��P�	127.0.0.1�")r9r:)
rrr#rr�sys�stderrrZfinish_request�getvalue)�app�data�serverZinp�outZolderr�errrrr�	run_amockCsrCcCs�|�}d}x$|D]}|||ks$t�|d7}qWy||Wntk
rPYnXtd|��yttfWntk
r|YnbX|�}t|�|k	r�t�x|D]}t|�|ks�t�q�Wyt|�Wntk
r�YnXtd|��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_iterQs4


rPc@sfeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�IntegrationTestsTcCsFt�dtjj�d}|j|d|d|r0dp2ddjd��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
r7z
Hello, world!z
iso-8859-1)rr;�version�split�assertEqualr5)rrA�
has_length�pyverrrr�check_helloxszIntegrationTests.check_hellocCst�\}}|j|�dS)N)rCrX)rrArBrrr�test_plain_hello�s
z!IntegrationTests.test_plain_hellocCs*d}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

rDs+Python test,Python test 2;query=test;/path/���)rCr6rU�
splitlines)rr$rArBrrr�test_environ�s

zIntegrationTests.test_environcCs2tddddd�\}}|j|j�dd�dS)NsGET �xis HTTP/1.0

)r?rs!HTTP/1.0 414 Request-URI Too Long)rCrUr[)rrArBrrr�test_request_length�sz$IntegrationTests.test_request_lengthcCs"ttt��\}}|j|dd�dS)NF)rV)rCrr-rX)rrArBrrr�test_validated_hello�sz%IntegrationTests.test_validated_hellocCs@dd�}tt|��\}}|j|jd��|j|j�dd�dS)NcSs|dd�dgS)Nz200 OK�Content-Type�
text/plainz
Hello, world!)r`rar)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'>���)rCr�
assertTrue�endswithrUr[)rrbrArBrrr�test_simple_validation_error�s
z-IntegrationTests.test_simple_validation_errorcCstdd�}dd
dg}x\|D]T\}}|j|d	��:t||��\}}|j|jd
��|j|j�d|�WdQRXqWdS)Ncs�fdd�}|S)Ncs|�dg�dgS)N�Content-Type�text/plain; charset=utf-8s
Hello, world!)rhrir)r+r,)�statusrrrb�szWIntegrationTests.test_status_validation_errors.<locals>.create_bad_app.<locals>.bad_appr)rjrbr)rjr�create_bad_app�szFIntegrationTests.test_status_validation_errors.<locals>.create_bad_app�200�4AssertionError: Status must be at least 4 characters�20X OK�8AssertionError: Status message must begin w/3-digit code�200OK�;AssertionError: Status message must have a space after code)rjs;A server error occurred.  Please contact the administrator.rc)rlrm)rnro)rprqrd)ZsubTestrCrerfrUr[)rrkZtestsrjZexc_messagerArBrrr�test_status_validation_errors�sz.IntegrationTests.test_status_validation_errorscCs@dd�}tt|��\}}|j|jd��|j|j�dd�dS)NcSs|dj�|ddg�dgS)Nz
wsgi.inputz200 OK�Content-Type�text/plain; charset=utf-8sdata)rsrt)�read)�e�srrrrb�sz1IntegrationTests.test_wsgi_input.<locals>.bad_apps;A server error occurred.  Please contact the administrator.rcrErd)rCrrerfrUr[)rrbrArBrrr�test_wsgi_input�sz IntegrationTests.test_wsgi_inputcCsldd�}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)ryrz)r)r{r)rvrwrrrr>�sz3IntegrationTests.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)
rCrrerfr;rSrTr5rrU)rr>rArBZver�pyrWrrr�test_bytes_validation�s
z&IntegrationTests.test_bytes_validationcCs>dd�}tt|�dd�\}}|jdtjdddd	g|j��dS)
NcSs|ddd	g�|djd�gS)
Nz200 OK�Content-Type�
text/plainr)�Wed, 24 Dec 2008 13:29:32 GMTr3�latin1)r�r�)r)r�)r5)rvrwrrrr>�sz-IntegrationTests.test_cp1252_url.<locals>.appsGET /�%80 HTTP/1.0)r?sHTTP/1.0 200 OKsContent-Type: text/plains#Date: Wed, 24 Dec 2008 13:29:32 GMT�s/��)rCrrUr�ANYr[)rr>rArBrrr�test_cp1252_url�s	z IntegrationTests.test_cp1252_urlcs�tjd�}tjtd��dd�}Gdd�dtt�}ttjd||d��|j�j	�|j
���fd	d
�}tjtj|�}|jtjtj|�d�|j�������fdd�}|j
|d
�}|j��j�|j�|j�tjd�dS)N�	threading�pthread_killcSs|dg�dtjgS)Nz200 OK�)r�
SOCK_MAX_SIZE)r+r,rrrr>s
z4IntegrationTests.test_interrupted_write.<locals>.appc@seZdZdS)z<IntegrationTests.test_interrupted_write.<locals>.WsgiHandlerN)rr r!rrrr�WsgiHandlersr�r)Z
handler_classcs�j�dS)N)�set)Zsignum�frame)�interruptedrr�signal_handlersz?IntegrationTests.test_interrupted_write.<locals>.signal_handlerc
spt�j�}|jdd�|j��@}|jd�x"��tj��jtd�d�r,Pq,Wt	|j���WdQRX|j
�dS)N�GETrR�drD)Ztimeout)rrr$Zgetresponseru�signal�SIGUSR1�wait�float�len�close)�httpZresponse)r��main_threadr��receivedr@rr�
run_clients


z;IntegrationTests.test_interrupted_write.<locals>.run_client)�targetr�)r�
import_moduleZ
get_attributer�rrrZHOSTZ
addCleanupZserver_closeZEventr��	get_identZThread�startZhandle_requestr4rUr�)rr�r>r�r�Zoriginalr�Z
backgroundr)r�r�r�r�r@r�test_interrupted_write�s$
z'IntegrationTests.test_interrupted_writeN)T)rr r!rXrYr\r^r_rgrrrxrr�r�rrrrrQvs



rQc@s�eZdZdd�Zd!dd�Zdd�Zdd	�Zd"dd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �ZdS)#�UtilityTestscCsJ||d�}tj|�|jtj|�|�|j|d|�|j|d|�|S)N)�SCRIPT_NAMEr3r3r�)rrrUZshift_path_info)rZsn_inZpi_in�partZsn_outZpi_out�envrrr�
checkShift1s

zUtilityTests.checkShiftNcCs|i}tj|�t|t�r*|j||t�n,t|t�rF|j||t�n|j|||�||i}tj|�|j|||�dS)N)rr�
isinstancerZassertIsInstancerrUZassertIs)r�key�value�altr�rrr�checkDefault9s



zUtilityTests.checkDefaultcKstj|�|j|||�dS)N)rrrU)rr�r��kwrrr�checkCrossDefaultIs
zUtilityTests.checkCrossDefaultcKs tj|�|jtj|�|�dS)N)rrrUZapplication_uri)r�urir�rrr�checkAppURIMs
zUtilityTests.checkAppURIrDcKs"tj|�|jtj||�|�dS)N)rrrUZrequest_uri)rr�Zqueryr�rrr�checkReqURIQs
zUtilityTests.checkReqURIcCsb||fdd�}t||�|�}|j|jj�x|D]}q2W|j|jj�|j�|j|jj�dS)NcSstjt|�|�S)N)rZFileWrapperr)�text�sizerrrrKWsz%UtilityTests.checkFW.<locals>.make_it)rP�assertFalseZfilelike�closedr�re)rr�r�rLrKrMrOrrr�checkFWUs

zUtilityTests.checkFWcCs^|jddddd�|jddddd�|jddddd�|jddddd�|jdd	ddd�dS)
Nr7rRz/x�xz/az/x/yz/a/xz/yz/x/)r�)rrrr�testSimpleShiftsgs
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/yr7z//y�yz/a/b/yz//y/rRz/./yz/./y/z///./..//y/.//z/y/z///z/a/b/z/.//z/x//r�z/a/b/xz/.)r�)rrrr�testNormalizedShiftsnsz!UtilityTests.testNormalizedShiftscCsJxDdddddddd d!d"d#dt�fdt�fd$gD]\}}|j||�q.WdS)%N�SERVER_NAME�	127.0.0.1�SERVER_PORT�80�SERVER_PROTOCOL�HTTP/1.0�	HTTP_HOST�REQUEST_METHODr�r�r7r3rR�wsgi.versionrDr�
wsgi.run_once�wsgi.multithread�wsgi.multiprocessz
wsgi.inputzwsgi.errors�wsgi.url_schemer�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r7)r3rR�rDr)r�r�)r�r)r�r)r�r)r�r�)rrr�)rr�r�rrr�testDefaults{s zUtilityTests.testDefaultscCst|jdddd�|jdddd�|jdddd�|jddd	d�|jdd
dd�|jdd
dd�|jdddd�dS)Nr�zfoo.bar)r�zwsgi.url_scheme�https�on)�HTTPS�1�yesr��foor�r�Z443)r�)rrrr�testCrossDefaults�szUtilityTests.testCrossDefaultscCsn|jtji�d�|jtjddi�d�|jtjddi�d�|jtjddi�d�|jtjddi�d�dS)Nr�r�r�r�r�r�r�)rUrZguess_scheme)rrrr�testGuessScheme�s
zUtilityTests.testGuessSchemecCsv|jd�|jddd�|jddd�|jddd	d
�|jddd
�|jdddd�|jddd�|jdddd�dS)Nzhttp://127.0.0.1/zhttp://127.0.0.1/spamz/spam)r�zhttp://127.0.0.1/sp%E4mu/spämzhttp://spam.example.com:2071/zspam.example.com:2071Z2071)r�r�zhttp://spam.example.com/zspam.example.com)r�z	127.0.0.1)r�r�zhttps://127.0.0.1/r�)r�zhttp://127.0.0.1:8000/Z8000)r�r�)r�)rrrr�testAppURIs�s


zUtilityTests.testAppURIscCs�|jd�|jddd�|jddd�|jdddd	�|jd
ddd	�|jdddd	�|jd
ddd	�|jddddd�|jddddd�|jdddddd�dS)Nzhttp://127.0.0.1/zhttp://127.0.0.1/spamz/spam)r�zhttp://127.0.0.1/sp%E4mu/spämzhttp://127.0.0.1/spammity/spamz	/spammity)r�r3z 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=nizsay=ni)r�r3r2z'http://127.0.0.1/spammity/spam?s%E4y=nizs%E4y=nir)r�)rrrr�testReqURIs�s"




zUtilityTests.testReqURIscCs"|jdddddddg�dS)NZxyz�2�x�(�
)r�)rrrr�testFileWrapper�szUtilityTests.testFileWrappercCs�xBdj�D]6}x0||j�|j�|j�fD]}|jtj|��q(Wq
WxBdj�D]6}x0||j�|j�|j�fD]}|jtj|��qlWqNWdS)NzbConnection Keep-Alive Proxy-Authenticate Proxy-Authorization TE Trailers Transfer-Encoding Upgradez4Accept Cache-Control Date Pragma Trailer Via Warning)rT�title�upper�lowerrerZ
is_hop_by_hopr�)rZhopr�rrr�testHopByHop�szUtilityTests.testHopByHop)N)rD)rr r!r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�/s


	r�c@s$eZdZdd�Zdd�Zdd�ZdS)�HeaderTestscCs�dg}|jtt��d�|jttg��d�|jtt|dd���d�|jt|dd��j�dg�|jt|dd��j�dg�|jt|dd��j�|�|jt|�j�|�t�}|d=d|d<xT|j|j|j	|j
fD]<}|j|d��|j|d��|j|d��|j|d��q�W|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�rrDr��bar�FooZFOO�bazZwheeZzoo)r�r�)rUr�r�keys�values�itemsZassertIsNot�__contains__�get�get_all�__getitem__rer��
setdefault)r�test�h�mrrr�testMappingInterface�s4z HeaderTests.testMappingInterfacecCs|jttd�dS)Nr�)�assertRaises�	TypeErrorr)rrrr�testRequireList�szHeaderTests.testRequireListcCs�t�}|jt|�d�|jdddd�|j|dd�|jt|�d�|jdddd	�|j|jd�dd
g�|jt|�d�dS)Nz
r�r�Zspam)r�zbar; baz="spam"zfoo: bar; baz="spam"

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

)rrU�strZ
add_headerr�)rr�rrr�
testExtras�s

zHeaderTests.testExtrasN)rr r!r�r�r�rrrrr��s r�c@s&eZdZdZeejj��Zdd�Z	dS)�ErrorHandlerz/Simple handler subclass for testing BaseHandlerc	Ks*t|�tj|t�t�t�|ddd�dS)NT)�multithread�multiprocess)rr	rrr)rr�rrrrszErrorHandler.__init__N)
rr r!r"�dict�osr+r�Z
os_environrrrrrr�sr�c@seZdZdZdd�ZdS)�TestHandlerzASimple handler subclass for testing BaseHandler, w/error passthrucCs�dS)Nr)rrrr�handle_errorszTestHandler.handle_errorN)rr r!r"r�rrrrr�sr�c@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�HandlerTestscCsJ|j}x>dD]6}|dkr$|jdkr$q|jt|d|�|d|�qWdS)	NrSr�r��run_once�file_wrapperZwsgi_zwsgi.)rSr�r�r�r�)r+Zwsgi_file_wrapperrU�getattr)r�handlerr��attrrrr�checkEnvironAttrs szHandlerTests.checkEnvironAttrscCsri}t|�|j}ddlm}x,|j�D] \}}||kr(|j|||�q(Wx |j�D]\}}|j||�qVWdS)Nr)r+)rr+r�r�rU�assertIn)rr��emptyr�r+�k�vrrr�checkOSEnviron)szHandlerTests.checkOSEnvironcCs<tdd�}|j�|j|�|j|�|j|jdd�dS)N�Y)�Xr)r�rr�rrUr+)rr�rrr�testEnviron3s



zHandlerTests.testEnvironcCs6tdddi�}|j�xdD]}|j||j�qWdS)N�wsgi.url_scheme�
wsgi.input�wsgi.errors)rrr)r	rr�r+)rr�r�rrr�testCGIEnviron:s
zHandlerTests.testCGIEnvironcCsHtdd�}|j�|j|jdd�t�}|j�|j|jdd�dS)Nr�)r�zwsgi.url_schemer�r�)r�rrUr+)rr�rrr�
testScheme@s
zHandlerTests.testSchemecCs:t�}xdD]}|jtt||��qW|jt|jd�dS)N�_flush�	get_stdin�
get_stderr�add_cgi_varsr�)rrr
r)rr��NotImplementedErrorr�Z_write)rr��namerrr�testAbstractMethodsFs
z HandlerTests.testAbstractMethodscCs�dd�}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)r5)rvrwrrr�trivial_app1Qs
z4HandlerTests.testContentLength.<locals>.trivial_app1cSs|dg�|djd��gS)Nz200 OKzwsgi.url_schemez
iso-8859-1)r5)rvrwrrr�trivial_app2Usz4HandlerTests.testContentLength.<locals>.trivial_app2cSs|dg�djd�gS)Nz200 OKuтестzutf-8)r5)rvrwrrr�trivial_app3Ys
z4HandlerTests.testContentLength.<locals>.trivial_app3cSs|ddg�gS)Nz200 OK�Content-Length�12345)rrr)rvrwrrr�trivial_app4]sz4HandlerTests.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��runrU�stdoutr=r5)rrrrrr�rrr�testContentLengthNs,



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)rvrwrrr�
non_error_app�s
z8HandlerTests.testBasicErrorOutput.<locals>.non_error_appcSstd��dS)Nz This should be caught by handler)rE)rvrwrrr�	error_app�sz4HandlerTests.testBasicErrorOutput.<locals>.error_appz%Status: 200 OK
Content-Length: 0

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

rE)r�rrUrr=r5r<Zerror_statusr�Z
error_bodyr�)rrrr�rrr�testBasicErrorOutput�s


z!HandlerTests.testBasicErrorOutputcsRd��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)rE)rvrw)�MSGrrr�sz4HandlerTests.testErrorAfterOutput.<locals>.error_appzStatus: 200 OK

z
iso-8859-1rE)r�rrUrr=r5r�r<)rrr�r)rr�testErrorAfterOutput�s
z!HandlerTests.testErrorAfterOutputc	Csdd�}d}djd�}�x�dD]�}|r.d|p0d}x�dD]�}x�dD]�}t|d�}d|_||_||_|j|�|j||jj��t|d�}d|_||_||_|j|�|dkr�|j|jj�d�qB|j	t
j|||fjd�|jj��|||fjd�|jj�f�qBWq8WqWdS)NcSs|dg�gS)Nz200 OKr)rvrwrrrr�s
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
r7�1.0�1.1�HTTP/0.9�HTTP/1.0�HTTP/1.1)r�FTr�)r N)r!r")r#r$r%)r5r�Z
origin_serverZhttp_versionZserver_softwarerrUrr=re�rerL)	rrZstdpatZshortpatZssw�swrS�protor�rrr�testHeaderFormats�s4






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

data)r�rrUrr=)rr>r�rrr�
testBytesData�s

zHandlerTests.testBytesDatacs>ddi�d���fdd�}t�}|j|�|j�dd�dS)N�close_calledFsSome output has been sentcs(|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)rE)rrrr�__iter__�szQHandlerTests.testCloseOnError.<locals>.error_app.<locals>.CrashyIterable.__iter__csd�d<dS)NTr-r)r)�side_effectsrrr��szNHandlerTests.testCloseOnError.<locals>.error_app.<locals>.CrashyIterable.closeN)rr r!r.r�r)r/rr�CrashyIterable�sr0)�object)rvrwr0)rr/rrr�sz0HandlerTests.testCloseOnError.<locals>.error_appT)r�rrU)rrr�r)rr/r�testCloseOnError�s
zHandlerTests.testCloseOnErrorc
sjt��G�fdd�d�}ddi}tt�|�tj|�}d}|jt|��|jt�WdQRX|j	d��dS)Ncs eZdZ�fdd�Zdd�ZdS)z4HandlerTests.testPartialWrite.<locals>.PartialWritercs|dd�}�j|�t|�S)N�)�extendr�)r�b�partial)�writtenrr�write�s
z:HandlerTests.testPartialWrite.<locals>.PartialWriter.writecSsdS)Nr)rrrr�flush�sz:HandlerTests.testPartialWrite.<locals>.PartialWriter.flushN)rr r!r8r9r)r7rr�
PartialWriter�sr:r�zHTTP/1.0zshould not do partial writesssHTTP/1.0 200 OK
Content-Type: text/plain
Date: Mon, 05 Jun 2006 18:49:54 GMT
Content-Length: 13

Hello, world!)
�	bytearrayr
rr;r<ZassertWarnsRegex�DeprecationWarningrr-rU)rr:r+r��msgr)r7r�testPartialWrite�s	zHandlerTests.testPartialWriteN)rr r!r�rrr	r
rrrrr)r,r2r>rrrrr�s	
2
+r��__main__)3Zunittestrr�rZtest.test_httpserversrrZwsgiref.utilrZwsgiref.headersrZwsgiref.handlersrr	r
ZwsgirefrZwsgiref.validaterZwsgiref.simple_serverr
rrZhttp.clientr�iorrrZsocketserverr�platformrr�r&r�r;rr#r-r6rCrPrQr�r�r�r�r�r�mainrrrr�<module>sH
%:#7s