home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from isapi import isapicon
- from isapi.simple import SimpleExtension
- import sys
- import os
- import stat
- if hasattr(sys, 'isapidllhandle'):
- import win32traceutil
-
- from isapi import InternalReloadException
- import win32event
- import win32file
- import winerror
- import win32con
- import threading
-
- class ReloadWatcherThread(threading.Thread):
-
- def __init__(self):
- self.change_detected = False
- self.filename = __file__
- if self.filename.endswith('c') or self.filename.endswith('o'):
- self.filename = self.filename[:-1]
-
- self.handle = win32file.FindFirstChangeNotification(os.path.dirname(self.filename), False, win32con.FILE_NOTIFY_CHANGE_LAST_WRITE)
- threading.Thread.__init__(self)
-
-
- def run(self):
- last_time = os.stat(self.filename)[stat.ST_MTIME]
- while None:
-
- try:
- rc = win32event.WaitForSingleObject(self.handle, win32event.INFINITE)
- win32file.FindNextChangeNotification(self.handle)
- except win32event.error:
- details = None
- if details[0] != winerror.ERROR_INVALID_HANDLE:
- raise
- details[0] != winerror.ERROR_INVALID_HANDLE
- break
-
- this_time = os.stat(self.filename)[stat.ST_MTIME]
- if this_time != last_time:
- print 'Detected file change - flagging for reload.'
- self.change_detected = True
- last_time = this_time
- continue
- continue
- return None
-
-
- def stop(self):
- win32file.FindCloseChangeNotification(self.handle)
-
-
-
- def TransmitFileCallback(ecb, hFile, cbIO, errCode):
- print 'Transmit complete!'
- ecb.close()
-
-
- class Extension(SimpleExtension):
-
- def __init__(self):
- self.reload_watcher = ReloadWatcherThread()
- self.reload_watcher.start()
-
-
- def HttpExtensionProc(self, ecb):
- if self.reload_watcher.change_detected:
- print 'Doing reload'
- raise InternalReloadException
- self.reload_watcher.change_detected
- if ecb.GetServerVariable('URL').endswith('test.py'):
- file_flags = win32con.FILE_FLAG_SEQUENTIAL_SCAN | win32con.FILE_FLAG_OVERLAPPED
- hfile = win32file.CreateFile(__file__, win32con.GENERIC_READ, 0, None, win32con.OPEN_EXISTING, file_flags, None)
- flags = isapicon.HSE_IO_ASYNC | isapicon.HSE_IO_DISCONNECT_AFTER_SEND | isapicon.HSE_IO_SEND_HEADERS
-
- try:
- ecb.TransmitFile(TransmitFileCallback, hfile, int(hfile), '200 OK', 0, 0, None, None, flags)
- hfile.Close()
- raise
-
- else:
- ecb.SendResponseHeaders('200 OK', 'Content-Type: text/html\r\n\r\n', 0)
- print >>ecb, '<HTML><BODY>'
- print >>ecb, 'The root of this site is at', ecb.MapURLToPath('/')
- print >>ecb, '</BODY></HTML>'
- ecb.close()
- return isapicon.HSE_STATUS_SUCCESS
-
-
- def TerminateExtension(self, status):
- self.reload_watcher.stop()
-
-
-
- def __ExtensionFactory__():
- return Extension()
-
-
- def PreInstallDirectory(params, options):
- if options.description:
- params.Description = options.description
-
-
-
- def PostInstall(params, options):
- print
- print 'The sample has been installed.'
- print 'Point your browser to /PyISAPITest'
-
-
- def status_handler(options, log, arg):
- print 'Everything seems to be fine!'
-
- custom_arg_handlers = {
- 'status': status_handler }
- if __name__ == '__main__':
- from isapi.install import *
- params = ISAPIParameters(PostInstall = PostInstall)
- sm = [
- ScriptMapParams(Extension = '*', Flags = 0)]
- vd = VirtualDirParameters(Name = 'PyISAPITest', Description = Extension.__doc__, ScriptMaps = sm, ScriptMapUpdate = 'replace', PreInstall = PreInstallDirectory)
- params.VirtualDirs = [
- vd]
- from optparse import OptionParser
- parser = OptionParser('')
- parser.add_option('', '--description', action = 'store', help = 'custom description to use for the virtual directory')
- HandleCommandLine(params, opt_parser = parser, custom_arg_handlers = custom_arg_handlers)
-
-