Add Neil's run_cgi script (quixote/demo/run_cgi.py)
Andrew Kuchling <akuchlin-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Tue, 07 Jan 2003 10:44:37 -0500
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /home/cvs/quixote/demo
In directory hewson:/tmp/cvs-serv18409/demo
Added Files:
run_cgi.py
Log Message:
Add Neil's run_cgi script
--- NEW FILE: run_cgi.py ---
# This is a simple script that makes it easy to write one file CGI
# applications that use Quixote. To use, add the following line to the top
# of your CGI script:
#
# #!/usr/local/bin/python <some_path>/run_cgi.py
#
# Your CGI script becomes the root namespace and you may use PTL syntax
# inside the script. Errors will go to stderr and should end up in the server
# error log.
#
# Note that this will be quite slow since the script will be recompiled on
# every hit. If you are using Apache with mod_fastcgi installed you should be
# able to use .fcgi as an extension instead of .cgi and get much better
# performance. Maybe someday I will write code that caches the compiled
# script on the filesystem. :-)
import sys
import new
from quixote import enable_ptl, ptl_compile, Publisher
enable_ptl()
filename = sys.argv[1]
root_code = ptl_compile.compile_template(open(filename), filename)
root = new.module("root")
root.__file__ = filename
root.__name__ = "root"
exec root_code in root.__dict__
p = Publisher(root)
p.publish_cgi()