17
17
# along with this program; if not, write to the Free Software
18
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
from paste.httpexceptions import HTTPNotFound, HTTPSeeOther
25
22
from paste.request import path_info_pop, parse_querystring
27
24
from loggerhead import util
69
65
self.__history = self._history_callable()
70
66
return self.__history
72
def parse_args(self, environ):
68
def __call__(self, environ, start_response):
73
70
kwargs = dict(parse_querystring(environ))
74
71
util.set_context(kwargs)
84
81
path = unicode('/'.join(args[1:]), 'utf-8')
89
def add_template_values(self, values):
91
85
'static_url': self._branch.static_url,
92
86
'branch': self._branch,
94
88
'url': self._branch.context_url,
96
values.update(templatefunctions)
98
def __call__(self, environ, start_response):
100
if environ.get('loggerhead.as_json') and not self.supports_json:
102
path = self.parse_args(environ)
90
vals.update(templatefunctions)
104
values = self.get_values(path, self.kwargs, headers)
106
self.log.info('Getting information for %s: %.3f secs' % (
93
vals.update(self.get_values(path, kwargs, headers))
95
self.log.info('Getting information for %s: %r secs' % (
107
96
self.__class__.__name__, time.time() - z))
108
if environ.get('loggerhead.as_json'):
109
headers['Content-Type'] = 'application/json'
110
elif 'Content-Type' not in headers:
97
if 'Content-Type' not in headers:
111
98
headers['Content-Type'] = 'text/html'
112
99
writer = start_response("200 OK", headers.items())
113
if environ.get('REQUEST_METHOD') == 'HEAD':
114
# No content for a HEAD request
100
template = load_template(self.template_path)
117
102
w = BufferingWriter(writer, 8192)
118
if environ.get('loggerhead.as_json'):
119
w.write(simplejson.dumps(values,
120
default=util.convert_to_json_ready))
122
self.add_template_values(values)
123
template = load_template(self.template_path)
124
template.expand_into(w, **values)
103
template.expand_into(w, **vals)
127
'Rendering %s: %.3f secs, %s bytes' % (
106
'Rendering %s: %r secs, %s bytes' % (
128
107
self.__class__.__name__, time.time() - z, w.bytes))