a c*@sddlZddlZddlZddlZddlZddlZddlmZmZm Z e de ee e dddZGdddZGd d d ZdS) N)ReceiveScopeSendzstarlette.middleware.wsgi is deprecated and will be removed in a future release. Please refer to https://github.com/abersheeran/a2wsgi as a replacement.)scopebodyreturnc Cs,|d|dddd|ddd|ddd |d d |d d t|tjdddd }|dpvd}|d|d<|d|d<|dr|dd|d<|dgD]p\}}|d}|dkrd}n$|dkrd}nd|dd }|d}||vr||d!|}|||<q|S)"zE Builds a scope and request body into a WSGI environ object. method root_pathutf8latin1pathZ query_stringasciizHTTP/ http_version)rschemehttpTF) REQUEST_METHODZ SCRIPT_NAMEZ PATH_INFO QUERY_STRINGZSERVER_PROTOCOLz wsgi.versionzwsgi.url_schemez wsgi.inputz wsgi.errorszwsgi.multithreadzwsgi.multiprocessz wsgi.run_onceserver) localhostPrZ SERVER_NAMErZ SERVER_PORTclientZ REMOTE_ADDRheaderszcontent-lengthCONTENT_LENGTHz content-type CONTENT_TYPEZHTTP_-_,) getencodedecodeioBytesIOsysstdoutupperreplace)rrenvironrnamevalueZcorrected_namer+f/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/starlette/middleware/wsgi.py build_environs<          r-c@s2eZdZejddddZeeeddddZ dS)WSGIMiddlewareN)apprcCs ||_dSN)r/)selfr/r+r+r,__init__AszWSGIMiddleware.__init__)rreceivesendrcs0|ddksJt|j|}|||IdHdS)Ntyper) WSGIResponderr/)r1rr3r4Z responderr+r+r,__call__Ds zWSGIMiddleware.__call__) __name__ __module__ __qualname__typingCallabler2rrrr7r+r+r+r,r.@sr.c@s~eZdZejeddddZeeddddZ eddd d Z de ej ej e e fejdd d d ZeejddddZdS)r6N)r/rrcCs<||_||_d|_d|_ttj\|_|_ d|_ d|_ dS)NF) r/rstatusresponse_headersanyioZcreate_memory_object_streammathinf stream_sendstream_receiveresponse_startedexc_info)r1r/rr+r+r,r2Ks zWSGIResponder.__init__)r3r4rc sd}d}|r6|IdH}||dd7}|dd}qt|j|}t4IdHx}||j||j4IdH0tj |j ||j IdHWdIdHq1IdHs0YWdIdHq1IdHs0Y|j dur |j d |j d|j ddS) NTr more_bodyFrr)rr-rr?Zcreate_task_groupZ start_soonsenderrBZ to_threadZrun_syncwsgistart_responserEwith_traceback)r1r3r4rrGmessager(Z task_groupr+r+r,r7Vs  n zWSGIResponder.__call__)r4rc sb|j4IdH:|j2z3dHW}||IdHq6WdIdHq^1IdHsT0YdSr0)rC)r1r4rMr+r+r,rIfszWSGIResponder.sender)r=r>rErcCsV||_|jsRd|_|dd\}}t|}dd|D}tj|jjd||ddS)NT rcSs0g|](\}}|d|dfqS)r)stripr lower).0r)r*r+r+r, vsz0WSGIResponder.start_response..zhttp.response.start)r5r=r) rErDsplitintr? from_threadrunrBr4)r1r=r>rEZstatus_code_stringr status_coderr+r+r,rKkszWSGIResponder.start_response)r(rKrcCsH|||D]}tj|jjd|ddq tj|jjddddS)Nzhttp.response.bodyT)r5rrGrF)r5r)r/r?rUrVrBr4)r1r(rKchunkr+r+r,rJs zWSGIResponder.wsgi)N)r8r9r:r;r<rr2rrr7rIstrListTupleAnyrKdictrJr+r+r+r,r6Js   r6)r"r@r$r;warningsr?Zstarlette.typesrrrwarnDeprecationWarningbytesr]r-r.r6r+r+r+r,s.