comparison pylons_app/lib/simplehg.py @ 178:24dbf4bc57aa

simplehg update
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 21 May 2010 20:58:18 +0200
parents 93bd77e1f3c1
children 3380ca40cdba
comparison
equal deleted inserted replaced
177:93bd77e1f3c1 178:24dbf4bc57aa
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright (c) 2010 marcink. All rights reserved.
5 #
6 """
7 Created on 2010-04-28
8
9 @author: marcink
10 SimpleHG middleware for handling mercurial protocol request (push/clone etc.)
11 It's implemented with basic auth function
12 """
13
1 from mercurial.hgweb import hgweb 14 from mercurial.hgweb import hgweb
2 from mercurial.hgweb.request import wsgiapplication 15 from mercurial.hgweb.request import wsgiapplication
3 from paste.auth.basic import AuthBasicAuthenticator 16 from paste.auth.basic import AuthBasicAuthenticator
4 from paste.httpheaders import REMOTE_USER, AUTH_TYPE 17 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
5 from pylons.controllers.util import abort 18 from pylons_app.lib.utils import is_mercurial
6 from pylons_app.lib.auth import authfunc 19 from pylons_app.lib.auth import authfunc
7 from pylons_app.lib.utils import make_ui, invalidate_cache 20 from pylons_app.lib.utils import make_ui, invalidate_cache
8 from webob.exc import HTTPNotFound 21 from webob.exc import HTTPNotFound
9 import os 22 import os
10 23
69 hgserve.repo.ui = repoui 82 hgserve.repo.ui = repoui
70 83
71 return hgserve 84 return hgserve
72 85
73 86
74
75 def is_mercurial(environ):
76 """
77 Returns True if request's target is mercurial server - header
78 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
79 """
80 http_accept = environ.get('HTTP_ACCEPT')
81 if http_accept and http_accept.startswith('application/mercurial'):
82 return True
83 return False
84
85