From 763c0f2e7bb9b3422f3951dafe7595eb85041b72 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Sat, 7 Aug 2010 10:58:06 -0400 Subject: [PATCH 1/1] added handle_json() method --- PLC/API.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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) + + -- 2.43.0