summaryrefslogtreecommitdiffstats
path: root/module/remote/json_converter.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-10-13 21:39:58 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-10-13 21:39:58 +0200
commit7e7adc64713f74976d5994af36b5f758620fb37b (patch)
tree868084317f8818dbb327c76eaff3c7c7edce0231 /module/remote/json_converter.py
parentfixed JsEngine init (diff)
downloadpyload-7e7adc64713f74976d5994af36b5f758620fb37b.tar.xz
added JSON and WS client, re organized tests, new classes for easier api tests
Diffstat (limited to 'module/remote/json_converter.py')
-rw-r--r--module/remote/json_converter.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/module/remote/json_converter.py b/module/remote/json_converter.py
index 57e85fd16..ea76842a6 100644
--- a/module/remote/json_converter.py
+++ b/module/remote/json_converter.py
@@ -1,7 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from module.common.json_layer import json
+try:
+ from module.common.json_layer import json
+except ImportError:
+ import json
+
+
+import ttypes
from ttypes import BaseObject
# json encoder that accepts TBase objects
@@ -16,18 +22,12 @@ class BaseEncoder(json.JSONEncoder):
return json.JSONEncoder.default(self, o)
-class BaseDecoder(json.JSONDecoder):
-
- def __init__(self, *args, **kwargs):
- json.JSONDecoder.__init__(self, *args, **kwargs)
- self.object_hook = self.convertObject
-
- def convertObject(self, dct):
- if '@class' in dct:
- # TODO: convert
- pass
- return dct
+def convert_obj(dct):
+ if '@class' in dct:
+ cls = getattr(ttypes, dct['@class'])
+ del dct['@class']
+ return cls(**dct)
def dumps(*args, **kwargs):
kwargs['cls'] = BaseEncoder
@@ -35,5 +35,5 @@ def dumps(*args, **kwargs):
def loads(*args, **kwargs):
- kwargs['cls'] = BaseDecoder
+ kwargs['object_hook'] = convert_obj
return json.loads(*args, **kwargs) \ No newline at end of file