SVN: r25881 - trunk/quixote
David Binger <dbinger-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Tue, 18 Jan 2005 14:15:23 -0500
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: dbinger
Date: 2005-01-18 13:10:25 -0500 (Tue, 18 Jan 2005)
New Revision: 25881
Modified:
trunk/quixote/mod_python_handler.py
Log:
Update mod_python_handler.py using a diff posted to quixote-users.
This needs testing.
Modified: trunk/quixote/mod_python_handler.py
===================================================================
--- trunk/quixote/mod_python_handler.py 2005-01-18 17:44:57 UTC (rev 25880)
+++ trunk/quixote/mod_python_handler.py 2005-01-18 18:10:25 UTC (rev 25881)
@@ -1,9 +1,8 @@
-"""quixote.mod_python_handler
-$HeadURL$
+"""
+$URL$
$Id$
-mod_python handler for Quixote *1*.
-This still needs to be converted for Quixote 2.
+This needs testing.
mod_python configuration
------------------------
@@ -16,7 +15,7 @@
<LocationMatch "^/qdemo(/|$)">
SetHandler python-program
PythonHandler quixote.mod_python_handler
- PythonOption quixote-root-namespace quixote.demo
+ PythonOption quixote-publisher-factory quixote.demo.create_publisher
PythonInterpreter quixote.demo
PythonDebug On
</LocationMatch>
@@ -26,8 +25,8 @@
the pattern in the ``LocationMatch`` directive), and no need for a
driver script.
-mod_python support was contributed to Quixote by Erno Kuusela
-<[email protected]>.
+mod_python support was contributed to Quixote (1) by Erno Kuusela
+<[email protected]> and the Quixote 2 port comes from Clint.
"""
import sys
@@ -35,6 +34,7 @@
from quixote import enable_ptl
from quixote.publish import Publisher
from quixote.config import Config
+from quixote.util import import_object
class ErrorLog:
def __init__(self, publisher):
@@ -78,29 +78,29 @@
finally:
self.__apache_request = None
-enable_ptl()
-
name2publisher = {}
+def run(publisher, req):
+ from quixote.http_request import HTTPRequest
+ request = HTTPRequest(apache.CGIStdin(req), apache.build_cgi_env(req))
+ response = publisher.process_request(request)
+ try:
+ response.write(apache.CGIStdout(req))
+ except IOError, err:
+ publisher.log("IOError while sending response ignored: %s" % err)
+ return apache.OK
+
def handler(req):
opts = req.get_options()
try:
- package = opts['quixote-root-namespace']
+ factory = opts['quixote-publisher-factory']
except KeyError:
- package = None
-
- try:
- configfile = opts['quixote-config-file']
- config = Config()
- config.read_file(configfile)
- except KeyError:
- config = None
-
- if not package:
+ apache.log_error('quixote-publisher-factory setting required')
return apache.HTTP_INTERNAL_SERVER_ERROR
+ pub = name2publisher.get(factory)
+ if pub is None:
+ factory_fcn = import_object(factory)
+ pub = factory_fcn()
+ name2publisher[factory] = pub
+ return run(pub, req)
- pub = name2publisher.get(package)
- if pub is None:
- pub = ModPythonPublisher(package, config=config)
- name2publisher[package] = pub
- return pub.publish_modpython(req)