[PATCH 1 of 1] ui: add environ property to access os.environ or wsgirequest.environ
Sune Foldager
cryo at cyanite.org
Mon Nov 9 03:14:14 CST 2009
# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1257757868 -3600
# Node ID 86d0bf1943132203d1ce76adb84fdb4659724b04
# Parent 4ce13d7c6b8855e028dd284e03d416400fcb5225
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
@@ -66,6 +68,8 @@
self.allowpull = self.configbool("web", "allowpull", True)
encoding.encoding = self.config("web", "encoding",
encoding.encoding)
+ elif request:
+ self.repo.ui.environ = request.environ
def run(self):
if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
@@ -80,7 +84,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,12 +29,17 @@
self._ocfg = src._ocfg.copy()
self._trustusers = src._trustusers.copy()
self._trustgroups = src._trustgroups.copy()
+ self.environ = src.environ
self.fixconfig()
else:
# we always trust global config files
for f in util.rcpath():
self.readconfig(f, trust=True)
+ @property
+ def environ(self):
+ return os.environ
+
def copy(self):
return self.__class__(self)
More information about the Mercurial-devel
mailing list