From 5510f65f5a033eb8d0e9d90046087047410846f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Thu, 17 Feb 2005 21:23:20 +0000 Subject: Avoid using items() in environ.update(). Fixes #1124513. Will backport to 2.4. --- Lib/os.py | 26 ++++++++++++++++++-------- Lib/test/test_os.py | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Lib/os.py b/Lib/os.py index b967978..5824609 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -445,12 +445,17 @@ else: def update(self, dict=None, **kwargs): if dict: try: - items = dict.items() + keys = dict.keys() except AttributeError: # List of (key, value) - items = dict - for k, v in items: - self[k] = v + for k, v in dict: + self[k] = v + else: + # got keys + # cannot use items(), since mappings + # may not have them. + for k in keys: + self[k] = dict[k] if kwargs: self.update(kwargs) def copy(self): @@ -467,12 +472,17 @@ else: def update(self, dict=None, **kwargs): if dict: try: - items = dict.items() + keys = dict.keys() except AttributeError: # List of (key, value) - items = dict - for k, v in items: - self[k] = v + for k, v in dict: + self[k] = v + else: + # got keys + # cannot use items(), since mappings + # may not have them. + for k in keys: + self[k] = dict[k] if kwargs: self.update(kwargs) try: diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index cce6926..2bc5fc0 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -227,7 +227,7 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): os.environ.update(self.__save) # Bug 1110478 - def test_update(self): + def test_update2(self): if os.path.exists("/bin/sh"): os.environ.update(HELLO="World") value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip() -- cgit v0.12