remove body: with a double-quote before it, tolerate parsing errors in parseMethodRes...
authorsmbaker <smbaker@fc8clean.lan>
Wed, 7 Sep 2011 02:44:17 +0000 (19:44 -0700)
committersmbaker <smbaker@fc8clean.lan>
Wed, 7 Sep 2011 02:44:17 +0000 (19:44 -0700)
sface/xmlrpcwindow.py

index cc17584..81007c0 100644 (file)
@@ -20,10 +20,17 @@ class XmlrpcReader():
         self.rawOutput = rawOutput
 
     def parseMethodResponse(self, mr):
-        tree = etree.fromstring(str(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
 
@@ -62,7 +69,7 @@ class XmlrpcReader():
         replies = re.compile(pttrnAns, re.DOTALL).findall(self.rawOutput)
         # cleaning
         answers = [ x.replace('\\n','\n') for x in answers ]
-        replies = [ x.replace('\\n','\n').replace("'\nbody: '", '') for x in replies ]
+        replies = [ x.replace('\\n','\n').replace("'\nbody: '", '').replace("\"\nbody: '", '') for x in replies ]
         replies.reverse() # so that I use pop() as popleft
         # A well-formed XML document must have one, and only one, top-level element