[Python-checkins] r78317 - in python/branches/release31-maint: Lib/os.py Lib/test/test_os.py Misc/NEWS

ezio.melotti python-checkins at python.org
Mon Feb 22 17:01:22 CET 2010


Author: ezio.melotti
Date: Mon Feb 22 17:01:22 2010
New Revision: 78317
Log:
Merged revisions 78316 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
 r78316 | ezio.melotti | 2010年02月22日 17:59:01 +0200 (2010年2月22日) | 1 line
 
 #7310: fix the repr() of os.environ
........
Modified:
 python/branches/release31-maint/ (props changed)
 python/branches/release31-maint/Lib/os.py
 python/branches/release31-maint/Lib/test/test_os.py
 python/branches/release31-maint/Misc/NEWS
Modified: python/branches/release31-maint/Lib/os.py
==============================================================================
--- python/branches/release31-maint/Lib/os.py	(original)
+++ python/branches/release31-maint/Lib/os.py	Mon Feb 22 17:01:22 2010
@@ -387,22 +387,32 @@
 self.data = data = {}
 for key, value in environ.items():
 data[keymap(key)] = str(value)
+
 def __getitem__(self, key):
 return self.data[self.keymap(key)]
+
 def __setitem__(self, key, value):
 value = str(value)
 self.putenv(key, value)
 self.data[self.keymap(key)] = value
+
 def __delitem__(self, key):
 self.unsetenv(key)
 del self.data[self.keymap(key)]
+
 def __iter__(self):
 for key in self.data:
 yield key
+
 def __len__(self):
 return len(self.data)
+
+ def __repr__(self):
+ return 'environ({!r})'.format(self.data)
+
 def copy(self):
 return dict(self)
+
 def setdefault(self, key, value):
 if key not in self:
 self[key] = value
Modified: python/branches/release31-maint/Lib/test/test_os.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_os.py	(original)
+++ python/branches/release31-maint/Lib/test/test_os.py	Mon Feb 22 17:01:22 2010
@@ -400,6 +400,14 @@
 for key, value in self._reference().items():
 self.assertEqual(os.environ.get(key), value)
 
+ # Issue 7310
+ def test___repr__(self):
+ """Check that the repr() of os.environ looks like environ({...})."""
+ env = os.environ
+ self.assertTrue(isinstance(env.data, dict))
+ self.assertEqual(repr(env), 'environ({!r})'.format(env.data))
+
+
 class WalkTests(unittest.TestCase):
 """Tests for os.walk()."""
 
Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Mon Feb 22 17:01:22 2010
@@ -79,6 +79,8 @@
 Library
 -------
 
+- Issue #7310: fix the __repr__ of os.environ to show the environment variables.
+
 - Issue #7970: email.Generator.flatten now correctly flattens message/rfc822
 messages parsed by email.Parser.HeaderParser.
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /