Lines Matching +full:key +full:- +full:value
6 # SPDX-License-Identifier: GPL-2.0-only
9 # Be careful when using mutable types (ie Dict and Lists) - operations involving these are SLOW.
40 keys = set(cls.__dict__.keys()) - ignored_keys
54 def __setitem__(cls, key, value): argument
55 if value is not None and not isinstance(value, ImmutableTypes):
56 if not isinstance(value, COWMeta):
58 key += MUTABLE
59 setattr(cls, key, value)
61 def __getmutable__(cls, key, readonly=False): argument
62 nkey = key + MUTABLE
68 value = getattr(cls, nkey)
70 return value
72 if not cls.__warn__ is False and not isinstance(value, COWMeta):
73 print("Warning: Doing a copy because %s is a mutable type." % key, file=cls.__warn__)
75 value = value.copy()
77 value = copy.copy(value)
78 setattr(cls, nkey, value)
79 return value
83 def __getreadonly__(cls, key, default=__getmarker__): argument
85 Get a value (even if mutable) which you promise not to change.
87 return cls.__getitem__(key, default, True)
89 def __getitem__(cls, key, default=__getmarker__, readonly=False): argument
92 value = getattr(cls, key)
94 value = cls.__getmutable__(key, readonly)
97 if value is cls.__marker__:
98 raise AttributeError("key %s does not exist." % key)
100 return value
107 def __delitem__(cls, key): argument
108 cls.__setitem__(key, cls.__marker__)
110 def __revertitem__(cls, key): argument
111 if key not in cls.__dict__:
112 key += MUTABLE
113 delattr(cls, key)
115 def __contains__(cls, key): argument
116 return cls.has_key(key)
118 def has_key(cls, key): argument
119 value = cls.__getreadonly__(key, cls.__marker__)
120 if value is cls.__marker__:
125 for key in dir(cls):
126 if key.startswith("__"):
129 if key.endswith(MUTABLE):
130 key = key[:-len(MUTABLE)]
133 yield key
137 value = cls.__getreadonly__(key)
139 value = cls[key]
144 yield value
146 yield (key, value)
166 keys = set(cls.__dict__.keys()) - ignored_keys
177 def add(cls, value): argument
178 COWDictMeta.__setitem__(cls, repr(hash(value)), value)
180 def remove(cls, value): argument
181 COWDictMeta.__delitem__(cls, repr(hash(value)))
183 def __in__(cls, value): argument
184 return repr(hash(value)) in COWDictMeta