summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/parameters.py14
-rw-r--r--ipalib/plugins/baseldap.py3
-rw-r--r--ipalib/util.py12
3 files changed, 27 insertions, 2 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):
"""
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index c42039a5d..43fafe32a 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -137,7 +137,8 @@ class LDAPObject(Object):
json_dict = dict(
(a, getattr(self, a)) for a in self.json_friendly_attributes
)
- json_dict['primary_key'] = self.primary_key.name
+ if self.primary_key:
+ json_dict['primary_key'] = self.primary_key.name
json_dict['methods'] = [m for m in self.methods]
return json_dict
diff --git a/ipalib/util.py b/ipalib/util.py
index ba111d46b..4aff88f83 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -27,15 +27,25 @@ import logging
import time
import krbV
import socket
+from types import NoneType
+
from ipalib import errors
from ipapython import dnsclient
def json_serialize(obj):
+ if isinstance(obj, (list, tuple)):
+ return [json_serialize(o) for o in obj]
+ if isinstance(obj, dict):
+ return dict((k, json_serialize(v)) for (k, v) in obj.iteritems())
+ if isinstance(obj, (bool, float, int, unicode, NoneType)):
+ return obj
+ if isinstance(obj, str):
+ return obj.decode('utf-8')
if not callable(getattr(obj, '__json__', None)):
# raise TypeError('%r is not JSON serializable')
return ''
- return obj.__json__()
+ return json_serialize(obj.__json__())
def get_current_principal():
try: