Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,11 @@ def get_exec_path(env=None):
# Change environ to automatically call putenv() and unsetenv()
from _collections_abc import MutableMapping, Mapping

# Sentinel used for seeing if a value is found within the internal _Environ
# dictionary.
_MISSING = sentinel("MISSING")


class _Environ(MutableMapping):
def __init__(self, data, encodekey, decodekey, encodevalue, decodevalue):
self.encodekey = encodekey
Expand All @@ -728,6 +733,9 @@ def __init__(self, data, encodekey, decodekey, encodevalue, decodevalue):
self.decodevalue = decodevalue
self._data = data

def __contains__(self, key):
return self.encodekey(key) in self._data

def __getitem__(self, key):
try:
value = self._data[self.encodekey(key)]
Expand Down Expand Up @@ -770,6 +778,10 @@ def __repr__(self):
def copy(self):
return dict(self)

def get(self, key, default = None):
val = self._data.get(self.encodekey(key), _MISSING)
return default if val is _MISSING else self.decodevalue(val)

def setdefault(self, key, value):
if key not in self:
self[key] = value
Expand Down
Loading