From 7e7adc64713f74976d5994af36b5f758620fb37b Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 13 Oct 2012 21:39:58 +0200 Subject: added JSON and WS client, re organized tests, new classes for easier api tests --- module/remote/json_converter.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'module/remote/json_converter.py') 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 -- cgit v1.2.3