comparison pylons_app/lib/simplehg.py @ 111:70b1e5d1e20d

simplehg, cleanup
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 28 Apr 2010 00:16:08 +0200
parents
children cc5cf1a93902
comparison
equal deleted inserted replaced
110:ad2500720b02 111:70b1e5d1e20d
1 import os
2
3 import cgi
4 from mercurial import util
5 from mercurial.hgweb.request import wsgirequest, normalize
6 from mercurial.hgweb import hgweb
7 from pylons.controllers.util import Response
8 from mercurial.hgweb.request import wsgiapplication
9
10
11 class SimpleHg(object):
12
13 def __init__(self, application, config):
14 self.application = application
15 self.config = config
16
17 def __call__(self, environ, start_response):
18 if not is_mercurial(environ):
19 return self.application(environ, start_response)
20 else:
21 from pprint import pprint
22 pprint(environ)
23
24 repo_path = os.path.join('/home/marcink/python_workspace/', environ['PATH_INFO'].replace('/', ''))
25 def _make_app():return hgweb(repo_path, "Name")
26 app = wsgiapplication(_make_app)
27 return app(environ, start_response)
28
29 def is_mercurial(environ):
30 """
31 Returns True if request's target is mercurial server - header
32 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
33 """
34 http_accept = environ.get('HTTP_ACCEPT')
35 if http_accept and http_accept.startswith('application/mercurial'):
36 return True
37 return False