#!/usr/bin/python """Processes embedded python code embedded in html. Copyright (C) by Sami Kyöstilä , 2002. Released under the GNU GPL. Here's a sample html file: The square of 5 is . Note that the opening and closing tags () must be in separate lines. Installation for Apache: Add the following to your httpd.conf and copy this script into your cgi-bin directory: AddHandler python-parsed-html .pyhtml Action python-parsed-html /cgi-bin/pyhtml.py Also, make sure you have the actions modules (mod_actions) loaded or the above won't work. """ import sys import os print "Content-type: text/html" print try: f = open(os.environ["PATH_TRANSLATED"]) lines = f.readlines() f.close() except: lines = sys.stdin.readlines() raise code=0 for l in lines: ls=l.strip().replace("\n","").replace("\r","") if not code: if ls=="": code=0 try: exec c except Exception, e: try: import cgi except: pass try: import traceback except: pass print "
"
				for l in traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback):
					l=cgi.escape(l).replace("\n","
") print l print "
" else: c+=l