3 from PyQt4.QtXml import QDomDocument
4 from sface.xmlwidget import XmlWindow, DomModel
11 def getAndPrint(self, rawOutput):
14 self.xmlrpcWindow.setData(self.xml)
15 if self.xml != "<debug></debug>":
16 # only popup the window if we have something to show
19 def store(self, rawOutput):
20 self.rawOutput = rawOutput
22 def parseMethodResponse(self, mr):
23 tree = etree.fromstring(str(mr))
25 response = {"kind": "unknown"}
27 if tree.tag != "methodResponse" or (len(list(tree))==0):
30 # a fault should look like:
33 # faultString: "Register: Missing authority..."
35 faults = tree.xpath("//methodResponse/fault")
37 response["kind"] = "fault"
38 structs = fault.xpath("value/struct")
39 for struct in structs:
40 members = struct.xpath("member")
41 for member in members:
42 names = member.xpath("name")
43 values = member.xpath("value")
44 if (names) and (values):
47 if len(list(value))>0:
49 response[name.text] = data.text
50 # once we have the first fault, return
53 # whatever didn't fault must have succeeded?
54 response["kind"] = "success"
59 pttrnAsk = '<methodCall>.*?</methodCall>'
60 pttrnAns = '<methodResponse>.*?</methodResponse>'
61 answers = re.compile(pttrnAsk, re.DOTALL).findall(self.rawOutput)
62 replies = re.compile(pttrnAns, re.DOTALL).findall(self.rawOutput)
64 answers = [ x.replace('\\n','\n') for x in answers ]
65 replies = [ x.replace('\\n','\n').replace("'\nbody: '", '') for x in replies ]
66 replies.reverse() # so that I use pop() as popleft
67 # A well-formed XML document must have one, and only one, top-level element
74 # we could have less responses than calls, so guard the pop
76 replyXml = replies.pop()
78 self.responses.append(self.parseMethodResponse(replyXml))
80 # just in case somehow we ended up with more responses than calls
82 replyXml = replies.pop()
84 self.responses.append(self.parseMethodResponse(replyXml))
89 # statistics: round-trip time, size of the com
92 class XmlrpcTracker(XmlrpcReader):
94 XmlrpcReader.__init__(self)
95 self.xmlrpcWindow = XmlrpcWindow()
97 def getAndPrint(self, rawOutput):
100 self.xmlrpcWindow.setData(self.xml)
101 if self.xml != "<debug></debug>":
102 # only popup the window if we have something to show
105 def showXmlrpc(self):
106 self.xmlrpcWindow.show()
107 self.xmlrpcWindow.resize(500, 640)
108 self.xmlrpcWindow.raise_()
109 self.xmlrpcWindow.activateWindow()
111 def extractXml(self):
112 self.xml = "<debug>" + XmlrpcReader.extractXml(self) + "</debug>"
114 class XmlrpcWindow(XmlWindow):
115 def __init__(self, parent=None):
116 # super __init__() calls updateView,
117 # which assumes you have some data
118 self.data = '<debug/>'
119 XmlWindow.__init__(self, parent, 'XMLRPC window')
121 def setData(self, XmlrpcCom):
122 self.data = XmlrpcCom
124 def updateView(self):
125 XmlWindow.updateView(self)
127 self.document.setContent(self.data)