HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_wsgiref.cpython-37.opt-1.pyc
B

��g�v�@s�ddlmZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
mZddlmZdd	lmZdd
lmZmZddlmZddlmZdd
lmZmZmZddlmZddlm 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�de�Z,Gd d!�d!e�Z-Gd"d#�d#e�Z.Gd$d%�d%e
�Z/Gd&d'�d'e/�Z0Gd(d)�d)e�Z1e2d*k�r�e�3�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 servercCst�|||�|��dS)N)r�__init__�server_bind)�self�server_addressZRequestHandlerClass�r�-/usr/local/lib/python3.7/test/test_wsgiref.pyrszMockServer.__init__cCs"|j\}}||_||_|��dS)N)rZserver_nameZserver_port�
setup_environ)rZhostZportrrrr s
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)rrr r!r$r%rrrrr"'sr"cCs|dddg�dgS)Nz200 OK)zContent-Typez
text/plain)�DatezMon, 05 Jun 2006 18:49:54 GMTs
Hello, world!r)�environ�start_responserrr�	hello_app1sr)cCs2|dddg�d�|d|d|dg��d�gS)	Nz200 OK)zContent-Typez
text/plain)r&zMon, 05 Jun 2006 18:49:54 GMT�;ZHTTP_X_TEST_HEADER�QUERY_STRING�	PATH_INFOz
iso-8859-1)�join�encode)r'r(rrr�
header_app9sr/sGET / HTTP/1.0

cCsbtdd|tt�}tt|��}t�}tj}t�}t_z|�||fd�Wd|t_X|�	�|�	�fS)N��P)z	127.0.0.1i�")
rrr"rr�sys�stderrrZfinish_request�getvalue)�app�data�serverZinp�outZolderr�errrrr�	run_amockDsr:cCs�|�}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_iterRs4


rGc@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
r0z
Hello, world!z
iso-8859-1)rr2�version�split�assertEqualr.)rr8�
has_length�pyverrrr�check_helloyszIntegrationTests.check_hellocCst�\}}|�|�dS)N)r:rO)rr8r9rrr�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/)r:r/rL�
splitlines)rr#r8r9rrr�test_environ�s

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

)r6rs!HTTP/1.0 414 Request-URI Too Long)r:rLrR)rr8r9rrr�test_request_length�sz$IntegrationTests.test_request_lengthcCs"ttt��\}}|j|dd�dS)NF)rM)r:rr)rO)rr8r9rrr�test_validated_hello�sz%IntegrationTests.test_validated_hellocCs@dd�}tt|��\}}|�|�d��|�|��dd�dS)NcSs|dd�dgS)Nz200 OK)zContent-Typez
text/plainz
Hello, world!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�endswithrLrR)rrWr8r9rrr�test_simple_validation_error�s
z-IntegrationTests.test_simple_validation_errorc
Cstdd�}dddg}x\|D]T\}}|j|d��:t||��\}}|�|�d��|�|��d|�WdQRXqWdS)	Ncs�fdd�}|S)Ncs|�dg�dgS)N)zContent-Typeztext/plain; charset=utf-8s
Hello, world!r)r'r()�statusrrrW�szWIntegrationTests.test_status_validation_errors.<locals>.create_bad_app.<locals>.bad_appr)r\rWr)r\r�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 code)r\s;A server error occurred.  Please contact the administrator.rX)�subTestr:rYrZrLrR)rr]Ztestsr\Zexc_messager8r9rrr�test_status_validation_errors�sz.IntegrationTests.test_status_validation_errorscCs@dd�}tt|��\}}|�|�d��|�|��dd�dS)NcSs|d��|ddg�dgS)Nz
wsgi.inputz200 OK)zContent-Typeztext/plain; charset=utf-8sdata)�read)�e�srrrrW�sz1IntegrationTests.test_wsgi_input.<locals>.bad_apps;A server error occurred.  Please contact the administrator.rXr<)r:rrYrZrLrR)rrWr8r9rrr�test_wsgi_input�sz IntegrationTests.test_wsgi_inputcCsldd�}tt|��\}}|�|�d��tj��d�d�}t��d�}|d|}|�	d|d|�dS)	NcSs|dddg�dgS)Nz200 OK)zContent-Typeztext/plain; charset=utf-8)r&zWed, 24 Dec 2008 13:29:32 GMTsdatar)rarbrrrr5�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)
r:rrYrZr2rJrKr.rrL)rr5r8r9Zver�pyrNrrr�test_bytes_validation�s
z&IntegrationTests.test_bytes_validationcCs>dd�}tt|�dd�\}}|�dtjdddd	g|���dS)
NcSs|dddg�|d�d�gS)Nz200 OK)zContent-Typez
text/plain)r&zWed, 24 Dec 2008 13:29:32 GMTr,�latin1)r.)rarbrrrr5�sz-IntegrationTests.test_cp1252_url.<locals>.appsGET /�%80 HTTP/1.0)r6sHTTP/1.0 200 OKsContent-Type: text/plains#Date: Wed, 24 Dec 2008 13:29:32 GMT�s/��)r:rrLr�ANYrR)rr5r8r9rrr�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)Nz200 OK�)r�
SOCK_MAX_SIZE)r'r(rrrr5s
z4IntegrationTests.test_interrupted_write.<locals>.appc@seZdZdS)z<IntegrationTests.test_interrupted_write.<locals>.WsgiHandlerN)rrr rrrr�WsgiHandlersror)Z
handler_classcs���dS)N)�set)Zsignum�frame)�interruptedrr�signal_handlersz?IntegrationTests.test_interrupted_write.<locals>.signal_handlerc	spt�j�}|�dd�|���@}|�d�x"��tj��jtd�d�r,Pq,Wt	|����WdQRX|�
�dS)N�GETrI�dr;)Ztimeout)rrr#Zgetresponser`�signal�SIGUSR1�wait�float�len�close)�httpZresponse)rr�main_threadrl�receivedr7rr�
run_clients


