home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-python-addon-1.4.9-installer.exe / cgihandler.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2004-10-01  |  2.5 KB  |  78 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.3)
  3.  
  4. import apache
  5. import imp
  6. import os
  7. import sys
  8.  
  9. try:
  10.     import threading
  11.     _lock = threading.Lock()
  12. except (ImportError, AttributeError):
  13.     
  14.     class DummyLock:
  15.         
  16.         def acquire(self):
  17.             pass
  18.  
  19.         
  20.         def release(self):
  21.             pass
  22.  
  23.  
  24.     _lock = DummyLock()
  25.  
  26. os.environ = { }
  27. original = sys.modules.keys()
  28. (stdlib, x) = os.path.split(os.__file__)
  29.  
  30. def handler(req):
  31.     for m in sys.modules.keys():
  32.         if m not in original:
  33.             mod = sys.modules[m]
  34.             if hasattr(mod, '__file__'):
  35.                 (path, x) = os.path.split(mod.__file__)
  36.                 if path != stdlib:
  37.                     del sys.modules[m]
  38.                 
  39.             
  40.         hasattr(mod, '__file__')
  41.     
  42.     if req.subprocess_env.has_key('script_filename'):
  43.         (dir, file) = os.path.split(req.subprocess_env['script_filename'])
  44.     else:
  45.         (dir, file) = os.path.split(req.filename)
  46.     (module_name, ext) = os.path.splitext(file)
  47.     _lock.acquire()
  48.     
  49.     try:
  50.         
  51.         try:
  52.             cwd = os.getcwd()
  53.             os.chdir(dir)
  54.             (env, si, so) = apache.setup_cgi(req)
  55.             
  56.             try:
  57.                 (fd, path, desc) = imp.find_module(module_name, [
  58.                     dir])
  59.             except ImportError:
  60.                 raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
  61.  
  62.             imp.load_module(module_name, fd, path, desc)
  63.             return apache.OK
  64.         finally:
  65.             apache.restore_nocgi(env, si, so)
  66.             
  67.             try:
  68.                 fd.close()
  69.             except:
  70.                 pass
  71.  
  72.             os.chdir(cwd)
  73.  
  74.     finally:
  75.         _lock.release()
  76.  
  77.  
  78.