#!/www/python/bin/python
import sys, os
import cgi # just for escape()
from quixote.http_request import HTTPRequest, FileUpload
print "content-type: text/html"
print
print "
Standard input
"
print ""
stdin_filename = "/tmp/cgi-input.%d" % os.getpid()
stdin_file = open(stdin_filename, "w")
for line in sys.stdin.xreadlines():
sys.stdout.write(cgi.escape(line))
stdin_file.write(line)
print "
"
stdin_file.close()
print "HTTPRequest object
"
stdin_file = open(stdin_filename)
try:
req = HTTPRequest(stdin_file, os.environ)
req.process_inputs()
except:
print "Uh-oh, HTTPRequest raised an exception:"
print ""
print_exc(file=sys.stdout)
print "
"
else:
print "Form variables
"
upload_vars = []
for (var, value) in req.form.items():
print "%s = %s
" \
% (var, cgi.escape(repr(req.form[var])))
if isinstance(value, FileUpload):
upload_vars.append(var)
if upload_vars:
print "File upload variables
"
for upload_var in upload_vars:
value = req.form[upload_var]
print "%s
" % upload_var
print "filename: %s
" % value.filename
print "headers:
"
for (hname, hvalue) in value.headers.items():
print " %s: %s
" \
% (hname, hvalue)
content = value.read()
print "content (%d bytes):
" % len(content)
print cgi.escape(repr(content))
vars = os.environ.keys() ; vars.sort()
print "Environment
"
print ""
for var in vars:
print " %s=%s" \
% (var, cgi.escape(os.environ[var]))
print "
"
print "Command line
"
i = 0
print ""
for arg in sys.argv:
print " %d | %s |
" % (i, arg)
i += 1
print "
"