home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 May / maximum-cd-2009-05.iso / DiscContents / XBMC_for_Windows-8.10.exe / system / python / spyce / spyceCGI.py < prev    next >
Encoding:
Python Source  |  2008-11-03  |  1.2 KB  |  47 lines

  1. ##################################################
  2. # SPYCE - Python-based HTML Scripting
  3. # Copyright (c) 2002 Rimon Barr.
  4. #
  5. # Refer to spyce.py
  6. # CVS: $Id: spyceCGI.py 5659 2006-04-27 16:15:15Z jwnmulder $
  7. ##################################################
  8.  
  9. import os, sys
  10. import spyceCmd, spyce
  11. import fcgi
  12.  
  13. __doc__ = '''(F)CGI-based Spyce entry point.'''
  14.  
  15. def findScriptFile(path):
  16.   origpath = path
  17.   while path and not path=='/':
  18.     if os.path.isfile(path):
  19.       return path
  20.     path = os.path.dirname(path)
  21.   return origpath
  22.  
  23. def doSpyce( (stdin, stdout, stderr, environ) ):
  24.   path = None
  25.   if len(sys.argv)<=1 or not os.path.isfile(sys.argv[1]):
  26.     try: path = findScriptFile(environ['PATH_TRANSLATED'])
  27.     except: pass
  28.   result = spyceCmd.spyceMain(cgimode=1, cgiscript=path,
  29.     stdout=stdout, stdin=stdin, stderr=stderr, environ=environ)
  30.   return result
  31.  
  32. def main():
  33.   cgi = fcgi.FCGI()
  34.   more = cgi.accept()
  35.   if cgi.socket: os.environ[spyce.SPYCE_ENTRY] = 'fcgi'
  36.   else: os.environ[spyce.SPYCE_ENTRY] = 'cgi'
  37.   while more:
  38.     doSpyce(more)
  39.     more = cgi.accept()
  40.  
  41. if __name__=='__main__':
  42.   if sys.platform == "win32":
  43.     import os, msvcrt
  44.     msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
  45.   main()
  46.  
  47.