idZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z ddlmZddlZddlmZmZdZd ZGd d ejZGd d ejjZdS)z>An ISAPI extension base class implemented using a thread-pool.N) OVERLAPPED)INFINITE) CloseHandleCreateIoCompletionPortGetQueuedCompletionStatusPostQueuedCompletionStatus)SetThreadToken)ExtensionErrorisapiconc eZdZdZdZdZdS) WorkerThreadcrd|_||_||_tj|ddS)NFT)daemon)running io_req_port extension threadingThread__init__)selfrrs FC:\PYTHON\_runtimes\venv\Lib\site-packages\isapi/threaded_extension.pyrzWorkerThread.__init__sJ &"!!  "     cd|_|jryt|jt\}}}}|tkr|dS|jj|}|td|d||||||jwdSdS)NTz Bad request '') rrrrISAPI_SHUTDOWNr dispatch_mapget RuntimeError)rerrCodebyteskey overlapped dispatchers rrunzWorkerThread.run's l 8.G (// +GUCn$$);488==J!"#93#9#9#9::: JwsJ 7 7 7l 8 8 8 8 8rc:|j|dSN)rDispatch)rcblocks r call_handlerzWorkerThread.call_handler7s '''''rN)__name__ __module__ __qualname__rr&r+rrrrsA    888 (((((rrcDeZdZdZdZdZdZdZdZdZ dZ d Z d Z d S) ThreadPoolExtensionzz:ThreadPoolExtension.TerminateExtension..ps%66616Q666r) r4rrrrtimeworker_shutdown_waitsleeprr)rstatusrCend_timealives rTerminateExtensionz&ThreadPoolExtension.TerminateExtensionbsl # #F"FNNl R RF &t'7ND Q Q Q Q9;;!:T!AA  7y{{X%% JsOOO66666E  7 D$%%%%%rc|j}|}td| ||n#||YnxYwtdddS#tddwxYwr()rEGetImpersonationTokenr r)HandleDispatchError)rr!r"r#r$rG hRequestTokens rr6z&ThreadPoolExtension.DispatchConnectionws") %;;== t]+++ ' 8 m,,,, 8((77777 4 & & & & &N4 & & & &sAA2AA22Bc td)aOverridden by the sub-class to handle connection requests. This class creates a thread-pool using a Windows completion port, and dispatches requests via this port. Sub-classes can generally implement each connection request using blocking reads and writes, and the thread-pool will still provide decent response to the end user. The sub-class can set a max_workers attribute (default is 20). Note that this generally does *not* mean 20 threads will all be concurrently running, via the magic of Windows completion ports. There is no default implementation - sub-classes must implement this. z$sub-classes should override Dispatch)NotImplementedError)recbs rr)zThreadPoolExtension.Dispatchs""HIIIrc &tj|_tj\}}}d} ddl}|dddt|td|tj ||tj ||z}| }td | d || ||nY#t$rYnMtd tjtd tj|||YnxYwd}|dS#d}|wxYw) zHandles errors in the Dispatch method. When a Dispatch method call fails, this method is called to handle the exception. The default implementation formats the traceback in the browser. Nrz200 OKzContent-type: text/html F)filez+

Traceback (most recent call last):

z
{}{}
z#FAILED to render the error message!zORIGINAL extension error:)r HSE_STATUS_ERRORHttpStatusCodesysexc_infohtmlSendResponseHeadersprint traceback format_tbformat_exception_onlypopformatescapejoinr print_excprint_exceptionDoneWithSession) rr\exc_typexc_valexc_tblimitrdlistbolds rrXz'ThreadPoolExtension.HandleDispatchErrors&6#&<>> &! " D ''?3C#NNNN *E3GWEEFxxzz,33 BGGDMM22 D)) "    D;<<<#%%%1222)'7FCCCCCF    ! ! ! ! !F    ! ! ! !s+CDE8 EE8AEE88FN) r,r-r.__doc__r>rPrr<rHrUr6r)rXr/rrr1r1?sBBK     ( ( (+++ &&&* ' ' 'JJJ ,",",",","rr1)rwrbrrOrg pywintypesr win32eventr win32filerrrr win32securityr isapi.simpler9r r r5rrrr:r;r1r/rrr}sJDD  !!!!!! )(((((******** (((((9#(((HB"B"B"B"B"%,6B"B"B"B"B"r