Your IP : 216.73.216.85


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_wsgiref.cpython-39.opt-2.pyc

a

XC?h�x�@s�ddlmZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZmZmZdd	lmZdd
lmZddlmZmZddlmZdd
lmZddlmZmZmZddlm Z ddl!m"Z"ddl#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 �d e�Z.Gd!d"�d"e�Z/Gd#d$�d$e�Z0Gd%d&�d&e�Z1Gd'd(�d(e1�Z2Gd)d*�d*e�Z3e4d+k�r�e�5�dS),�)�mock)�support)�
socket_helper)�NoLogRequestHandler)�TestCase)�setup_testing_defaults)�Headers)�BaseHandler�BaseCGIHandler�
SimpleHandler)�util)�	validator)�
WSGIServer�WSGIRequestHandler)�make_server)�HTTPConnection)�StringIO�BytesIO�BufferedReader)�
BaseServer)�python_implementationNc@seZdZdd�Zdd�ZdS)�
MockServercCst�|||�|��dS�N)r�__init__�server_bind)�self�server_addressZRequestHandlerClass�r�6/opt/alt/python39/lib64/python3.9/test/test_wsgiref.pyrszMockServer.__init__cCs"|j\}}||_||_|��dSr)rZserver_nameZserver_port�
setup_environ)rZhostZportrrrr!s
zMockServer.server_bindN)�__name__�
__module__�__qualname__rrrrrrrsrc@seZdZdd�Zdd�ZdS)�MockHandlercCs|j|_|j\|_|_dSr)�requestZ
connectionZrfileZwfile�rrrr�setup*szMockHandler.setupcCsdSrrr%rrr�finish.szMockHandler.finishN)r r!r"r&r'rrrrr#(sr#cCs|dddg�dgS)N�200 OK��Content-Typez
text/plain��DatezMon, 05 Jun 2006 18:49:54 GMT�
Hello, world!r��environZstart_responserrr�	hello_app2s
�r0cCs2|dddg�d�|d|d|dg��d�gS)	Nr(r)r+�;ZHTTP_X_TEST_HEADER�QUERY_STRING�	PATH_INFO�
iso-8859-1)�join�encoder.rrr�
header_app:s���r7sGET / HTTP/1.0

cCshtdd|tt�}tt|��}t�}tj}t�}t_z|�||fd�W|t_n|t_0|�	�|�	�fS)N��P)�	127.0.0.1i�")
rrr#rr�sys�stderrrZfinish_request�getvalue)�app�data�serverZinp�outZolderr�errrrr�	run_amockEsrCcCs�|�}d}|D]}|||ks"t�|d7}qz||WntyJYn0td|��zttfWntytYn\0|�}t|�|ur�t�|D]}t|�|ks�t�q�zt|�Wnty�Yn0td|��dS)Nr�zToo many items from __getitem__zToo many items from .__next__())�AssertionError�
IndexError�iter�
StopIteration�	NameError�next)�make_it�match�it�n�itemrrr�compare_generic_iterSs.

rPc@sfeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�IntegrationTestsTcCsFt�dtj��d}|�|d|d|r0dp2dd�d��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
r8z
Hello, world!r4)rr;�version�split�assertEqualr6)rrA�
has_length�pyverrrr�check_hellozs ���
����zIntegrationTests.check_hellocCst�\}}|�|�dSr)rCrX�rrArBrrr�test_plain_hello�s
z!IntegrationTests.test_plain_hellocCs*d}tt|�\}}|�|��dd�dS)NsmGET /p%61th/?query=test HTTP/1.0
X-Test-Header: Python test 
X-Test-Header: Python test 2
Content-Length: 0

���s+Python test,Python test 2;query=test;/path/)rCr7rU�
splitlines)rr$rArBrrr�test_environ�s�
�zIntegrationTests.test_environcCs2tddddd�\}}|�|��dd�dS)NsGET �xis HTTP/1.0

