diff options
author | Pavel Zuna <pzuna@redhat.com> | 2010-08-10 16:40:00 -0400 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2010-08-12 09:06:22 -0400 |
commit | f15758dbea6be0894cdc2fcc19ec9d2428c797f1 (patch) | |
tree | 7b414f943c41957f1f412dbdc4150f9c45b884b3 /ipalib/parameters.py | |
parent | 58fd1199f644a07b189087b09fdacbda74b11f27 (diff) | |
download | freeipa-f15758dbea6be0894cdc2fcc19ec9d2428c797f1.tar.gz freeipa-f15758dbea6be0894cdc2fcc19ec9d2428c797f1.tar.xz freeipa-f15758dbea6be0894cdc2fcc19ec9d2428c797f1.zip |
Improve serialization to JSON.
- Make it recursive.
- Make Param classes serializable.
- Take python native data types into account.
Diffstat (limited to 'ipalib/parameters.py')
-rw-r--r-- | ipalib/parameters.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ipalib/parameters.py b/ipalib/parameters.py index c86db758e..234ceff74 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -852,6 +852,20 @@ class Param(ReadOnly): pass return self.default + def __json__(self): + json_dict = {} + for (a, k, d) in self.kwargs: + if k in (callable, DefaultFrom): + continue + elif isinstance(getattr(self, a), frozenset): + json_dict[a] = [k for k in getattr(self, a, [])] + else: + json_dict[a] = getattr(self, a, '') + json_dict['class'] = self.__class__.__name__ + json_dict['name'] = self.name + json_dict['type'] = self.type.__name__ + return json_dict + class Bool(Param): """ |