From: Martin v. Löwis Date: Sat, 29 Jan 2005 13:29:23 +0000 (+0000) Subject: Revert os.py 1.75, and directly implement update. X-Git-Tag: v2.5a0~2072 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1d11de6dbd247689c508de2ec28f0f3fc35ecabc;p=thirdparty%2FPython%2Fcpython.git Revert os.py 1.75, and directly implement update. Fixes #1110478 and #1100235. --- diff --git a/Lib/os.py b/Lib/os.py index d3b9a8d5107c..b967978600df 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -442,6 +442,17 @@ else: return key.upper() in self.data def get(self, key, failobj=None): return self.data.get(key.upper(), failobj) + def update(self, dict=None, **kwargs): + if dict: + try: + items = dict.items() + except AttributeError: + # List of (key, value) + items = dict + for k, v in items: + self[k] = v + if kwargs: + self.update(kwargs) def copy(self): return dict(self) @@ -453,6 +464,17 @@ else: def __setitem__(self, key, item): putenv(key, item) self.data[key] = item + def update(self, dict=None, **kwargs): + if dict: + try: + items = dict.items() + except AttributeError: + # List of (key, value) + items = dict + for k, v in items: + self[k] = v + if kwargs: + self.update(kwargs) try: unsetenv except NameError: diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 472d13fd092a..cce692636f27 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -226,6 +226,13 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): os.environ.clear() os.environ.update(self.__save) + # Bug 1110478 + def test_update(self): + if os.path.exists("/bin/sh"): + os.environ.update(HELLO="World") + value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip() + self.assertEquals(value, "World") + class WalkTests(unittest.TestCase): """Tests for os.walk().""" diff --git a/Misc/NEWS b/Misc/NEWS index 1d919aa50ba2..92d94224fc4c 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -45,6 +45,8 @@ Extension Modules Library ------- +- Bug #1110478: Revert os.environ.update to do putenv again. + - Bug #1103844: fix distutils.install.dump_dirs() with negated options. - os.{SEEK_SET, SEEK_CUR, SEEK_END} have been added for convenience.