�r?rs!HTTP/1.0 414 Request-URI Too Long)rCrUr\rYrrr�test_request_length�s�z$IntegrationTests.test_request_lengthcCs"ttt��\}}|j|dd�dS)NF)rV)rCr
r0rXrYrrr�test_validated_hello�sz%IntegrationTests.test_validated_hellocCs@dd�}tt|��\}}|�|�d��|�|��dd�dS)NcSs|dd�dgS)Nr(r)z
Hello, world!rr.rrr�bad_app�s
z>IntegrationTests.test_simple_validation_error.<locals>.bad_app�;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_errorc	Cs�dd�}gd�}|D]h\}}|j|d��Dt||��\}}|�|�d��|�|��d|�Wd�q1sr0YqdS)Ncs�fdd�}|S)Ncs|�dg�dgS)N�r*ztext/plain; charset=utf-8r-rr.��statusrrrb�szWIntegrationTests.test_status_validation_errors.<locals>.create_bad_app.<locals>.bad_appr)rlrbrrkr�create_bad_app�szFIntegrationTests.test_status_validation_errors.<locals>.create_bad_app))Z200z4AssertionError: Status must be at least 4 characters)z20X OKz8AssertionError: Status message must begin w/3-digit code)Z200OKz;AssertionError: Status message must have a space after coderkrcrd)�subTestrCrfrgrUr\)rrmZtestsrlZexc_messagerArBrrr�test_status_validation_errors�s�z.IntegrationTests.test_status_validation_errorscCs@dd�}tt|��\}}|�|�d��|�|��dd�dS)NcSs|d��|ddg�dgS)N�
wsgi.inputr(rj�data)�read��e�srrrrb�sz1IntegrationTests.test_wsgi_input.<locals>.bad_apprcrdrErerhrrr�test_wsgi_input�s��z IntegrationTests.test_wsgi_inputcCsldd�}tt|��\}}|�|�d��tj��d�d�}t��d�}|d|}|�	d|d|�dS)	NcSs|dddg�dgS)Nr(rj�r,zWed, 24 Dec 2008 13:29:32 GMTrqrrsrrrr>�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)
rCr
rfrgr;rSrTr6rrU)rr>rArBZver�pyrWrrr�test_bytes_validation�s���z&IntegrationTests.test_bytes_validationcCs>dd�}tt|�dd�\}}|�dtjdddd	g|���dS)
NcSs|dddg�|d�d�gS)Nr(r)rwr3�latin1�r6rsrrrr>�s
�z-IntegrationTests.test_cp1252_url.<locals>.appsGET /�%80 HTTP/1.0r_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�t�td��dd�}Gdd�dtt�}ttjd||d��|��j	�t
����fdd	�}t�tj|�}|�tjtj|�d�t
�
�������fd
d�}t
j|d�}|�����|��|��tjd
�dS)N�pthread_killcSs|dg�dtjgS)Nr(�)r�
SOCK_MAX_SIZEr.rrrr>s
z4IntegrationTests.test_interrupted_write.<locals>.appc@seZdZdS)z<IntegrationTests.test_interrupted_write.<locals>.WsgiHandlerN�r r!r"rrrr�WsgiHandlersr�r)Z
handler_classcs���dSr)�set)Zsignum�frame)�interruptedrr�signal_handlersz?IntegrationTests.test_interrupted_write.<locals>.signal_handlercs�t�j�}|�dd�|���F}|�d���tj��jtd�d�r*qJq*t	|����Wd�n1sj0Y|�
�dS)N�GETrR�drD)Ztimeout)rrr$Zgetresponserr�signal�SIGUSR1�wait�float�len�close)�httpZresponse�r�Zmain_threadr�Zreceivedr@rr�
run_clients


