# 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): # 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/04/29 23:04:20 $"[7:-2] import cgi import imp from mod_python import apache import config TRACKER = imp.load_package("mod_python_roundup_tracker", config.TRACKER_HOME) 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""" # 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 :