a oe@sdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z ddlmZddlZddlmZmZdZd ZGd d d ejZGd d d ejjZdS)z>An ISAPI extension base class implemented using a thread-pool.N) OVERLAPPED)INFINITE) CloseHandleCreateIoCompletionPortGetQueuedCompletionStatusPostQueuedCompletionStatus)SetThreadToken)ExtensionErrorisapiconc@s$eZdZddZddZddZdS) WorkerThreadcCs,d|_||_||_tj||ddS)NFT)running io_req_port extension threadingThread__init__ setDaemon)selfrrr9C:\Program Files\Certbot\pkgs\isapi\threaded_extension.pyrs  zWorkerThread.__init__cCsjd|_|jrft|jt\}}}}|tkr2|dur2qf|jj|}|durVtd|f|||||qdS)NTzBad request '%s') rrrrISAPI_SHUTDOWNr dispatch_mapget RuntimeError)rerrCodebyteskey overlapped dispatcherrrrrun$s zWorkerThread.runcCs|j|dSN)rDispatch)rZcblockrrr call_handler4szWorkerThread.call_handlerN)__name__ __module__ __qualname__rr!r$rrrrr s r c@sPeZdZdZdZdZddZddZdd Zd d Z d d Z ddZ ddZ dS)ThreadPoolExtensionzlz:ThreadPoolExtension.TerminateExtension..) r*rrrrtimeworker_shutdown_waitsleeprr)rstatusr8Zend_timealiverrrTerminateExtension^s    z&ThreadPoolExtension.TerminateExtensionc Cs^|j}|}td|z4z||Wn||Yn0Wtddn tdd0dSr")r9ZGetImpersonationTokenrr#HandleDispatchError)rrrrrr:Z hRequestTokenrrrr,ss z&ThreadPoolExtension.DispatchConnectioncCs tddS)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 DispatchN)NotImplementedError)recbrrrr#szThreadPoolExtension.Dispatchc Cstj|_t\}}}d}zzzddl}|dddt|dtd|dt ||t ||}td| d |dd | |d f|dWnBt yYn2td ttd t|||Yn0Wd}|nd}|0dS) 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
%s%s
r-z#FAILED to render the error message!zORIGINAL extension error:)r ZHSE_STATUS_ERRORZHttpStatusCodesysexc_infocgiZSendResponseHeadersprint traceback format_tbformat_exception_onlyescapejoinr print_excprint_exceptionZDoneWithSession)rrIZexc_typZexc_valZexc_tblimitrNlistrrrrGsF       z'ThreadPoolExtension.HandleDispatchErrorN) r%r&r'__doc__r3rBrr1r;rFr,r#rGrrrrr(<s  r()rYrLrrArPZ pywintypesrZ win32eventrZ win32filerrrrZ win32securityrZ isapi.simpler.r r r+rrr r/r0r(rrrrs   "