import sys
import os
def print_environ(environ=os.environ):
"""Dump the shell environment as HTML."""
keys = environ.keys()
keys.sort()
print
i = 0
for key in keys:
if i == 0:
print "
", escape(key), " | ", escape(environ[key]), " |
"
i = 1
else:
print "", escape(key), " | ", escape(environ[key]), " | "
i = 0
print
def escape(s, quote=None):
"""Replace special characters '&', '<' and '>' by SGML entities."""
s = s.replace("&", "&") # Must be done first!
s = s.replace("<", "<")
s = s.replace(">", ">")
if quote:
s = s.replace('"', """)
return s
print "Content-type: text/html\n\n"
print """
Name | Value |
"""
print_environ()
print """
"""