diff options
author | Guido van Rossum <guido@python.org> | 2001-10-19 01:31:59 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-10-19 01:31:59 (GMT) |
commit | c524d952da928f745203876f2e67f651c2bc7246 (patch) | |
tree | 59686a72378708c6884596341bdd353d5ac3e4bf /Lib | |
parent | b6c1d5239cfeadd761d2055cc44212f7a6b7e5af (diff) | |
download | cpython-c524d952da928f745203876f2e67f651c2bc7246.zip cpython-c524d952da928f745203876f2e67f651c2bc7246.tar.gz cpython-c524d952da928f745203876f2e67f651c2bc7246.tar.bz2 |
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?)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/os.py | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -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) |