summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/os.py32
-rw-r--r--Lib/test/test_os.py4
-rw-r--r--Lib/test/test_posix.py1
3 files changed, 6 insertions, 31 deletions
diff --git a/Lib/os.py b/Lib/os.py
index ca418ed..7ae1026 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -654,17 +654,15 @@ def get_exec_path(env=None):
return path_list.split(pathsep)
-# Change environ to automatically call putenv(), unsetenv if they exist.
+# Change environ to automatically call putenv() and unsetenv()
from _collections_abc import MutableMapping
class _Environ(MutableMapping):
- def __init__(self, data, encodekey, decodekey, encodevalue, decodevalue, putenv, unsetenv):
+ def __init__(self, data, encodekey, decodekey, encodevalue, decodevalue):
self.encodekey = encodekey
self.decodekey = decodekey
self.encodevalue = encodevalue
self.decodevalue = decodevalue
- self.putenv = putenv
- self.unsetenv = unsetenv
self._data = data
def __getitem__(self, key):
@@ -678,12 +676,12 @@ class _Environ(MutableMapping):
def __setitem__(self, key, value):
key = self.encodekey(key)
value = self.encodevalue(value)
- self.putenv(key, value)
+ putenv(key, value)
self._data[key] = value
def __delitem__(self, key):
encodedkey = self.encodekey(key)
- self.unsetenv(encodedkey)
+ unsetenv(encodedkey)
try:
del self._data[encodedkey]
except KeyError:
@@ -712,22 +710,6 @@ class _Environ(MutableMapping):
self[key] = value
return self[key]
-try:
- _putenv = putenv
-except NameError:
- _putenv = lambda key, value: None
-else:
- if "putenv" not in __all__:
- __all__.append("putenv")
-
-try:
- _unsetenv = unsetenv
-except NameError:
- _unsetenv = lambda key: _putenv(key, "")
-else:
- if "unsetenv" not in __all__:
- __all__.append("unsetenv")
-
def _createenviron():
if name == 'nt':
# Where Env Var Names Must Be UPPERCASE
@@ -755,8 +737,7 @@ def _createenviron():
data = environ
return _Environ(data,
encodekey, decode,
- encode, decode,
- _putenv, _unsetenv)
+ encode, decode)
# unicode environ
environ = _createenviron()
@@ -781,8 +762,7 @@ if supports_bytes_environ:
# bytes environ
environb = _Environ(environ._data,
_check_bytes, bytes,
- _check_bytes, bytes,
- _putenv, _unsetenv)
+ _check_bytes, bytes)
del _check_bytes
def getenvb(key, default=None):
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index dbdc00c..9e3a169 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -953,8 +953,6 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
value_str = value.decode(sys.getfilesystemencoding(), 'surrogateescape')
self.assertEqual(os.environ['bytes'], value_str)
- @unittest.skipUnless(hasattr(os, 'putenv'), "Test needs os.putenv()")
- @unittest.skipUnless(hasattr(os, 'unsetenv'), "Test needs os.unsetenv()")
def test_putenv_unsetenv(self):
name = "PYTHONTESTVAR"
value = "testvalue"
@@ -975,8 +973,6 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
# On OS X < 10.6, unsetenv() doesn't return a value (bpo-13415).
@support.requires_mac_ver(10, 6)
- @unittest.skipUnless(hasattr(os, 'putenv'), "Test needs os.putenv()")
- @unittest.skipUnless(hasattr(os, 'unsetenv'), "Test needs os.unsetenv()")
def test_putenv_unsetenv_error(self):
# Empty variable name is invalid.
# "=" and null character are not allowed in a variable name.
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 4df882b..fad26d8 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -969,7 +969,6 @@ class PosixTester(unittest.TestCase):
self.assertEqual(type(k), item_type)
self.assertEqual(type(v), item_type)
- @unittest.skipUnless(hasattr(os, "putenv"), "requires os.putenv()")
def test_putenv(self):
with self.assertRaises(ValueError):
os.putenv('FRUIT\0VEGETABLE', 'cabbage')