*z;IntegrationTests.test_interrupted_write.<locals>.run_client)�targetr�)rZ
get_attributer�rrrrZHOSTZ
addCleanupZserver_close�	threadingZEventr��	get_identZThread�startZhandle_requestr5rUr�)rr>r�r�Zoriginalr�Z
backgroundrr�r�test_interrupted_write�s"z'IntegrationTests.test_interrupted_writeN)T)r r!r"rXrZr]r`rarirorvr{r�r�rrrrrQxs



rQc@s�eZdZdd�Zd$dd�Zdd�Zdd	�Zd%dd�Zej	e
d
�dd��Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�ZdS)&�UtilityTestscCsJ||d�}t�|�|�t�|�|�|�|d|�|�|d|�|S)N��SCRIPT_NAMEr3r3r�)rrrUZshift_path_info)rZsn_inZpi_in�partZsn_outZpi_out�envrrr�
checkShift2s

zUtilityTests.checkShiftNcCs|i}t�|�t|t�r*|�||t�n,t|t�rF|�||t�n|�|||�||i}t�|�|�|||�dSr)rr�
isinstancerZassertIsInstancerrUZassertIs)r�key�value�altr�rrr�checkDefault:s



zUtilityTests.checkDefaultcKst�|�|�|||�dSr)rrrU)rr�r��kwrrr�checkCrossDefaultJs
zUtilityTests.checkCrossDefaultcKs t�|�|�t�|�|�dSr)rrrUZapplication_uri)r�urir�rrr�checkAppURINs
zUtilityTests.checkAppURIrDcKs"t�|�|�t�||�|�dSr)rrrUZrequest_uri)rr�Zqueryr�rrr�checkReqURIRs
zUtilityTests.checkReqURI)�categorycCs^||fdd�}t||�|�}|�|jj�|D]}q0|�|jj�|��|�|jj�dS)NcSst�t|�|�Sr)r�FileWrapperr)�text�sizerrrrKYsz%UtilityTests.checkFW.<locals>.make_it)rP�assertFalseZfilelike�closedr�rf)rr�r�rLrKrMrOrrr�checkFWVs
zUtilityTests.checkFWcCsPt�td�d�}|�td�� |�|dd�Wd�n1sB0YdS)NZfoobar�zUse iterator protocol insteadrD�foo)rr�r�assertWarnsRegex�DeprecationWarningrU)r�wrapperrrr�$test_filewrapper_getitem_deprecationis
�z1UtilityTests.test_filewrapper_getitem_deprecationcCs^|�ddddd�|�ddddd�|�ddddd�|�ddddd�|�dd	ddd�dS)
Nr8rRz/x�x�/az/x/yz/a/x�/yz/x/�r�r%rrr�testSimpleShiftsps
zUtilityTests.testSimpleShiftscCs�|�ddddd�|�ddddd�|�dddd	d�|�dd
dd	d�|�dddd	d�|�dd
dd	d�|�ddddd�|�ddddd�|�ddddd�|�ddddd�|�ddddd�dS)Nz/a/bz/../yz..r�r�r8z//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�r%rrr�testNormalizedShiftswsz!UtilityTests.testNormalizedShiftscCsFddddddddd	d
ddt�fd
t�fdfD]\}}|�||�q,dS)N)�SERVER_NAMEr:)�SERVER_PORT�80)�SERVER_PROTOCOL�HTTP/1.0)�	HTTP_HOSTr:)ZREQUEST_METHODr�)r�r8)r3rR)�wsgi.version�rDr)�
wsgi.run_oncer)�wsgi.multithreadr)�wsgi.multiprocessrrp�wsgi.errors)�wsgi.url_schemer�)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�r��https�on��HTTPS�1�yesr�r�r�r�Z443)r�r%rrr�testCrossDefaults�szUtilityTests.testCrossDefaultscCsn|�t�i�d�|�t�ddi�d�|�t�ddi�d�|�t�ddi�d�|�t�ddi�d�dS)Nr�r�r�r�r�r�r�)rUrZguess_schemer%rrr�testGuessScheme�s
zUtilityTests.testGuessSchemecCsv|�d�|jddd�|jddd�|jddd	d
�|jddd
�|jdddd�|jddd�|jdddd�dS)N�http://127.0.0.1/�http://127.0.0.1/spam�/spam�r��http://127.0.0.1/sp%E4m�/spämzhttp://spam.example.com:2071/zspam.example.com:2071Z2071)r�r�zhttp://spam.example.com/zspam.example.comr�r:)r�r�zhttps://127.0.0.1/r�r�zhttp://127.0.0.1:8000/Z8000)r�r�)r�r%rrr�testAppURIs�s 
����zUtilityTests.testAppURIscCs�|�d�|jddd�|jddd�|jdddd	�|jd
ddd	�|jdddd	�|jd
ddd	�|jddddd�|jddddd�|jdddddd�dS)Nr�r�r�r�r�r�zhttp://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=nizsay=ni)r�r3r2z'http://127.0.0.1/spammity/spam?s%E4y=nizs%E4y=nir)r�r%rrr�testReqURIs�s0
�������zUtilityTests.testReqURIscCs|�ddddg�dS)NZ�xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz�xZxxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzZxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz)r�r%rrr�testFileWrapper�szUtilityTests.testFileWrappercCs|d��D]2}||��|��|��fD]}|�t�|��q$qd��D]2}||��|��|��fD]}|�t�|��q`qDdS)NzbConnection Keep-Alive Proxy-Authenticate Proxy-Authorization TE Trailers Transfer-Encoding Upgradez4Accept Cache-Control Date Pragma Trailer Via Warning)rT�title�upper�lowerrfrZ
is_hop_by_hopr�)rZhopr�rrr�testHopByHop�s�
�
zUtilityTests.testHopByHop)N)rD)r r!r"r�r�r�r�r�rZignore_warningsr�r�r�r�r�r�r�r�r�r�r�r�rrrrr�0s"




	r�c@s$eZdZdd�Zdd�Zdd�ZdS)�HeaderTestscCs�dg}|�tt��d�|�ttg��d�|�tt|dd���d�|�t|dd����dg�|�t|dd����dg�|�t|dd����|�|�t|���|�t�}|d=d|d<|j|j|j	|j
