File: kid_handler.cgi

package info (click to toggle)
kid 0.9.6-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 2,264 kB
  • ctags: 4,633
  • sloc: python: 7,417; makefile: 120; sh: 47; xml: 4
file content (32 lines) | stat: -rwxr-xr-x 755 bytes parent folder | download | duplicates (4)
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)