##// 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 return MutationList.coerce(key, value)
99 return MutationList.coerce(key, value)
100 return value
100 return value
101
101
102 def de_coerce(self):
103 return self
104
102 @classmethod
105 @classmethod
103 def _listen_on_attribute(cls, attribute, coerce, parent_cls):
106 def _listen_on_attribute(cls, attribute, coerce, parent_cls):
104 key = attribute.key
107 key = attribute.key
@@ -158,6 +161,9 b' class MutationDict(MutationObj, DictClas'
158 self._key = key
161 self._key = key
159 return self
162 return self
160
163
164 def de_coerce(self):
165 return dict(self)
166
161 def __setitem__(self, key, value):
167 def __setitem__(self, key, value):
162 # Due to the way OrderedDict works, this is called during __init__.
168 # Due to the way OrderedDict works, this is called during __init__.
163 # At this time we don't have a key set, but what is more, the value
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 def __reduce_ex__(self, proto):
183 def __reduce_ex__(self, proto):
178 # support pickling of MutationDicts
184 # support pickling of MutationDicts
179 d = dict(self)
185 d = dict(self)
180 return (self.__class__, (d, ))
186 return (self.__class__, (d,))
181
187
182
188
183 class MutationList(MutationObj, list):
189 class MutationList(MutationObj, list):
@@ -188,6 +194,9 b' class MutationList(MutationObj, list):'
188 self._key = key
194 self._key = key
189 return self
195 return self
190
196
197 def de_coerce(self):
198 return list(self)
199
191 def __setitem__(self, idx, value):
200 def __setitem__(self, idx, value):
192 list.__setitem__(self, idx, MutationObj.coerce(self._key, value))
201 list.__setitem__(self, idx, MutationObj.coerce(self._key, value))
193 self.changed()
202 self.changed()
General Comments 0
You need to be logged in to leave comments. Login now