+ def parseMethodResponse(self, mr):
+ mr = str(mr) # PyQT supplies a QByteArray; make it a string
+
+ response = {"kind": "unknown"}
+
+ try:
+ tree = etree.fromstring(mr)
+ except etree.XMLSyntaxError, e:
+ print "failed to parse XML response", str(e)
+ #file("badparse.xml","w").write(mr)
+ return response
+
+ if tree.tag != "methodResponse" or (len(list(tree))==0):
+ return response
+
+ # a fault should look like:
+ # kind: "fault"
+ # faultCode: "102"
+ # faultString: "Register: Missing authority..."
+
+ faults = tree.xpath("//methodResponse/fault")
+ for fault in faults:
+ response["kind"] = "fault"
+ structs = fault.xpath("value/struct")
+ for struct in structs:
+ members = struct.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]
+ response[name.text] = data.text
+ # once we have the first fault, return
+ return response
+
+ # whatever didn't fault must have succeeded?
+ response["kind"] = "success"
+
+ return response
+