Python ServerPages

Jon Ribbens jon+python-list at unequivocal.co.uk
Tue Sep 26 12:41:24 EDT 2000


Jon Brisbin <mail at jbrisbin.net> wrote:
> My project differs greatly from the current PSP in that it approaches the
> problem of embeding python in HTML from a different tack than anyone else
> I've found so far...no JPython, no third-party modules or add-ons, no
> special compilation issues...just plain ol Python...parsing plain ol HTML
> with a sprinkling of plain ol Python ;-)

How 'bout this:

import re, os, sys

def execute(page):
  code = 0
  g = { "H": H }
  l = {}
  for chunk in re.split(r"(<\?|\?>)", page):
    if chunk == "<?":
      code = 1
    elif chunk == "?>":
      code = 0
    else:
      if code:
        exec chunk in g, l
      else:
        sys.stdout.write(chunk)

print "Content-Type: text/html\n"
execute(open(os.environ["PATH_TRANSLATED"]).read())

? ;-)




More information about the Python-list mailing list