mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Close #17702: os.environ now raises KeyError with the original environment
variable name (str on UNIX), instead of using the encoded name (bytes on UNIX).
This commit is contained in:
parent
c4e0d982f3
commit
6d10139d70
3 changed files with 34 additions and 4 deletions
16
Lib/os.py
16
Lib/os.py
|
@ -669,7 +669,11 @@ class _Environ(MutableMapping):
|
|||
self._data = data
|
||||
|
||||
def __getitem__(self, key):
|
||||
value = self._data[self.encodekey(key)]
|
||||
try:
|
||||
value = self._data[self.encodekey(key)]
|
||||
except KeyError:
|
||||
# raise KeyError with the original key value
|
||||
raise KeyError(key)
|
||||
return self.decodevalue(value)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
|
@ -679,9 +683,13 @@ class _Environ(MutableMapping):
|
|||
self._data[key] = value
|
||||
|
||||
def __delitem__(self, key):
|
||||
key = self.encodekey(key)
|
||||
self.unsetenv(key)
|
||||
del self._data[key]
|
||||
encodedkey = self.encodekey(key)
|
||||
self.unsetenv(encodedkey)
|
||||
try:
|
||||
del self._data[encodedkey]
|
||||
except KeyError:
|
||||
# raise KeyError with the original key value
|
||||
raise KeyError(key)
|
||||
|
||||
def __iter__(self):
|
||||
for key in self._data:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue