diff roundup/cgi/apache.py @ 2552:41fbe26aa2df

mod_python interface for Roundup Issue Tracker
author Alexander Smishlajev <a1s@users.sourceforge.net>
date Tue, 06 Jul 2004 10:25:42 +0000
parents
children d45f1669599c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roundup/cgi/apache.py	Tue Jul 06 10:25:42 2004 +0000
@@ -0,0 +1,95 @@
+# mod_python interface for Roundup Issue Tracker
+#
+# This module is free software, you may redistribute it
+# and/or modify under the same terms as Python.
+#
+# This module provides Roundup Web User Interface
+# using mod_python Apache module.  Initially written
+# with python 2.3.3, mod_python 3.1.3, roundup 0.7.0.
+#
+# This module operates with only one tracker
+# and must be placed in the tracker directory.
+#
+# History (most recent first):
+# 04-jul-2004 [als] tracker lookup moved from module global to request handler;
+#                   use PythonOption TrackerHome (configured in apache)
+#                   to open the tracker
+# 06-may-2004 [als] use cgi.FieldStorage from Python library
+#                   instead of mod_python FieldStorage
+# 29-apr-2004 [als] created
+
+__version__ = "$Revision: 1.1 $"[11:-2]
+__date__ = "$Date: 2004-07-06 10:25:42 $"[7:-2]
+
+import cgi
+import os
+
+from mod_python import apache
+
+import roundup.instance
+
+class Headers(dict):
+
+    """HTTP headers wrapper"""
+
+    def __init__(self, headers):
+        """Initialize with `apache.table`"""
+        super(Headers, self).__init__(headers)
+        self.getheader = self.get
+
+class Request(object):
+
+    """`apache.Request` object wrapper providing roundup client interface"""
+
+    def __init__(self, request):
+        """Initialize with `apache.Request` object"""
+        self._req = request
+        # .headers.getheader()
+        self.headers = Headers(request.headers_in)
+        # .wfile.write()
+        self.wfile = self._req
+
+    def send_response(self, response_code):
+        """Set HTTP response code"""
+        self._req.status = response_code
+
+    def send_header(self, name, value):
+        """Set output header"""
+        # value may be an instance of roundup.cgi.exceptions.HTTPException
+        value = str(value)
+        # XXX default content_type is "text/plain",
+        #   and ain't overrided by "Content-Type" header
+        if name == "Content-Type":
+            self._req.content_type = value
+        else:
+            self._req.headers_out.add(name, value)
+
+    def end_headers(self):
+        """NOOP. There aint no such thing as 'end_headers' in mod_python"""
+        pass
+
+def handler(req):
+    """HTTP request handler"""
+    _options = req.get_options()
+    _home = _options.get("TrackerHome")
+    if not (_home and os.path.isdir(_home)):
+        apache.log_error(
+            "PythonOption TrackerHome missing or invalid for %(uri)s"
+            % {'uri': req.uri})
+        return apache.HTTP_INTERNAL_SERVER_ERROR
+    _tracker = roundup.instance.open(_home)
+    # create environment
+    # Note: cookies are read from HTTP variables, so we need all HTTP vars
+    req.add_common_vars()
+    _env = dict(req.subprocess_env)
+    # XXX classname must be the first item in PATH_INFO.  roundup.cgi does:
+    #       path = string.split(os.environ.get('PATH_INFO', '/'), '/')
+    #       os.environ['PATH_INFO'] = string.join(path[2:], '/')
+    #   we just remove the first character ('/')
+    _env["PATH_INFO"] = req.path_info[1:]
+    _form = cgi.FieldStorage(req, environ=_env)
+    _client = _tracker.Client(_tracker, Request(req), _env, _form)
+    _client.main()
+    return apache.OK
+
+# vim: set et sts=4 sw=4 :

Roundup Issue Tracker: http://roundup-tracker.org/