SVN: r23960 - trunk/quixote

Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Mon, 12 Apr 2004 10:16:15 -0400
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: nascheme
Date: 2004-04-12 10:16:15 -0400 (Mon, 12 Apr 2004)
New Revision: 23960

Modified:
   trunk/quixote/ACKS
   trunk/quixote/mod_python_handler.py
Log:
Implement error logging for mod_python handler.


Modified: trunk/quixote/ACKS
===================================================================
--- trunk/quixote/ACKS	2004-04-12 13:43:44 UTC (rev 23959)
+++ trunk/quixote/ACKS	2004-04-12 14:16:15 UTC (rev 23960)
@@ -25,6 +25,7 @@
 David Goodger
 Neal M. Holtz
 Kaweh Kazemi
+Shahms E. King
 A.M. Kuchling    <akuchlin-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]>
 Erno Kuusela
 Nicola Larosa

Modified: trunk/quixote/mod_python_handler.py
===================================================================
--- trunk/quixote/mod_python_handler.py	2004-04-12 13:43:44 UTC (rev 23959)
+++ trunk/quixote/mod_python_handler.py	2004-04-12 14:16:15 UTC (rev 23960)
@@ -6,26 +6,53 @@
 section of doc/web-server.txt for details.
 """
 
-__revision__ = "$Id$"
-
-# adapted from Erno Kuusela's quixote_handler.py, 2001/09/19 GPW
-
 import sys
 from mod_python import apache
 from quixote import Publisher, enable_ptl
+from quixote.config import Config
 
+class ErrorLog:
+    def __init__(self, publisher):
+        self.publisher = publisher
+
+    def write(self, msg):
+        self.publisher.log(msg)
+
+    def close(self):
+        pass
+
 class ModPythonPublisher(Publisher):
+    def __init__(self, package, config=None):
+        Publisher.__init__(self, package, config)
+        self.error_log = self.__error_log = ErrorLog(self) # may be overwritten
+        self.setup_logs()
+        self.__apache_request = None
+
+    def log(self, msg):
+        if self.error_log is self.__error_log:
+            if self.__apache_request:
+                self.__apache_request.log_error(msg)
+            else:
+                apache.log_error(msg)
+        else:
+            Publisher.log(self, msg)
+
     def publish_modpython(self, req):
         """publish_modpython() -> None
 
         Entry point from mod_python.
         """
-        self.publish(apache.CGIStdin(req),
-                     apache.CGIStdout(req),
-                     sys.stderr,
-                     apache.build_cgi_env(req))
-        return apache.OK
+        self.__apache_request = req
+        try:
+            self.publish(apache.CGIStdin(req),
+                         apache.CGIStdout(req),
+                         sys.stderr,
+                         apache.build_cgi_env(req))
 
+            return apache.OK
+        finally:
+            self.__apache_request = None
+
 enable_ptl()
 
 name2publisher = {}
@@ -37,12 +64,18 @@
     except KeyError:
         package = None
 
+    try:
+        configfile = opts['quixote-config-file']
+        config = Config()
+        config.read_file(self, configfile)
+    except KeyError:
+        config = None
+
     if not package:
         return apache.HTTP_INTERNAL_SERVER_ERROR
-    else:
-        pub = name2publisher.get(package)
-        if pub is None:
-            pub = ModPythonPublisher(package)
-            pub.setup_logs()
-            name2publisher[package] = pub
-        return pub.publish_modpython(req)
+
+    pub = name2publisher.get(package)
+    if pub is None:
+        pub = ModPythonPublisher(package, config)
+        name2publisher[package] = pub
+    return pub.publish_modpython(req)