home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / xbmc-9.11.exe / system / python / spyce / spyceCGI.py < prev    next >
Encoding:
Python Source  |  2009-12-23  |  1.3 KB  |  49 lines

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