[PATCH 1 of 1] ui: add environ property to access os.environ or wsgirequest.environ

Sune Foldager cryo at cyanite.org
Wed Nov 18 04:09:55 CST 2009


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1258537090 -3600
# Node ID baa71bc536e9dd50e33f8e50dce7684d6dd08e76
# Parent  d266aa7606ce82fa926a1d3389453d7cb7b8f200
ui: add environ property to access os.environ or wsgirequest.environ

The property returns os.environ by default, and is propagted by
ui.copy. During hgweb processing, ui.environ is set to the proper
WSGI-request environment, as contained in wsgirequest.environ. For
CGI, this is the same as os.environ.

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -54,7 +54,9 @@
         return self.repo.ui.configlist(section, name, default,
                                        untrusted=untrusted)
 
-    def refresh(self):
+    def refresh(self, request=None):
+        if request:
+            self.ui.environ = request.environ
         mtime = get_mtime(self.repo.root)
         if mtime != self.mtime:
             self.mtime = mtime
@@ -80,7 +82,7 @@
 
     def run_wsgi(self, req):
 
-        self.refresh()
+        self.refresh(req)
 
         # work with CGI variables to create coherent structure
         # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -29,8 +29,10 @@
             self._ocfg = src._ocfg.copy()
             self._trustusers = src._trustusers.copy()
             self._trustgroups = src._trustgroups.copy()
+            self.environ = src.environ
             self.fixconfig()
         else:
+            self.environ = os.environ
             # we always trust global config files
             for f in util.rcpath():
                 self.readconfig(f, trust=True)


More information about the Mercurial-devel mailing list