-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcommon.py
50 lines (41 loc) · 1.62 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
##
# pitweb - Web interface for git repository written in python
# ------------------------------------------------------------
# Copyright (c)2010 Daniel Fiser <[email protected]>
#
#
# This file is part of pitweb.
#
# pitweb is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of
# the License, or (at your option) any later version.
#
# pitweb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
from mod_python import apache, util
class ModPythonOutput(object):
""" Class able to produce output using mod_python's request object """
def __init__(self, req):
self._req = req
def _esc(self, s):
""" Replaces special characters by HTML escape sequences """
s = s.replace('<', '<')
s = s.replace('>', '>')
s = s.replace('\n', '<br />')
return s
def write(self, s):
self._req.write(s)
def setContentType(self, type):
self._req.content_type = type
def setFilename(self, filename):
self._req.headers_out['Content-disposition'] = ' attachment; filename="{0}"'.format(filename)
def run(self):
self.write("This method should be overloaded")
return apache.OK