#!/usr/bin/env python
from fcgi import WSGIServer
import cgi
import string, commands
def test_app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
yield '
Python Exploration\n' \
'\n' \
'Environment Variables
\n' \
''
names = environ.keys()
names.sort()
for name in names:
yield '| %s | %s |
\n' % (
name, cgi.escape(`environ[name]`))
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
keep_blank_values=1)
if form.list:
yield '| Form data |
'
for field in form.list:
yield '| %s | %s |
\n' % (
field.name, field.value)
yield '
\n'
commandString = "whoami"
commandOutput = commands.getoutput(commandString)
commandResults = cgi.escape(commandOutput)
yield '
' \
'User name: %s
' % (commandResults)
yield '\n'
WSGIServer(test_app).run()