z;IntegrationTests.test_interrupted_write.<locals>.run_client)�targetru)rZ
get_attributervrrrZHOSTZ
addCleanupZserver_close�	threadingZEventrw�	get_identZThread�startZhandle_requestr-rLrn)rr5rorsZoriginalrZ
backgroundr)rrr}rlr~r7r�test_interrupted_write�s"z'IntegrationTests.test_interrupted_writeN)T)rrr rOrPrSrUrVr[r_rcrgrkr�rrrrrHws



rHc@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�}t�|�|�t�|�|�|�|d|�|�|d|�|S)N)�SCRIPT_NAMEr,r,r�)rrrLZshift_path_info)rZsn_inZpi_in�partZsn_outZpi_out�envrrr�
checkShift1s

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



zUtilityTests.checkDefaultcKst�|�|�|||�dS)N)rrrL)rr�r��kwrrr�checkCrossDefaultIs
zUtilityTests.checkCrossDefaultcKs t�|�|�t�|�|�dS)N)rrrLZapplication_uri)r�urir�rrr�checkAppURIMs
zUtilityTests.checkAppURIr;cKs"t�|�|�t�||�|�dS)N)rrrLZrequest_uri)rr�Zqueryr�rrr�checkReqURIQs
zUtilityTests.checkReqURIcCsb||fdd�}t||�|�}|�|jj�x|D]}q2W|�|jj�|��|�|jj�dS)NcSst�t|�|�S)N)r�FileWrapperr)�text�sizerrrrBWsz%UtilityTests.checkFW.<locals>.make_it)rG�assertFalseZfilelike�closedr{rY)rr�r�rCrBrDrFrrr�checkFWUs

