From 38d5f241770d94bfcea955e889a110acb96ddf81 Mon Sep 17 00:00:00 2001 From: smbaker Date: Tue, 20 Sep 2011 18:10:56 -0700 Subject: [PATCH] use xmlrpclib.loads rather than parsing manually --- sface/xmlrpcwindow.py | 54 +++++++------------------------------------ 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/sface/xmlrpcwindow.py b/sface/xmlrpcwindow.py index 72b0f68..995b108 100644 --- a/sface/xmlrpcwindow.py +++ b/sface/xmlrpcwindow.py @@ -1,4 +1,5 @@ import re +import xmlrpclib 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 paramString(self, item): - """ - Convert an xmlrpc 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) @@ -61,20 +29,14 @@ class XmlrpcReader(): 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 = "" - request["methodName"] = methodNames[0].text + request["args"] = [str(x) for x in pythonParams] + request["methodName"] = methodName # methodNames[0].text return request -- 2.43.0