#!/usr/bin/env python import cgi import cgitb; cgitb.enable() import os, sys def ctype(): print """Content-Type: text/html """ def head(): print """ Upload test. """ def tail(): print """ """ form = cgi.FieldStorage() def print_env(k, v, hilite=False): if hilite: print '
%s = %s
' % (k, v) else: print '
%s = %s
' % (k, v) def print_file(k, v): print '
%s (%s) (File: %s):
%s
' % (k, v.filename, v.type, v.value) def print_fs(k, v): print '
%s (FieldStorage: %s) = %s
' % (k, v.type, v.value) def print_unk(k, v): print '
%s (Unknown: %s) = %s
' % (k, v.type, v.value) def print_mfs(k, v): print '
%s (MiniFieldStorage: %s) = %s
' % (k, v.type, v.value) def env(): print '

Environment

' for k, v in os.environ.items(): print_env(k, v, hilite = (k == 'REQUEST_METHOD') or (k == 'CONTENT_TYPE')) def act(): print '

Form Fields

' for k in form: v = form[k] if v.file and v.filename: print_file(k, v) elif isinstance(v, cgi.FieldStorage): print_fs(k, v) elif isinstance(v, cgi.MiniFieldStorage): print_mfs(k, v) else: print_unk(k, v) if (__name__ == "__main__"): ctype() if not 'inline' in form or form['inline'].value != 'yes': head() act() #env() if not 'inline' in form or form['inline'].value != 'yes': tail()