zUtilityTests.checkFWcCs^|�ddddd�|�ddddd�|�ddddd�|�ddddd�|�dd	ddd�dS)
Nr0rIz/x�xz/az/x/yz/a/xz/yz/x/)r�)rrrr�testSimpleShiftsgs
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..z/az/yr0z//y�yz/a/b/yz//y/rIz/./yz/./y/z///./..//y/.//z/y/z///z/a/b/z/.//z/x//r�z/a/b/xz/.)r�)rrrr�testNormalizedShiftsnsz!UtilityTests.testNormalizedShiftscCsJxDddddddddd	d
ddt�fd
t�fdgD]\}}|�||�q.WdS)N)�SERVER_NAMEz	127.0.0.1)�SERVER_PORT�80)�SERVER_PROTOCOLzHTTP/1.0)�	HTTP_HOSTz	127.0.0.1)ZREQUEST_METHODrt)r�r0)r,rI)zwsgi.version)r;r)z
wsgi.run_oncer)zwsgi.multithreadr)zwsgi.multiprocessrz
wsgi.inputzwsgi.errors)zwsgi.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�zwsgi.url_scheme�https�on)�HTTPS�1�yesr|�foor�r�Z443)r�)rrrr�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�)rLrZguess_scheme)rrrr�testGuessScheme�s
zUtilityTests.testGuessSchemecCsv|�d�|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�|�d�|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�r,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�r,r+z'http://127.0.0.1/spammity/spam?s%E4y=nizs%E4y=nir)r�)rrrr�testReqURIs�s"




zUtilityTests.testReqURIscCs|�ddddg�dS)NZ�xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz�xZxxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzZxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz)r�)rrrr�testFileWrapper�szUtilityTests.testFileWrappercCs�xBd��D]6}x0||��|��|��fD]}|�t�|��q(Wq
WxBd��D]6}x0||��|��|��fD]}|�t�|��qlWqNWdS)NzbConnection Keep-Alive Proxy-Authenticate Proxy-Authorization TE Trailers Transfer-Encoding Upgradez4Accept Cache-Control Date Pragma Trailer Via Warning)rK�title�upper�lowerrYrZ
is_hop_by_hopr�)rZhopr�rrr�testHopByHop�szUtilityTests.testHopByHop)N)r;)rrr 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�dg}|�tt��d�|�ttg��d�|�tt|dd���d�|�t|dd����dg�|�t|dd����dg�|�t|dd����|�|�t|���|�t�}|d=d|d<xT|j|j|j	|j
fD]<}|�|d��|�|d��|�|d	��|�|d��q�W|�|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�rr;r�r�r��bar�FooZFOO�bazZwheeZzoo)rLrzr�keys�values�itemsZassertIsNot�__contains__�get�get_all�__getitem__rYr��
setdefault)r�test�h�mrrr�testMappingInterface�s4z HeaderTests.testMappingInterfacecCs|�ttd�dS)Nr�)�assertRaises�	TypeErrorr)rrrr�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

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

zHeaderTests.testExtrasN)rrr r�r�r�rrrrr��s r�c@s&eZdZdZeej���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)
rrr r!�dict�osr'r��
os_environrrrrrr�sr�c@seZdZdZdd�ZdS)�TestHandlerzASimple handler subclass for testing BaseHandler, w/error passthrucCs�dS)Nr)rrrr�handle_errorszTestHandler.handle_errorN)rrr r!r�rrrrr�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
�}|��WdQRXx,dD]$}|�t|d|�|jd
|�qDWi}t|�x$|��D]\}}||kr�|||<q�W|�	dd	dd|�
�|��dddddtj
d��|�|j|�dS)Nz/my/homez/my/pathzfr_FR.UTF-8Ztest_script_nameZtest_server_name)�HOME�PATH�LANGr�r�r��Yz/override/home)�Xr�)rJr�r�Zrun_onceZfile_wrapperZwsgi_zwsgi.r0z	127.0.0.1)r;rFr|T)r�r�r�r�z
wsgi.inputzwsgi.errorszwsgi.versionz
wsgi.run_oncezwsgi.url_schemezwsgi.multithreadzwsgi.multiprocesszwsgi.file_wrapper)rZ	swap_attrr�rrL�getattrr'rr��update�	get_stdin�
get_stderrrr�ZassertDictEqual)rr�Zhandler�attrZexpectedr�r�rrr�testEnviron"s<
zHandlerTests.testEnvironcCs6tdddi�}|��xdD]}|�||j�qWdS)N)zwsgi.url_schemez
wsgi.inputzwsgi.errors)r	r�assertInr')rr�r�rrr�testCGIEnvironXs
zHandlerTests.testCGIEnvironcCsHtdd�}|��|�|jdd�t�}|��|�|jdd�dS)Nr�)r�zwsgi.url_schemer�r|)r�rrLr')rr�rrr�
testScheme^s
zHandlerTests.testSchemecCs:t�}xdD]}|�tt||��qW|�t|jd�dS)N)Z_flushr�r�Zadd_cgi_varsr�)rr��NotImplementedErrorr�Z_write)rr��namerrr�testAbstractMethodsds
z 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)Nz200 OKzwsgi.url_schemez
iso-8859-1)r.)rarbrrr�trivial_app1os
z4HandlerTests.testContentLength.<locals>.trivial_app1cSs|dg�|d�d��gS)Nz200 OKzwsgi.url_schemez
iso-8859-1)r.)rarbrrr�trivial_app2ssz4HandlerTests.testContentLength.<locals>.trivial_app2cSs|dg�d�d�gS)Nz200 OKuтестzutf-8)r.)rarbrrr�trivial_app3ws
z4HandlerTests.testContentLength.<locals>.trivial_app3cSs|ddg�gS)Nz200 OK)zContent-LengthZ12345r)rarbrrr�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��runrL�stdoutr4r.)rr�r�r�r�r�rrr�testContentLengthls,



zHandlerTests.testContentLengthcCs�dd�}dd�}t�}|�|�|�|j��d�d��|�|j��d�t�}|�|�|�|j��d|jt|j	�f�d�|j	�|�
d	|j���dS)
NcSs|dg�gS)Nz200 OKr)rarbrrr�
non_error_app�s
z8HandlerTests.testBasicErrorOutput.<locals>.non_error_appcSstd��dS)Nz This should be caught by handler)r<)rarbrrr�	error_app�sz4HandlerTests.testBasicErrorOutput.<locals>.error_appz%Status: 200 OK
Content-Length: 0

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

r<)r�r�rLr�r4r.r3Zerror_statusrzZ
error_bodyr�)rr�r�r�rrr�testBasicErrorOutput�s


z!HandlerTests.testBasicErrorOutputcsRd��fdd�}t�}|�|�|�|j��d�d���|�d|j���dS)NsSome output has been sentcs|dg���td��dS)Nz200 OKz This should be caught by handler)r<)rarb)�MSGrrr��sz4HandlerTests.testErrorAfterOutput.<locals>.error_appzStatus: 200 OK

z
iso-8859-1r<)r�r�rLr�r4r.r�r3)rr�r�r)r�r�testErrorAfterOutput�s
z!HandlerTests.testErrorAfterOutputc	
Csdd�}d}d�d�}x�dD]�}|r,d|p.d}x�d	D]�}x�d
D]�}t|d�}d|_||_||_|�|�|�||j���t|d�}d
|_||_||_|�|�|dkr�|�|j��d�q@|�	t
�|||f�d�|j���|||f�d�|j��f�q@Wq6WqWdS)NcSs|dg�gS)Nz200 OKr)rarbrrrr��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)z
FooBar/1.0NzServer: %s
r0)z1.0z1.1)zHTTP/0.9zHTTP/1.0zHTTP/1.1)r�FTzHTTP/0.9ri)r.r�Z
origin_serverZhttp_versionZserver_softwarer�rLr�r4rY�rerC)	rr�ZstdpatZshortpatZssw�swrJ�protor�rrr�testHeaderFormats�s4







zHandlerTests.testHeaderFormatscCs.dd�}t�}|�|�|�d|j���dS)NcSs|ddg�dgS)Nz200 OK)zContent-Typeztext/plain; charset=utf-8sdatar)rarbrrrr5�sz'HandlerTests.testBytesData.<locals>.appsRStatus: 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 4

data)r�r�rLr�r4)rr5r�rrr�
testBytesData�s

zHandlerTests.testBytesDatacs>ddi�d���fdd�}t�}|�|�|��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)r<)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)rrr r�r{r)r�rr�CrashyIterablesr�)�object)rarbr�)r�r�rrr�sz0HandlerTests.testCloseOnError.<locals>.error_appT)r�r�rL)rr�r�r)r�r�r�testCloseOnErrors
zHandlerTests.testCloseOnErrorc	sjt��G�fdd�d�}ddi}tt�|�tj|�}d}|�t|��|�t�WdQRX|�	d��dS)Ncs eZdZ�fdd�Zdd�ZdS)z4HandlerTests.testPartialWrite.<locals>.PartialWritercs|dd�}��|�t|�S)N�)�extendrz)r�b�partial)�writtenrr�writes
z:HandlerTests.testPartialWrite.<locals>.PartialWriter.writecSsdS)Nr)rrrr�flushsz:HandlerTests.testPartialWrite.<locals>.PartialWriter.flushN)rrr r�rr)r�rr�
PartialWritersrr�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
rr2r3ZassertWarnsRegex�DeprecationWarningr�r)rL)rrr'r��msgr)r�r�testPartialWrites	zHandlerTests.testPartialWritec
szddi}xltttfD]^�|j�d��HG�fdd�d�}t�}tt�|�||�}|�t�|�	|�
��WdQRXqWdS)Nr�zHTTP/1.0)�	exceptioncseZdZ�fdd�ZdS)zEHandlerTests.testClientConnectionTerminations.<locals>.AbortingWritercs��dS)Nr)rr�)rrrr�6szKHandlerTests.testClientConnectionTerminations.<locals>.AbortingWriter.writeN)rrr r�r)rrr�AbortingWriter5sr)�ConnectionAbortedError�BrokenPipeError�ConnectionResetErrorr^rr
rr�r)r�r4)rr'rr3r�r)rr� testClientConnectionTerminations-s

z-HandlerTests.testClientConnectionTerminationscs�Gdd�dt��G�fdd�d�}t�}ddi}tt�|�||�}|�t�|�d|���|�|j	�|�|j
�|�|j�|�|j�dS)Nc@seZdZdS)zKHandlerTests.testDontResetInternalStateOnException.<locals>.CustomExceptionN)rrr rrrr�CustomException@srcseZdZ�fdd�ZdS)zJHandlerTests.testDontResetInternalStateOnException.<locals>.AbortingWritercs��dS)Nr)rr�)rrrr�HszPHandlerTests.testDontResetInternalStateOnException.<locals>.AbortingWriter.writeN)rrr r�r)rrrrGsrr�zHTTP/1.0)
�
ValueErrorrr
rr�r)r�r4ZassertIsNotNone�resultZheadersr\r')rrr3r'r�r)rr�%testDontResetInternalStateOnException?s
z2HandlerTests.testDontResetInternalStateOnExceptionN)rrr ZmaxDiffr�r�r�r�r�r�r�r�r�r�rrrrrrrr�s62
+r��__main__)4Zunittestrr�rZtest.test_httpserversrrZwsgiref.utilrZwsgiref.headersrZwsgiref.handlersrr	r
ZwsgirefrZwsgiref.validaterZwsgiref.simple_serverr
rrZhttp.clientr�iorrrZsocketserverr�platformrr�r�rvr2r�rr"r)r/r:rGrHr�r�r�r�r�r�mainrrrr�<module>sL
%9#7=