Mercurial > public > src > rhodecode
annotate pylons_app/controllers/hg.py @ 43:2e1247e62c5b
changed for pylons 0.1 / 1.0
added admin controller
author | marcink |
---|---|
date | Wed, 07 Apr 2010 15:28:50 +0200 |
parents | 71ffa932799d |
children | e00dccb6f211 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 import logging | |
43 | 4 from pylons_app.lib.base import BaseController |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
5 from pylons import tmpl_context as c, app_globals as g, session, request, config |
22 | 6 from pylons_app.lib import helpers as h |
0 | 7 from mako.template import Template |
37
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
8 from pylons.controllers.util import abort |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
9 |
10
525ed90e4577
major app speedup moved the wsgi creation to app globals, in order to make it run only once.
Marcin Kuzminski
parents:
8
diff
changeset
|
10 log = logging.getLogger(__name__) |
0 | 11 |
12 class HgController(BaseController): | |
21 | 13 |
14 def __before__(self): | |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
15 c.repos_prefix = config['repos_name'] |
21 | 16 |
8 | 17 def view(self, *args, **kwargs): |
21 | 18 response = g.hgapp(request.environ, self.start_response) |
37
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
19 |
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
20 http_accept = request.environ.get('HTTP_ACCEPT', False) |
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
21 if not http_accept: |
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
22 return abort(status_code=400, detail='no http accept in header') |
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
23 |
31
2963f2894a7a
Tempalting change, bugfix for serving raw files, and diffs. Now raw files are not parsed thruough mako, and diffs are mako safe (not parsed also)
Marcin Kuzminski <marcin@python-blog.com>
parents:
22
diff
changeset
|
24 #for mercurial protocols and raw files we can't wrap into mako |
37
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
25 if http_accept.find("mercurial") != -1 or \ |
31
2963f2894a7a
Tempalting change, bugfix for serving raw files, and diffs. Now raw files are not parsed thruough mako, and diffs are mako safe (not parsed also)
Marcin Kuzminski <marcin@python-blog.com>
parents:
22
diff
changeset
|
26 request.environ['PATH_INFO'].find('raw-file') != -1: |
21 | 27 return response |
32
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
28 try: |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
29 tmpl = u''.join(response) |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
30 template = Template(tmpl, lookup=request.environ['pylons.pylons']\ |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
31 .config['pylons.app_globals'].mako_lookup) |
32
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
32 |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
33 except (RuntimeError, UnicodeDecodeError): |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
34 log.info('disabling unicode due to encoding error') |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
35 response = g.hgapp(request.environ, self.start_response) |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
36 tmpl = ''.join(response) |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
37 template = Template(tmpl, lookup=request.environ['pylons.pylons']\ |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
38 .config['pylons.app_globals'].mako_lookup, disable_unicode=True) |
31
2963f2894a7a
Tempalting change, bugfix for serving raw files, and diffs. Now raw files are not parsed thruough mako, and diffs are mako safe (not parsed also)
Marcin Kuzminski <marcin@python-blog.com>
parents:
22
diff
changeset
|
39 |
21 | 40 |
31
2963f2894a7a
Tempalting change, bugfix for serving raw files, and diffs. Now raw files are not parsed thruough mako, and diffs are mako safe (not parsed also)
Marcin Kuzminski <marcin@python-blog.com>
parents:
22
diff
changeset
|
41 return template.render(g=g, c=c, session=session, h=h) |