Patch #1181: add os.environ.clear() method.
This commit is contained in:
parent
e2176020f9
commit
4a21268a74
|
@ -117,7 +117,11 @@ process and user.
|
||||||
|
|
||||||
If the platform supports the :func:`unsetenv` function, you can delete items in
|
If the platform supports the :func:`unsetenv` function, you can delete items in
|
||||||
this mapping to unset environment variables. :func:`unsetenv` will be called
|
this mapping to unset environment variables. :func:`unsetenv` will be called
|
||||||
automatically when an item is deleted from ``os.environ``.
|
automatically when an item is deleted from ``os.environ``, and when
|
||||||
|
:meth:`os.environ.clear` is called.
|
||||||
|
|
||||||
|
.. versionchanged:: 2.6
|
||||||
|
Also unset environment variables when calling :meth:`os.environ.clear`.
|
||||||
|
|
||||||
|
|
||||||
.. function:: chdir(path)
|
.. function:: chdir(path)
|
||||||
|
|
|
@ -446,6 +446,10 @@ else:
|
||||||
def __delitem__(self, key):
|
def __delitem__(self, key):
|
||||||
unsetenv(key)
|
unsetenv(key)
|
||||||
del self.data[key.upper()]
|
del self.data[key.upper()]
|
||||||
|
def clear(self):
|
||||||
|
for key in self.data.keys():
|
||||||
|
unsetenv(key)
|
||||||
|
del self.data[key]
|
||||||
def has_key(self, key):
|
def has_key(self, key):
|
||||||
return key.upper() in self.data
|
return key.upper() in self.data
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
|
@ -503,6 +507,10 @@ else:
|
||||||
def __delitem__(self, key):
|
def __delitem__(self, key):
|
||||||
unsetenv(key)
|
unsetenv(key)
|
||||||
del self.data[key]
|
del self.data[key]
|
||||||
|
def clear(self):
|
||||||
|
for key in self.data.keys():
|
||||||
|
unsetenv(key)
|
||||||
|
del self.data[key]
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return dict(self)
|
return dict(self)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue