hg.py
41 lines
| 1.6 KiB
| text/x-python
|
PythonLexer
Marcin Kuzminski
|
r0 | #!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||||
import logging | ||||
r43 | from pylons_app.lib.base import BaseController | |||
Marcin Kuzminski
|
r41 | from pylons import tmpl_context as c, app_globals as g, session, request, config | ||
Marcin Kuzminski
|
r22 | from pylons_app.lib import helpers as h | ||
Marcin Kuzminski
|
r0 | from mako.template import Template | ||
r37 | from pylons.controllers.util import abort | |||
Marcin Kuzminski
|
r41 | |||
Marcin Kuzminski
|
r10 | log = logging.getLogger(__name__) | ||
Marcin Kuzminski
|
r0 | |||
class HgController(BaseController): | ||||
Marcin Kuzminski
|
r21 | |||
def __before__(self): | ||||
Marcin Kuzminski
|
r41 | c.repos_prefix = config['repos_name'] | ||
Marcin Kuzminski
|
r21 | |||
Marcin Kuzminski
|
r8 | def view(self, *args, **kwargs): | ||
Marcin Kuzminski
|
r21 | response = g.hgapp(request.environ, self.start_response) | ||
r37 | ||||
http_accept = request.environ.get('HTTP_ACCEPT', False) | ||||
if not http_accept: | ||||
return abort(status_code=400, detail='no http accept in header') | ||||
Marcin Kuzminski
|
r31 | #for mercurial protocols and raw files we can't wrap into mako | ||
r37 | if http_accept.find("mercurial") != -1 or \ | |||
Marcin Kuzminski
|
r31 | request.environ['PATH_INFO'].find('raw-file') != -1: | ||
Marcin Kuzminski
|
r21 | return response | ||
Marcin Kuzminski
|
r32 | try: | ||
tmpl = u''.join(response) | ||||
template = Template(tmpl, lookup=request.environ['pylons.pylons']\ | ||||
Marcin Kuzminski
|
r41 | .config['pylons.app_globals'].mako_lookup) | ||
Marcin Kuzminski
|
r32 | |||
except (RuntimeError, UnicodeDecodeError): | ||||
log.info('disabling unicode due to encoding error') | ||||
response = g.hgapp(request.environ, self.start_response) | ||||
tmpl = ''.join(response) | ||||
template = Template(tmpl, lookup=request.environ['pylons.pylons']\ | ||||
Marcin Kuzminski
|
r41 | .config['pylons.app_globals'].mako_lookup, disable_unicode=True) | ||
Marcin Kuzminski
|
r31 | |||
Marcin Kuzminski
|
r21 | |||
Marcin Kuzminski
|
r31 | return template.render(g=g, c=c, session=session, h=h) | ||