mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
SF patch #460805 by Chris Gonnerman: Support for unsetenv()
This adds unsetenv to posix, and uses it in the __delitem__ method of os.environ. (XXX Should we change the preferred name for putenv to setenv, for consistency?)
This commit is contained in:
parent
b6c1d5239c
commit
c524d952da
6 changed files with 81 additions and 19 deletions
28
Lib/os.py
28
Lib/os.py
|
@ -354,6 +354,14 @@ except NameError:
|
|||
else:
|
||||
import UserDict
|
||||
|
||||
# Fake unsetenv() for Windows
|
||||
# not sure about os2 and dos here but
|
||||
# I'm guessing they are the same.
|
||||
|
||||
if name in ('os2', 'nt', 'dos'):
|
||||
def unsetenv(key):
|
||||
putenv(key, "")
|
||||
|
||||
if name == "riscos":
|
||||
# On RISC OS, all env access goes through getenv and putenv
|
||||
from riscosenviron import _Environ
|
||||
|
@ -370,8 +378,15 @@ else:
|
|||
self.data[key.upper()] = item
|
||||
def __getitem__(self, key):
|
||||
return self.data[key.upper()]
|
||||
def __delitem__(self, key):
|
||||
del self.data[key.upper()]
|
||||
try:
|
||||
unsetenv
|
||||
except NameError:
|
||||
def __delitem__(self, key):
|
||||
del self.data[key.upper()]
|
||||
else:
|
||||
def __delitem__(self, key):
|
||||
unsetenv(key)
|
||||
del self.data[key.upper()]
|
||||
def has_key(self, key):
|
||||
return self.data.has_key(key.upper())
|
||||
def get(self, key, failobj=None):
|
||||
|
@ -391,6 +406,15 @@ else:
|
|||
def update(self, dict):
|
||||
for k, v in dict.items():
|
||||
self[k] = v
|
||||
try:
|
||||
unsetenv
|
||||
except NameError:
|
||||
pass
|
||||
else:
|
||||
def __delitem__(self, key):
|
||||
unsetenv(key)
|
||||
del self.data[key]
|
||||
|
||||
|
||||
environ = _Environ(environ)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue