]> granicus.if.org Git - python/commitdiff
Patch #1181: add os.environ.clear() method.
authorGeorg Brandl <georg@python.org>
Thu, 20 Sep 2007 17:57:59 +0000 (17:57 +0000)
committerGeorg Brandl <georg@python.org>
Thu, 20 Sep 2007 17:57:59 +0000 (17:57 +0000)
Doc/library/os.rst
Lib/os.py

index 7f03a754c3b1e6081a3b799b248d862a4730c9e8..24830d2394a0141d6571b68d9c27a2083085def1 100644 (file)
@@ -115,9 +115,13 @@ process and user.
    passed to the appropriate process-creation functions to cause  child processes
    to use a modified environment.
 
-   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
-   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)
index 206aa371b3436c72b89bfe480e7dc428abd1f567..7d21763603ed08b50ac9b6323d51233b8fea2c5b 100644 (file)
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -446,6 +446,10 @@ else:
                 def __delitem__(self, key):
                     unsetenv(key)
                     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):
                 return key.upper() in self.data
             def __contains__(self, key):
@@ -503,6 +507,10 @@ else:
                 def __delitem__(self, key):
                     unsetenv(key)
                     del self.data[key]
+                def clear(self):
+                    for key in self.data.keys():
+                        unsetenv(key)
+                        del self.data[key]
             def copy(self):
                 return dict(self)