##// END OF EJS Templates
jsonalchemy: add de_coerce to reverse serialization of list and dict elements from Mutation objects back to original state.
marcink -
r2397:737f97b5 default
parent child Browse files
Show More
@@ -99,6 +99,9 b' class MutationObj(Mutable):'
99 99 return MutationList.coerce(key, value)
100 100 return value
101 101
102 def de_coerce(self):
103 return self
104
102 105 @classmethod
103 106 def _listen_on_attribute(cls, attribute, coerce, parent_cls):
104 107 key = attribute.key
@@ -158,6 +161,9 b' class MutationDict(MutationObj, DictClas'
158 161 self._key = key
159 162 return self
160 163
164 def de_coerce(self):
165 return dict(self)
166
161 167 def __setitem__(self, key, value):
162 168 # Due to the way OrderedDict works, this is called during __init__.
163 169 # At this time we don't have a key set, but what is more, the value
@@ -177,7 +183,7 b' class MutationDict(MutationObj, DictClas'
177 183 def __reduce_ex__(self, proto):
178 184 # support pickling of MutationDicts
179 185 d = dict(self)
180 return (self.__class__, (d, ))
186 return (self.__class__, (d,))
181 187
182 188
183 189 class MutationList(MutationObj, list):
@@ -188,6 +194,9 b' class MutationList(MutationObj, list):'
188 194 self._key = key
189 195 return self
190 196
197 def de_coerce(self):
198 return list(self)
199
191 200 def __setitem__(self, idx, value):
192 201 list.__setitem__(self, idx, MutationObj.coerce(self._key, value))
193 202 self.changed()
General Comments 0
You need to be logged in to leave comments. Login now