diff --git a/synergy/client/command.py b/synergy/client/command.py index 4e2fb35..3d06d62 100644 --- a/synergy/client/command.py +++ b/synergy/client/command.py @@ -1,7 +1,7 @@ import json import requests -from synergy.common import utils +from synergy.common.utils import objectHookHandler from tabulate import tabulate @@ -35,32 +35,16 @@ class HTTPCommand(object): def configureParser(self, subparser): raise NotImplementedError("not implemented!") - def objectHookHandler(self, parsed_dict): - if "synergy_object" in parsed_dict: - synergy_object = parsed_dict["synergy_object"] - try: - objClass = utils.import_class(synergy_object["name"]) - - objInstance = objClass() - return objInstance.deserialize(parsed_dict) - except Exception as ex: - print(ex) - raise ex - else: - return parsed_dict - def execute(self, synergy_url, payload=None): request = requests.get(synergy_url, params=payload) if request.status_code != requests.codes.ok: - # print(request.reason) - # print(request.status_code) request.raise_for_status() self.results = request.json() try: - return json.loads(request.text, object_hook=self.objectHookHandler) + return json.loads(request.text, object_hook=objectHookHandler) except Exception: return request.json() diff --git a/synergy/client/shell.py b/synergy/client/shell.py index b97b2d7..405ea2e 100644 --- a/synergy/client/shell.py +++ b/synergy/client/shell.py @@ -176,7 +176,6 @@ def main(): print("command %r not found!" % command_name) commands[command_name].execute(synergy_url, args) - # commands[command_name].log() except KeyboardInterrupt as e: print("Shutting down synergyclient") sys.exit(1) diff --git a/synergy/common/serializer.py b/synergy/common/serializer.py index f0102e2..f8fdb25 100644 --- a/synergy/common/serializer.py +++ b/synergy/common/serializer.py @@ -92,11 +92,9 @@ class SynergyObject(object): try: objName = synergy_object["name"] - # objVer = synergy_object['version'] objClass = utils.import_class(objName) objInstance = objClass() except Exception as ex: - print(ex) raise Exception("error on deserializing the object %r: %s" % (objName, ex)) diff --git a/synergy/common/utils.py b/synergy/common/utils.py index 0b209cb..66735b4 100644 --- a/synergy/common/utils.py +++ b/synergy/common/utils.py @@ -31,3 +31,16 @@ def import_class(import_str): raise ImportError( 'Class %s cannot be found (%s)' % (class_str, traceback.format_exception(*sys.exc_info()))) + + +def objectHookHandler(parsed_dict): + if "synergy_object" in parsed_dict: + synergy_object = parsed_dict["synergy_object"] + try: + objClass = import_class(synergy_object["name"]) + objInstance = objClass() + return objInstance.deserialize(parsed_dict) + except Exception as ex: + raise ex + else: + return parsed_dict diff --git a/synergy/tests/functional/test_synergy.py b/synergy/tests/functional/test_synergy.py index 811f1d1..4ab1859 100644 --- a/synergy/tests/functional/test_synergy.py +++ b/synergy/tests/functional/test_synergy.py @@ -23,7 +23,7 @@ import sys import time from mock import Mock -from synergy.common import utils +from synergy.common.utils import objectHookHandler from synergy.service import Synergy logging.basicConfig(level=logging.DEBUG) @@ -48,21 +48,6 @@ def getLogger(name): return logger -def objectHookHandler(parsed_dict): - if "synergy_object" in parsed_dict: - synergy_object = parsed_dict["synergy_object"] - try: - objClass = utils.import_class(synergy_object["name"]) - - objInstance = objClass() - return objInstance.deserialize(parsed_dict) - except Exception as ex: - print(ex) - raise ex - else: - return parsed_dict - - class SynergyTests(unittest.TestCase): @mock.patch('synergy.service.LOG', LOG) diff --git a/test-requirements.txt b/test-requirements.txt index 56027c3..58f8a7b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -13,5 +13,4 @@ testrepository>=0.0.18 testscenarios>=0.4 testtools>=1.4.0 mock==2.0.0 -tabulate>=0.7.2,<0.8.0