File: upload.py

package info (click to toggle)
clearsilver 0.10.5-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,304 kB
  • sloc: ansic: 24,586; python: 4,233; sh: 2,502; cs: 1,429; ruby: 819; java: 735; makefile: 589; perl: 120; lisp: 34; sql: 21
file content (41 lines) | stat: -rwxr-xr-x 835 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python

import sys, os, traceback, string
import neo_cgi

def log (s):
  sys.stderr.write("CGI: %s\n" % s)

def exceptionString():
  import StringIO

  ## get the traceback message  
  sfp = StringIO.StringIO()
  traceback.print_exc(file=sfp)
  exception = sfp.getvalue()
  sfp.close()

  return exception

def main (argv, environ):
  # log ("starting")
  cgi = neo_cgi.CGI("")

  try:
    fp = cgi.filehandle("file")
    print "Content-Type: text/plain\r\n\r\n"
    data = fp.read()
    print data

    f = open("/tmp/file", "w")
    f.write(data)

  except neo_cgi.CGIFinished:
    return
  except Exception, Reason:
    log ("Python Exception: %s" % (str(repr(Reason))))
    s = neo_cgi.text2html("Python Exception: %s" % exceptionString())
    cgi.error (s)

if __name__ == "__main__":
  main (sys.argv, os.environ)