E5XML/XMLStreamReaderBase.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1131
7781e396c903
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
11 import base64 11 import base64
12 12
13 from PyQt4.QtCore import QXmlStreamReader, QCoreApplication 13 from PyQt4.QtCore import QXmlStreamReader, QCoreApplication
14 14
15 from E5Gui import E5MessageBox 15 from E5Gui import E5MessageBox
16
16 17
17 class XMLStreamReaderBase(QXmlStreamReader): 18 class XMLStreamReaderBase(QXmlStreamReader):
18 """ 19 """
19 Class implementing a base class for all of eric5s XML stream readers. 20 Class implementing a base class for all of eric5s XML stream readers.
20 """ 21 """
47 Public method to show an error message. 48 Public method to show an error message.
48 """ 49 """
49 if self.hasError(): 50 if self.hasError():
50 msg = QCoreApplication.translate("XMLStreamReaderBase", 51 msg = QCoreApplication.translate("XMLStreamReaderBase",
51 "<p>XML parse error in file <b>{0}</b>, line {1}, column {2}</p>" 52 "<p>XML parse error in file <b>{0}</b>, line {1}, column {2}</p>"
52 "<p>Error: {3}</p>").format(self.device().fileName(), 53 "<p>Error: {3}</p>").format(self.device().fileName(),
53 self.lineNumber(), self.columnNumber(), self.errorString()) 54 self.lineNumber(), self.columnNumber(), self.errorString())
54 E5MessageBox.warning(None, 55 E5MessageBox.warning(None,
55 QCoreApplication.translate("XMLStreamReaderBase", "XML parse error"), 56 QCoreApplication.translate("XMLStreamReaderBase", "XML parse error"),
56 msg) 57 msg)
57 58
86 """ 87 """
87 Public method to read and parse the XML document. 88 Public method to read and parse the XML document.
88 """ 89 """
89 pass 90 pass
90 91
91 def attribute(self, name, default = ""): 92 def attribute(self, name, default=""):
92 """ 93 """
93 Public method to read the given attribute of the current tag. 94 Public method to read the given attribute of the current tag.
94 95
95 @param name name of the attribute (string) 96 @param name name of the attribute (string)
96 @param default default value (string) 97 @param default default value (string)
139 val = False 140 val = False
140 elif self.name() == "float": 141 elif self.name() == "float":
141 val = float(self.readElementText()) 142 val = float(self.readElementText())
142 elif self.name() == "complex": 143 elif self.name() == "complex":
143 real, imag = self.readElementText().split() 144 real, imag = self.readElementText().split()
144 val = float(real) + float(imag)*1j 145 val = float(real) + float(imag) * 1j
145 elif self.name() == "string": 146 elif self.name() == "string":
146 val = self.readElementText() 147 val = self.readElementText()
147 elif self.name() == "unicode": # backward compatibility to 4.6 148 elif self.name() == "unicode": # backward compatibility to 4.6
148 val = self.readElementText() 149 val = self.readElementText()
149 elif self.name() == "bytes": 150 elif self.name() == "bytes":
171 return val 172 return val
172 elif self.name() == "pickle": 173 elif self.name() == "pickle":
173 encoding = self.attribute("encoding") 174 encoding = self.attribute("encoding")
174 if encoding != "base64": 175 if encoding != "base64":
175 self.raiseError(QCoreApplication.translate( 176 self.raiseError(QCoreApplication.translate(
176 "XMLStreamReaderBase", 177 "XMLStreamReaderBase",
177 "Pickle data encoding '{0}' is not supported.")\ 178 "Pickle data encoding '{0}' is not supported.")\
178 .format(encoding)) 179 .format(encoding))
179 continue 180 continue
180 b64 = self.readElementText() 181 b64 = self.readElementText()
181 pic = base64.b64decode(b64.encode("ASCII")) 182 pic = base64.b64decode(b64.encode("ASCII"))

eric ide

mercurial