fD]<}|�|d��|�|d��|�|d	��|�|d��q�|�|dd�d
|d<|�|d	d
�|�|�	d�d
g�|�|�dd�d
�|�|�dd�d�|�|�
dd�d
�|�|�
dd�d�|�|dd
�|�|dd�dS)
N)r�r�rrDr�r�r��bar�FooZFOO�bazZwheeZzoo)rUr�r�keys�values�itemsZassertIsNot�__contains__�get�get_all�__getitem__rfr��
setdefault)r�test�h�mrrr�testMappingInterface�s4z HeaderTests.testMappingInterfacecCs|�ttd�dS)Nr�)�assertRaises�	TypeErrorrr%rrr�testRequireList�szHeaderTests.testRequireListcCs�t�}|�t|�d�|jdddd�|�|dd�|�t|�d�|jdddd	�|�|�d�dd
g�|�t|�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)r r!r"r�r�r�rrrrr��s r�c@s"eZdZeej���Zdd�ZdS)�ErrorHandlerc	Ks*t|�tj|t�t�t�|ddd�dS)NT)�multithread�multiprocess)rr
rrr)rr�rrrrs
�zErrorHandler.__init__N)	r r!r"�dict�osr/r��
os_environrrrrrr�sr�c@seZdZdd�ZdS)�TestHandlercCs�dSrrr%rrr�handle_error#szTestHandler.handle_errorN)r r!r"rrrrrr� sr�c@sxeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�HandlerTestsi�cCs�dddddd�}t�td|��$tdd	d
�}|��Wd�n1sH0YdD]$}|�t|d|�|jd
|�qVi}t|�|��D]\}}||vr�|||<q�|�	dd	dd|�
�|��dddddtj
d��|�|j|�dS)Nz/my/homez/my/pathzfr_FR.UTF-8Ztest_script_nameZtest_server_name)�HOME�PATHZLANGr�r�r��Yz/override/home)�Xr)rSr�r�Zrun_onceZfile_wrapperZwsgi_zwsgi.r8r:r�Fr�T)rrr�r�rpr�r�r�r�r�r�zwsgi.file_wrapper)rZ	swap_attrr�rrU�getattrr/rr��update�	get_stdin�
get_stderrrr�ZassertDictEqual)rr�Zhandler�attrZexpectedr�r�rrr�testEnviron+sB�&�
�zHandlerTests.testEnvironcCs2tdddi�}|��dD]}|�||j�qdS)N)r�rpr�)r
r�assertInr/)rr�r�rrr�testCGIEnvironaszHandlerTests.testCGIEnvironcCsHtdd�}|��|�|jdd�t�}|��|�|jdd�dS)Nr�r�r�r�r�)r�rrUr/r�rrr�
testSchemegszHandlerTests.testSchemecCs6t�}dD]}|�tt||��q
|�t|jd�dS)N)Z_flushrr	Zadd_cgi_varsr�)r	r��NotImplementedErrorrZ_write)rr��namerrr�testAbstractMethodsmsz HandlerTests.testAbstractMethodscCs�dd�}dd�}dd�}dd�}t�}|�|�|�|j��d	�d
��t�}|�|�|�|j��d�d
��t�}|�|�|�|j��d�t�}|�|�|�|j��d
�dS)NcSs|dg�|d�d�gS�Nr(r�r4r}rsrrr�trivial_app1xs
z4HandlerTests.testContentLength.<locals>.trivial_app1cSs|dg�|d�d��gSrr}rsrrr�trivial_app2|sz4HandlerTests.testContentLength.<locals>.trivial_app2cSs|dg�d�d�gS)Nr(uтестzutf-8r}rsrrr�trivial_app3�s
z4HandlerTests.testContentLength.<locals>.trivial_app3cSs|ddg�gS)Nr()zContent-LengthZ12345rrsrrr�trivial_app4�sz4HandlerTests.testContentLength.<locals>.trivial_app4z)Status: 200 OK
Content-Length: 4

httpr4zStatus: 200 OK

https-Status: 200 OK
Content-Length: 8

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

)r��runrU�stdoutr=r6)rrrrrr�rrr�testContentLengthus8
��
��
�
�zHandlerTests.testContentLengthcCs�dd�}dd�}t�}|�|�|�|j��d�d��|�|j��d�t�}|�|�|�|j��d|jt|j	�f�d�|j	�|�
d	|j���dS)
NcSs|dg�gS�Nr(rrsrrr�
non_error_app�s
z8HandlerTests.testBasicErrorOutput.<locals>.non_error_appcSstd��dS)N� This should be caught by handler�rErsrrr�	error_app�sz4HandlerTests.testBasicErrorOutput.<locals>.error_app�%Status: 200 OK
Content-Length: 0

r4r8z<Status: %s
Content-Type: text/plain
Content-Length: %d

rE)r�rrUrr=r6r<Zerror_statusr�Z
error_bodyr)rrrr�rrr�testBasicErrorOutput�s,
��
����z!HandlerTests.testBasicErrorOutputcsRd��fdd�}t�}|�|�|�|j��d�d���|�d|j���dS)N�Some output has been sentcs|dg���td��dS)Nr(rrrs��MSGrrr�sz4HandlerTests.testErrorAfterOutput.<locals>.error_appzStatus: 200 OK

r4rE)r�rrUrr=r6rr<�rrr�rr"r�testErrorAfterOutput�s
���z!HandlerTests.testErrorAfterOutputc	
Csdd�}d}d�d�}dD]�}|r*d|p,d}d	D]�}d
D]�}t|d�}d|_||_||_|�|�|�||j���t|d�}d
|_||_||_|�|�|dkr�|�|j��d�q:|�	t
�|||f�d�|j���|||f�d�|j��f�q:q2qdS)NcSs|dg�gSrrrsrrrr�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\nrr4)z
FooBar/1.0NzServer: %s
r8)z1.0z1.1)�HTTP/0.9r�zHTTP/1.1)r�FTr&r~)r6r�Z
origin_serverZhttp_versionZserver_softwarerrUrr=rf�rerL)	rrZstdpatZshortpatZssw�swrS�protor�rrr�testHeaderFormats�s@���



