Kaydet (Commit) 3d75d0cc authored tarafından Victor Stinner's avatar Victor Stinner

Issue #8603: Environ.data is now protected -> Environ._data

os.environ.data was a str dict in Python 3.1. In Python 3.2 on UNIX/BSD,
os.environ.data is now a bytes dict: mark it as protected to avoid confusion.
üst 00ebe2cd
...@@ -420,34 +420,34 @@ class _Environ(MutableMapping): ...@@ -420,34 +420,34 @@ class _Environ(MutableMapping):
self.decodevalue = decodevalue self.decodevalue = decodevalue
self.putenv = putenv self.putenv = putenv
self.unsetenv = unsetenv self.unsetenv = unsetenv
self.data = data self._data = data
def __getitem__(self, key): def __getitem__(self, key):
value = self.data[self.encodekey(key)] value = self._data[self.encodekey(key)]
return self.decodevalue(value) return self.decodevalue(value)
def __setitem__(self, key, value): def __setitem__(self, key, value):
key = self.encodekey(key) key = self.encodekey(key)
value = self.encodevalue(value) value = self.encodevalue(value)
self.putenv(key, value) self.putenv(key, value)
self.data[key] = value self._data[key] = value
def __delitem__(self, key): def __delitem__(self, key):
key = self.encodekey(key) key = self.encodekey(key)
self.unsetenv(key) self.unsetenv(key)
del self.data[key] del self._data[key]
def __iter__(self): def __iter__(self):
for key in self.data: for key in self._data:
yield self.decodekey(key) yield self.decodekey(key)
def __len__(self): def __len__(self):
return len(self.data) return len(self._data)
def __repr__(self): def __repr__(self):
return 'environ({{{}}})'.format(', '.join( return 'environ({{{}}})'.format(', '.join(
('{!r}: {!r}'.format(self.decodekey(key), self.decodevalue(value)) ('{!r}: {!r}'.format(self.decodekey(key), self.decodevalue(value))
for key, value in self.data.items()))) for key, value in self._data.items())))
def copy(self): def copy(self):
return dict(self) return dict(self)
...@@ -521,7 +521,7 @@ if supports_bytes_environ: ...@@ -521,7 +521,7 @@ if supports_bytes_environ:
return value return value
# bytes environ # bytes environ
environb = _Environ(environ.data, environb = _Environ(environ._data,
_check_bytes, bytes, _check_bytes, bytes,
_check_bytes, bytes, _check_bytes, bytes,
_putenv, _unsetenv) _putenv, _unsetenv)
......
...@@ -422,7 +422,6 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): ...@@ -422,7 +422,6 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
def test___repr__(self): def test___repr__(self):
"""Check that the repr() of os.environ looks like environ({...}).""" """Check that the repr() of os.environ looks like environ({...})."""
env = os.environ env = os.environ
self.assertTrue(isinstance(env.data, dict))
self.assertEqual(repr(env), 'environ({{{}}})'.format(', '.join( self.assertEqual(repr(env), 'environ({{{}}})'.format(', '.join(
'{!r}: {!r}'.format(key, value) '{!r}: {!r}'.format(key, value)
for key, value in env.items()))) for key, value in env.items())))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment