def application(environ, start_response):
import cgi
import html
import platform
write_fn = start_response('200 OK', [('Content-Type', 'text/html')])
yield '
os.environment\n' \
'\n' \
'os.environment
\n' \
''
names = environ.keys()
sorted(names)
for name in names:
yield '%s | %s |
\n' % (
name, escape(str(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)
write_fn('This has been write()n :-) | Python ' +
platform.sys.version + ' |
\n')
yield '
\n' \
'\n'
def escape(s, quote=None):
'''Replace special characters "&", "<" and ">" to HTML-safe sequences.
If the optional flag quote is true, the quotation mark character (")
is also translated. (Python 2 and 3 neutral.)'''
s = s.replace("&", "&") # Must be done first!
s = s.replace("<", "<")
s = s.replace(">", ">")
if quote:
s = s.replace('"', """)
return s
import wasd
wasd.wsgi_run(application)