PK œqhYî¶J‚ßF ßF ) nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/
Dir : /proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/ |
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64 IP: 209.182.202.254 |
Dir : //proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/immutabletypes.py |
""" :codeauthor: Pedro Algarvio (pedro@algarvio.me) salt.utils.immutabletypes ~~~~~~~~~~~~~~~~~~~~~~~~~ Immutable types """ import copy from collections.abc import Mapping, Sequence, Set class ImmutableDict(Mapping): """ An immutable dictionary implementation """ def __init__(self, obj): self.__obj = obj def __len__(self): return len(self.__obj) def __iter__(self): return iter(self.__obj) def __getitem__(self, key): return freeze(self.__obj[key]) def __repr__(self): return f"<{self.__class__.__name__} {repr(self.__obj)}>" def __deepcopy__(self, memo): return copy.deepcopy(self.__obj) def copy(self): """ Return an un-frozen copy of self """ return copy.deepcopy(self.__obj) class ImmutableList(Sequence): """ An immutable list implementation """ def __init__(self, obj): self.__obj = obj def __len__(self): return len(self.__obj) def __iter__(self): return iter(self.__obj) def __add__(self, other): return self.__obj + other def __radd__(self, other): return other + self.__obj def __getitem__(self, key): return freeze(self.__obj[key]) def __repr__(self): return f"<{self.__class__.__name__} {repr(self.__obj)}>" def __deepcopy__(self, memo): return copy.deepcopy(self.__obj) def copy(self): """ Return an un-frozen copy of self """ return copy.deepcopy(self.__obj) class ImmutableSet(Set): """ An immutable set implementation """ def __init__(self, obj): self.__obj = obj def __len__(self): return len(self.__obj) def __iter__(self): return iter(self.__obj) def __contains__(self, key): return key in self.__obj def __repr__(self): return f"<{self.__class__.__name__} {repr(self.__obj)}>" def __deepcopy__(self, memo): return copy.deepcopy(self.__obj) def copy(self): """ Return an un-frozen copy of self """ return copy.deepcopy(self.__obj) def freeze(obj): """ Freeze python types by turning them into immutable structures. """ if isinstance(obj, dict): return ImmutableDict(obj) if isinstance(obj, list): return ImmutableList(obj) if isinstance(obj, set): return ImmutableSet(obj) return obj