use xmlrpclib.loads rather than parsing manually
[sface.git] / sface / xmlrpcwindow.py
index 72b0f68..995b108 100644 (file)
@@ -1,4 +1,5 @@
 import re
 import re
+import xmlrpclib
 from lxml import etree
 from PyQt4.QtXml import QDomDocument
 from sface.xmlwidget import XmlWindow, DomModel, XmlView, XmlDelegate, ElemNodeDelegate, TextNodeDelegate, CommentNodeDelegate
 from lxml import etree
 from PyQt4.QtXml import QDomDocument
 from sface.xmlwidget import XmlWindow, DomModel, XmlView, XmlDelegate, ElemNodeDelegate, TextNodeDelegate, CommentNodeDelegate
@@ -15,39 +16,6 @@ class XmlrpcReader():
     def store(self, rawOutput):
         self.rawOutput = rawOutput
 
     def store(self, rawOutput):
         self.rawOutput = rawOutput
 
-    def paramString(self, item):
-        """
-           Convert an xmlrpc <PARAM> into a human-readable string
-           Is there an easier way?
-        """
-        if item.tag == "string":
-            return item.text
-        elif item.tag == "array":
-            arrayValues = item.xpath("data/value")
-            if arrayValues:
-                children = list(arrayValues[0])
-                if children:
-                    return self.paramString(children[0]) + ", ..."
-                else:
-                    return "[]"
-            else:
-                return "[]"
-        elif item.tag == "struct":
-            dict = {}
-            members = item.xpath("member")
-            for member in members:
-                names = member.xpath("name")
-                values = member.xpath("value")
-                if (names) and (values):
-                    name = names[0]
-                    value = values[0]
-                    if len(list(value))>0:
-                        data = list(value)[0]
-                        dict[name.text] = self.paramString(list(value)[0])
-            return str(dict)
-        else:
-            return "unknown"
-
     def parseMethodCall(self, mc):
         mc = str(mc)
 
     def parseMethodCall(self, mc):
         mc = str(mc)
 
@@ -61,20 +29,14 @@ class XmlrpcReader():
         if tree.tag != "methodCall" or (len(list(tree))==0):
             return request
 
         if tree.tag != "methodCall" or (len(list(tree))==0):
             return request
 
-        methodNames = tree.xpath("//methodCall/methodName")
-
-        if len(methodNames) == 0:
-            return request
-
-        request["args"] = []
-
-        params = tree.xpath("//methodCall/params/param/value")
-        for param in params:
-            children = list(param)
-            if children:
-                request["args"].append(self.paramString(children[0]))
+        try:
+            (pythonParams, methodName) = xmlrpclib.loads(etree.tostring(tree))
+        except:  # in case something went wrong when unmarashaling...
+            pythonParams = []
+            methodName = "<exception in parseMethodCall>"
 
 
-        request["methodName"] = methodNames[0].text
+        request["args"] = [str(x) for x in pythonParams]
+        request["methodName"] = methodName # methodNames[0].text
 
         return request
 
 
         return request