���zHandlerTests.testHeaderFormatscCs.dd�}t�}|�|�|�d|j���dS)NcSs|ddg�dgS)Nr(rjrqrrsrrrr>�s�z'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�}|�|�|��dd�dS)N�close_calledFr!cs(|dg���G�fdd�dt�}|�S)Nr(cs eZdZdd�Z�fdd�ZdS)zHHandlerTests.testCloseOnError.<locals>.error_app.<locals>.CrashyIterablecssdVtd��qdS)Nsblahrrr%rrr�__iter__szQHandlerTests.testCloseOnError.<locals>.error_app.<locals>.CrashyIterable.__iter__csd�d<dS)NTr,rr%��side_effectsrrr�szNHandlerTests.testCloseOnError.<locals>.error_app.<locals>.CrashyIterable.closeN)r r!r"r-r�rr.rr�CrashyIterablesr0)�object)rtrur0�r#r/rrrsz0HandlerTests.testCloseOnError.<locals>.error_appT)r�rrUr$rr2r�testCloseOnErrors
zHandlerTests.testCloseOnErrorcs~t��G�fdd�d�}ddi}tt�|�tj|�}d}|�t|��|�t�Wd�n1sd0Y|�	d��dS)Ncs eZdZ�fdd�Zdd�ZdS)z4HandlerTests.testPartialWrite.<locals>.PartialWritercs|dd�}��|�t|�S)N�)�extendr�)r�b�partial�Zwrittenrr�write!s
z:HandlerTests.testPartialWrite.<locals>.PartialWriter.writecSsdSrrr%rrr�flush&sz:HandlerTests.testPartialWrite.<locals>.PartialWriter.flushN)r r!r"r9r:rr8rr�
PartialWriter sr;r�r�zshould 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!)
�	bytearrayrrr;r<r�r�rr0rU)rr;r/r��msgrr8r�testPartialWrites	(�zHandlerTests.testPartialWritec	s�ddi}tttfD]r�|j�d��RG�fdd�d�}t�}tt�|�||�}|�t�|�	|�
��Wd�q1sz0YqdS)Nr�r��Z	exceptioncseZdZ�fdd�ZdS)zEHandlerTests.testClientConnectionTerminations.<locals>.AbortingWritercs��dSrr�rr6r?rrr9?szKHandlerTests.testClientConnectionTerminations.<locals>.AbortingWriter.writeN�r r!r"r9rr?rr�AbortingWriter>srB)�ConnectionAbortedError�BrokenPipeError�ConnectionResetErrorrnrrrrr0r�r=)rr/rBr<r�rr?r� testClientConnectionTerminations6s�
z-HandlerTests.testClientConnectionTerminationscs�Gdd�dt��G�fdd�d�}t�}ddi}tt�|�||�}|�t�|�d|���|�|j	�|�|j
�|�|j�|�|j�dS)Nc@seZdZdS)zKHandlerTests.testDontResetInternalStateOnException.<locals>.CustomExceptionNr�rrrr�CustomExceptionIsrGcseZdZ�fdd�ZdS)zJHandlerTests.testDontResetInternalStateOnException.<locals>.AbortingWritercs��dSrrr@�rGrrr9QszPHandlerTests.testDontResetInternalStateOnException.<locals>.AbortingWriter.writeNrArrHrrrBPsrBr�r�)
�
ValueErrorrrrrr0rr=ZassertIsNotNone�resultZheadersrlr/)rrBr<r/r�rrHr�%testDontResetInternalStateOnExceptionHs
z2HandlerTests.testDontResetInternalStateOnExceptionN)r r!r"ZmaxDiffrr
rrrr r%r*r+r3r>rFrKrrrrr's62
+r�__main__)6Zunittestrr�rZtest.supportrZtest.test_httpserversrrZwsgiref.utilrZwsgiref.headersrZwsgiref.handlersr	r
rZwsgirefrZwsgiref.validater
Zwsgiref.simple_serverrrrZhttp.clientr�iorrrZsocketserverr�platformrr�r'r�r;r�rr#r0r7rCrPrQr�r�r�r�rr �mainrrrr�<module>sN
%9+7=