Mercurial > kallithea
comparison pylons_app/lib/simplehg.py @ 124:f8ae5c1dfae2
Removed unneeded PATH_INFO manipulation, and added 404 codes on bad repositories paths
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 29 Apr 2010 00:29:49 +0200 |
parents | 345811faa8a0 |
children | 52bbeb1e813f |
comparison
equal
deleted
inserted
replaced
123:f57bd22d433d | 124:f8ae5c1dfae2 |
---|---|
1 import os | 1 import os |
2 from mercurial.hgweb import hgweb | 2 from mercurial.hgweb import hgweb |
3 from mercurial.hgweb.request import wsgiapplication | 3 from mercurial.hgweb.request import wsgiapplication |
4 from pylons_app.lib.utils import make_ui | 4 from pylons_app.lib.utils import make_ui |
5 from pylons.controllers.util import abort | |
6 from webob.exc import HTTPNotFound | |
5 class SimpleHg(object): | 7 class SimpleHg(object): |
6 | 8 |
7 def __init__(self, application, config): | 9 def __init__(self, application, config): |
8 self.application = application | 10 self.application = application |
9 self.config = config | 11 self.config = config |
10 | 12 |
11 def __call__(self, environ, start_response): | 13 def __call__(self, environ, start_response): |
12 if not is_mercurial(environ): | 14 if not is_mercurial(environ): |
13 return self.application(environ, start_response) | 15 return self.application(environ, start_response) |
14 else: | 16 else: |
15 #repo_name = environ['PATH_INFO'].replace('/', '') | 17 try: |
16 repo_name = environ['PATH_INFO'].split('/')[1] | 18 repo_name = environ['PATH_INFO'].split('/')[1] |
17 if not environ['PATH_INFO'].endswith == '/': | 19 except: |
18 environ['PATH_INFO'] += '/' | 20 return HTTPNotFound()(environ, start_response) |
19 #environ['SCRIPT_NAME'] = request.path | 21 |
22 #since we wrap into hgweb, just reset the path | |
20 environ['PATH_INFO'] = '/' | 23 environ['PATH_INFO'] = '/' |
21 self.baseui = make_ui() | 24 self.baseui = make_ui() |
22 self.basepath = self.baseui.configitems('paths')[0][1].replace('*', '') | 25 self.basepath = self.baseui.configitems('paths')[0][1].replace('*', '') |
23 self.repo_path = os.path.join(self.basepath, repo_name) | 26 self.repo_path = os.path.join(self.basepath, repo_name) |
24 app = wsgiapplication(self._make_app) | 27 try: |
28 app = wsgiapplication(self._make_app) | |
29 except Exception as e: | |
30 return HTTPNotFound()(environ, start_response) | |
25 return app(environ, start_response) | 31 return app(environ, start_response) |
26 | 32 |
27 def _make_app(self): | 33 def _make_app(self): |
28 hgserve = hgweb(self.repo_path) | 34 hgserve = hgweb(self.repo_path) |
29 return self.load_web_settings(hgserve) | 35 return self.load_web_settings(hgserve) |