changeset 111:70b1e5d1e20d

simplehg, cleanup
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 28 Apr 2010 00:16:08 +0200
parents ad2500720b02
children f7c403e89d5b
files pylons_app/lib/simplehg.py
diffstat 1 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylons_app/lib/simplehg.py	Wed Apr 28 00:16:08 2010 +0200
@@ -0,0 +1,37 @@
+import os
+
+import cgi
+from mercurial import util
+from mercurial.hgweb.request import wsgirequest, normalize
+from mercurial.hgweb import hgweb
+from pylons.controllers.util import Response
+from mercurial.hgweb.request import wsgiapplication
+
+
+class SimpleHg(object):
+
+    def __init__(self, application, config):
+        self.application = application
+        self.config = config
+        
+    def __call__(self, environ, start_response):
+        if not is_mercurial(environ):
+            return self.application(environ, start_response)
+        else:
+            from pprint import pprint
+            pprint(environ)
+
+            repo_path = os.path.join('/home/marcink/python_workspace/', environ['PATH_INFO'].replace('/', ''))
+            def _make_app():return hgweb(repo_path, "Name")
+            app = wsgiapplication(_make_app)
+            return app(environ, start_response)            
+                
+def is_mercurial(environ):
+    """
+    Returns True if request's target is mercurial server - header
+    ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
+    """
+    http_accept = environ.get('HTTP_ACCEPT')
+    if http_accept and http_accept.startswith('application/mercurial'):
+        return True
+    return False