MCPcopy Index your code
hub / github.com/python/cpython / _Environ

Class _Environ

Lib/os.py:709–785  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

707from _collections_abc import MutableMapping, Mapping
708
709class _Environ(MutableMapping):
710 def __init__(self, data, encodekey, decodekey, encodevalue, decodevalue):
711 self.encodekey = encodekey
712 self.decodekey = decodekey
713 self.encodevalue = encodevalue
714 self.decodevalue = decodevalue
715 self._data = data
716
717 def __getitem__(self, key):
718 try:
719 value = self._data[self.encodekey(key)]
720 except KeyError:
721 # raise KeyError with the original key value
722 raise KeyError(key) from None
723 return self.decodevalue(value)
724
725 def __setitem__(self, key, value):
726 key = self.encodekey(key)
727 value = self.encodevalue(value)
728 putenv(key, value)
729 self._data[key] = value
730
731 def __delitem__(self, key):
732 encodedkey = self.encodekey(key)
733 unsetenv(encodedkey)
734 try:
735 del self._data[encodedkey]
736 except KeyError:
737 # raise KeyError with the original key value
738 raise KeyError(key) from None
739
740 def __iter__(self):
741 # list() from dict object is an atomic operation
742 keys = list(self._data)
743 for key in keys:
744 yield self.decodekey(key)
745
746 def __len__(self):
747 return len(self._data)
748
749 def __repr__(self):
750 formatted_items = ", ".join(
751 f"{self.decodekey(key)!r}: {self.decodevalue(value)!r}"
752 for key, value in self._data.items()
753 )
754 return f"environ({{{formatted_items}}})"
755
756 def copy(self):
757 return dict(self)
758
759 def setdefault(self, key, value):
760 if key not in self:
761 self[key] = value
762 return self[key]
763
764 def __ior__(self, other):
765 self.update(other)
766 return self

Callers 2

_create_environ_mappingFunction · 0.85
os.pyFile · 0.85

Calls 1

_existsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…