Home | History | Annotate | Download | only in python
      1 #!/usr/bin/env python
      2 
      3 import sys, os, traceback, string
      4 import neo_cgi
      5 
      6 def log (s):
      7   sys.stderr.write("CGI: %s\n" % s)
      8 
      9 def exceptionString():
     10   import StringIO
     11 
     12   ## get the traceback message  
     13   sfp = StringIO.StringIO()
     14   traceback.print_exc(file=sfp)
     15   exception = sfp.getvalue()
     16   sfp.close()
     17 
     18   return exception
     19 
     20 def main (argv, environ):
     21   # log ("starting")
     22   cgi = neo_cgi.CGI("")
     23 
     24   try:
     25     fp = cgi.filehandle("file")
     26     print "Content-Type: text/plain\r\n\r\n"
     27     data = fp.read()
     28     print data
     29 
     30     f = open("/tmp/file", "w")
     31     f.write(data)
     32 
     33   except neo_cgi.CGIFinished:
     34     return
     35   except Exception, Reason:
     36     log ("Python Exception: %s" % (str(repr(Reason))))
     37     s = neo_cgi.text2html("Python Exception: %s" % exceptionString())
     38     cgi.error (s)
     39 
     40 if __name__ == "__main__":
     41   main (sys.argv, os.environ)
     42