1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#!/usr/bin/env python
"""A very very early attempt at a CGI based handler for Kid templates."""
import sys
# make sure the kid modules are available
# sys.path.append(os.path.dirname(__file__))
import os
import cgi
import cgitb; cgitb.enable()
import kid
f = os.environ['PATH_TRANSLATED']
template = kid.Template(file=f)
def default_cgi_main():
dic = template.__dict__
media_type = dic.get('media_type', 'text/html')
charset = dic.get('encoding', 'utf-8')
print 'Content-Type: %s;charset=%s' % (media_type, charset)
print ''
try:
cgi_main = module.cgi_main
except AttributeError:
cgi_main = default_cgi_main
cgi_main()
form = cgi.FieldStorage()
for part in template.generate(output=sys.stdout, context=form):
sys.stdout.write(part)
|