diff options
author | Victor Stinner <vstinner@python.org> | 2020-01-24 13:05:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-24 13:05:48 (GMT) |
commit | b8d1262e8afe7b907b4a394a191739571092acdb (patch) | |
tree | 32ad60fdd1ee4b039233a25a0663f022f97b0e77 /Lib/os.py | |
parent | 161e7b36b1ea871a1352ccfc1d4f4c1eda76830f (diff) | |
download | cpython-b8d1262e8afe7b907b4a394a191739571092acdb.zip cpython-b8d1262e8afe7b907b4a394a191739571092acdb.tar.gz cpython-b8d1262e8afe7b907b4a394a191739571092acdb.tar.bz2 |
bpo-39395: putenv() and unsetenv() always available (GH-18135)
The os.putenv() and os.unsetenv() functions are now always available.
On non-Windows platforms, Python now requires setenv() and unsetenv()
functions to build.
Remove putenv_dict from posixmodule.c: it's not longer needed.
Diffstat (limited to 'Lib/os.py')
-rw-r--r-- | Lib/os.py | 32 |
1 files changed, 6 insertions, 26 deletions
@@ -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): |