From: Tony Mack Date: Sat, 7 Aug 2010 14:58:06 +0000 (-0400) Subject: added handle_json() method X-Git-Tag: plcapi-5.0-17~6 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=763c0f2e7bb9b3422f3951dafe7595eb85041b72;hp=3042666c8109c44d258fbcec85e19df2dc0edac8;p=plcapi.git added handle_json() method --- diff --git a/PLC/API.py b/PLC/API.py index 783280f..8d95f8e 100644 --- a/PLC/API.py +++ b/PLC/API.py @@ -14,6 +14,7 @@ import traceback import string import xmlrpclib +import simplejson # See "2.2 Characters" in the XML specification: # @@ -207,3 +208,17 @@ class PLCAPI: data = buildSOAP(kw = {'%sResponse' % method: {'Result': result}}, encoding = self.encoding) return data + + def handle_json(self, source, data): + """ + Handle a JSON request + """ + method, args = simplejson.loads(data) + try: + result = self.call(source, method, *args) + except Exception, e: + result = str(e) + + return simplejson.dumps(result) + +