# HG changeset patch # User Marcin Kuzminski # Date 2017-11-26 16:18:28 # Node ID 737f97b5ebf28aa8fb9aabcdec2fddf562e07245 # Parent 6206bdd36545e90696c6673bbf0994fc81900795 jsonalchemy: add de_coerce to reverse serialization of list and dict elements from Mutation objects back to original state. diff --git a/rhodecode/lib/jsonalchemy.py b/rhodecode/lib/jsonalchemy.py --- a/rhodecode/lib/jsonalchemy.py +++ b/rhodecode/lib/jsonalchemy.py @@ -99,6 +99,9 @@ class MutationObj(Mutable): return MutationList.coerce(key, value) return value + def de_coerce(self): + return self + @classmethod def _listen_on_attribute(cls, attribute, coerce, parent_cls): key = attribute.key @@ -158,6 +161,9 @@ class MutationDict(MutationObj, DictClas self._key = key return self + def de_coerce(self): + return dict(self) + def __setitem__(self, key, value): # Due to the way OrderedDict works, this is called during __init__. # At this time we don't have a key set, but what is more, the value @@ -177,7 +183,7 @@ class MutationDict(MutationObj, DictClas def __reduce_ex__(self, proto): # support pickling of MutationDicts d = dict(self) - return (self.__class__, (d, )) + return (self.__class__, (d,)) class MutationList(MutationObj, list): @@ -188,6 +194,9 @@ class MutationList(MutationObj, list): self._key = key return self + def de_coerce(self): + return list(self) + def __setitem__(self, idx, value): list.__setitem__(self, idx, MutationObj.coerce(self._key, value)) self.changed()