Skip to content

Commit 9462214

Browse files
author
Alexander Smishlajev
committed
mod_python interface for Roundup Issue Tracker
1 parent 3858a6c commit 9462214

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

roundup/cgi/apache.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# mod_python interface for Roundup Issue Tracker
2+
#
3+
# This module is free software, you may redistribute it
4+
# and/or modify under the same terms as Python.
5+
#
6+
# This module provides Roundup Web User Interface
7+
# using mod_python Apache module. Initially written
8+
# with python 2.3.3, mod_python 3.1.3, roundup 0.7.0.
9+
#
10+
# This module operates with only one tracker
11+
# and must be placed in the tracker directory.
12+
#
13+
# History (most recent first):
14+
# 04-jul-2004 [als] tracker lookup moved from module global to request handler;
15+
# use PythonOption TrackerHome (configured in apache)
16+
# to open the tracker
17+
# 06-may-2004 [als] use cgi.FieldStorage from Python library
18+
# instead of mod_python FieldStorage
19+
# 29-apr-2004 [als] created
20+
21+
__version__ = "$Revision: 1.1 $"[11:-2]
22+
__date__ = "$Date: 2004-07-06 10:25:42 $"[7:-2]
23+
24+
import cgi
25+
import os
26+
27+
from mod_python import apache
28+
29+
import roundup.instance
30+
31+
class Headers(dict):
32+
33+
"""HTTP headers wrapper"""
34+
35+
def __init__(self, headers):
36+
"""Initialize with `apache.table`"""
37+
super(Headers, self).__init__(headers)
38+
self.getheader = self.get
39+
40+
class Request(object):
41+
42+
"""`apache.Request` object wrapper providing roundup client interface"""
43+
44+
def __init__(self, request):
45+
"""Initialize with `apache.Request` object"""
46+
self._req = request
47+
# .headers.getheader()
48+
self.headers = Headers(request.headers_in)
49+
# .wfile.write()
50+
self.wfile = self._req
51+
52+
def send_response(self, response_code):
53+
"""Set HTTP response code"""
54+
self._req.status = response_code
55+
56+
def send_header(self, name, value):
57+
"""Set output header"""
58+
# value may be an instance of roundup.cgi.exceptions.HTTPException
59+
value = str(value)
60+
# XXX default content_type is "text/plain",
61+
# and ain't overrided by "Content-Type" header
62+
if name == "Content-Type":
63+
self._req.content_type = value
64+
else:
65+
self._req.headers_out.add(name, value)
66+
67+
def end_headers(self):
68+
"""NOOP. There aint no such thing as 'end_headers' in mod_python"""
69+
pass
70+
71+
def handler(req):
72+
"""HTTP request handler"""
73+
_options = req.get_options()
74+
_home = _options.get("TrackerHome")
75+
if not (_home and os.path.isdir(_home)):
76+
apache.log_error(
77+
"PythonOption TrackerHome missing or invalid for %(uri)s"
78+
% {'uri': req.uri})
79+
return apache.HTTP_INTERNAL_SERVER_ERROR
80+
_tracker = roundup.instance.open(_home)
81+
# create environment
82+
# Note: cookies are read from HTTP variables, so we need all HTTP vars
83+
req.add_common_vars()
84+
_env = dict(req.subprocess_env)
85+
# XXX classname must be the first item in PATH_INFO. roundup.cgi does:
86+
# path = string.split(os.environ.get('PATH_INFO', '/'), '/')
87+
# os.environ['PATH_INFO'] = string.join(path[2:], '/')
88+
# we just remove the first character ('/')
89+
_env["PATH_INFO"] = req.path_info[1:]
90+
_form = cgi.FieldStorage(req, environ=_env)
91+
_client = _tracker.Client(_tracker, Request(req), _env, _form)
92+
_client.main()
93+
return apache.OK
94+
95+
# vim: set et sts=4 sw=4 :

0 commit comments

Comments
 (0)