changeset 9887:38170eeed18c

ui: add environ property to access os.environ or wsgirequest.environ The property returns os.environ by default, and is propagated 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. The property is meant to be read-only, as with os.environ (generally).
author Sune Foldager <cryo@cyanite.org>
date Thu, 19 Nov 2009 10:32:33 +0100
parents 56af3f240a22
children 510122bb3c7f
files mercurial/hgweb/hgweb_mod.py mercurial/ui.py
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Sun Nov 08 00:27:15 2009 +0100
+++ b/mercurial/hgweb/hgweb_mod.py	Thu Nov 19 10:32:33 2009 +0100
@@ -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
--- a/mercurial/ui.py	Sun Nov 08 00:27:15 2009 +0100
+++ b/mercurial/ui.py	Thu Nov 19 10:32:33 2009 +0100
@@ -29,8 +29,11 @@
             self._ocfg = src._ocfg.copy()
             self._trustusers = src._trustusers.copy()
             self._trustgroups = src._trustgroups.copy()
+            self.environ = src.environ
             self.fixconfig()
         else:
+            # shared read-only environment
+            self.environ = os.environ
             # we always trust global config files
             for f in util.rcpath():
                 self.readconfig(f, trust=True)