diff --git a/pysearpc/__init__.py b/pysearpc/__init__.py index 084d0da..4703b7d 100644 --- a/pysearpc/__init__.py +++ b/pysearpc/__init__.py @@ -1,2 +1,2 @@ -from client import SearpcClient, searpc_func, SearpcError +from client import SearpcClient, searpc_func, SearpcError, SearpcObjEncoder diff --git a/pysearpc/client.py b/pysearpc/client.py index 7f4a55f..f44b1aa 100644 --- a/pysearpc/client.py +++ b/pysearpc/client.py @@ -8,7 +8,6 @@ class SearpcError(Exception): def __str__(self): return self.msg - def _fret_int(ret_str): try: dicts = json.loads(ret_str) @@ -57,6 +56,12 @@ class _SearpcObj(object): except: return None +class SearpcObjEncoder(json.JSONEncoder): + def default(self, obj): + if not isinstance(obj, _SearpcObj): + return super(_SearpcObjEncoder, self).default(obj) + return obj._dict + def _fret_obj(ret_str): try: dicts = json.loads(ret_str)