added handle_json() method
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Sat, 7 Aug 2010 14:58:06 +0000 (10:58 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Sat, 7 Aug 2010 14:58:06 +0000 (10:58 -0400)
PLC/API.py

index 783280f..8d95f8e 100644 (file)
@@ -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) 
+        
+