a oe@sbddlZddlZddlZddlmZddlmZeedrBddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZz ed7ZWneydZYn0Gddde jZGd d d eZd d Zd dZddZddZdeiZedkr^ddlTeedZedddgZedej ededZ!e!ge_"ddl#m$Z$e$dZ%e%j&dddd d!e'ee%ed"dS)#N)isapicon)SimpleExtensionZisapidllhandle)InternalReloadExceptionc@s$eZdZddZddZddZdS)ReloadWatcherThreadcCs`d|_t|_|jds$|jdr4|jdd|_ttj|jdt j |_ t j |dS)NFco)change_detected__file__filenameendswith win32fileZFindFirstChangeNotificationospathdirnamewin32conZFILE_NOTIFY_CHANGE_LAST_WRITEhandle threadingThread__init__selfr7C:\Program Files\Certbot\pkgs\isapi\samples\advanced.pyrNs zReloadWatcherThread.__init__c Cst|jtj}z t|jtj}t |jWn@tj yr}z&|j t j krRWYd}~qWYd}~n d}~00t|jtj}||krt dd|_|}qdS)Nz+Detected file change - flagging for reload.T)rstatr ST_MTIME win32eventZWaitForSingleObjectrZINFINITErZFindNextChangeNotificationerrorwinerrorZERROR_INVALID_HANDLEprintr )rZ last_timercZdetailsZ this_timerrrrunZs "zReloadWatcherThread.runcCst|jdSN)rZFindCloseChangeNotificationrrrrrstopkszReloadWatcherThread.stopN)__name__ __module__ __qualname__rr"r$rrrrrMs rc@s(eZdZdZddZddZddZdS) Extensionz Python advanced sample ExtensioncCst|_|jdSr#)rreload_watcherstartrrrrrtszExtension.__init__cCs|jjrtdt|d}|dr2|d|dddtd|d |d }|r|d }td |d |D]$}||d }td||f|d qttd|d td|d tdt f|d td|d | t j S)Nz Doing reloadZ UNICODE_URLReportUnhealthyzI'm a little sickz200 OKzContent-Type: text/html rz )fileZ QUERY_STRING&z
z<no such variable>z%s=%rz

zThis module has been importedz%d timesz) r)r r rZGetServerVariabler r+ZSendResponseHeaderssplitreload_countercloserZHSE_STATUS_SUCCESS)rZecburlqsZqueriesqvalrrrHttpExtensionProcxs*           zExtension.HttpExtensionProccCs|jdSr#)r)r$)rstatusrrrTerminateExtensionszExtension.TerminateExtensionN)r%r&r'__doc__rr5r7rrrrr(qsr(cCstSr#)r(rrrr__ExtensionFactory__sr9cCs|jr|j|_dSr#) description DescriptionparamsoptionsrrrPreInstallDirectorysr?cCs*ttdtdtdtddS)NzThe sample has been installed.z+Point your browser to /AdvancedPythonSamplez2If you modify the source file and reload the page,z+you should see the reload counter incrementr r<rrr PostInstalls rAcCs tddS)zQuery the status of somethingzEverything seems to be fine!Nr@)r>logargrrrstatus_handlersrDr6__main__)*)rArF)r(ZFlagsZAdvancedPythonSamplereplace)Namer;Z ScriptMapsZScriptMapUpdateZ PreInstall) OptionParserz --descriptionstorez3custom description to use for the virtual directory)actionhelp)Z opt_parsercustom_arg_handlers)(rrsysZisapirZ isapi.simplerhasattrZwin32traceutilrrrrrrr/ NameErrorrrr(r9r?rArDrNr%Z isapi.installZISAPIParametersr=ZScriptMapParamsZsmZVirtualDirParametersr8ZvdZ VirtualDirsZoptparserIparserZ add_optionZHandleCommandLinerrrrs\   $    $+