]> granicus.if.org Git - python/commitdiff
Added hook to os.environ to call putenv(), if it exists.
authorGuido van Rossum <guido@python.org>
Wed, 24 Jul 1996 00:55:17 +0000 (00:55 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 24 Jul 1996 00:55:17 +0000 (00:55 +0000)
Lib/os.py

index d974c59fa0f3e748d26056d985ebb0d85256884f..51e8a67fca56277f968f24a93231ca2388ddda31 100644 (file)
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -121,3 +121,22 @@ if name == 'nt':
                                list.append(line[:-1])
                                line = f.readline()
                        return list
+
+
+# Change environ to automatically call putenv() if it exists
+try:
+       _putenv = putenv
+except NameError:
+       _putenv = None
+if _putenv:
+       import UserDict
+
+       class _Environ(UserDict.UserDict):
+               def __init__(self, environ):
+                       UserDict.UserDict.__init__(self)
+                       self.data = environ
+               def __setitem__(self, key, item):
+                       putenv(key, item)
+                       self.data[key] = item
+
+       environ = _Environ(environ)