47 """ |
47 """ |
48 Public method to show an error message. |
48 Public method to show an error message. |
49 """ |
49 """ |
50 if self.hasError(): |
50 if self.hasError(): |
51 msg = QCoreApplication.translate("XMLStreamReaderBase", |
51 msg = QCoreApplication.translate("XMLStreamReaderBase", |
52 "<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}," |
53 "<p>Error: {3}</p>").format(self.device().fileName(), |
53 " column {2}</p><p>Error: {3}</p>").format( |
54 self.lineNumber(), self.columnNumber(), self.errorString()) |
54 self.device().fileName(), |
|
55 self.lineNumber(), self.columnNumber(), |
|
56 self.errorString()) |
55 E5MessageBox.warning(None, |
57 E5MessageBox.warning(None, |
56 QCoreApplication.translate("XMLStreamReaderBase", "XML parse error"), |
58 QCoreApplication.translate( |
|
59 "XMLStreamReaderBase", "XML parse error"), |
57 msg) |
60 msg) |
58 |
61 |
59 def raiseUnexpectedStartTag(self, tag): |
62 def raiseUnexpectedStartTag(self, tag): |
60 """ |
63 """ |
61 Public method to raise an error for an unexpected start tag. |
64 Public method to raise an error for an unexpected start tag. |
129 try: |
132 try: |
130 if self.name() == "none": |
133 if self.name() == "none": |
131 val = None |
134 val = None |
132 elif self.name() == "int": |
135 elif self.name() == "int": |
133 val = int(self.readElementText()) |
136 val = int(self.readElementText()) |
134 elif self.name() == "long": # backward compatibility to 4.6 |
137 elif self.name() == "long": |
|
138 # backward compatibility to 4.6 |
135 val = int(self.readElementText()) |
139 val = int(self.readElementText()) |
136 elif self.name() == "bool": |
140 elif self.name() == "bool": |
137 b = self.readElementText() |
141 b = self.readElementText() |
138 if b == "True": |
142 if b == "True": |
139 val = True |
143 val = True |
144 elif self.name() == "complex": |
148 elif self.name() == "complex": |
145 real, imag = self.readElementText().split() |
149 real, imag = self.readElementText().split() |
146 val = float(real) + float(imag) * 1j |
150 val = float(real) + float(imag) * 1j |
147 elif self.name() == "string": |
151 elif self.name() == "string": |
148 val = self.readElementText() |
152 val = self.readElementText() |
149 elif self.name() == "unicode": # backward compatibility to 4.6 |
153 elif self.name() == "unicode": |
|
154 # backward compatibility to 4.6 |
150 val = self.readElementText() |
155 val = self.readElementText() |
151 elif self.name() == "bytes": |
156 elif self.name() == "bytes": |
152 by = bytes( |
157 by = bytes([int(b) for b in |
153 [int(b) for b in self.readElementText().split(",")]) |
158 self.readElementText().split(",")]) |
154 val = by |
159 val = by |
155 elif self.name() == "bytearray": |
160 elif self.name() == "bytearray": |
156 by = bytearray( |
161 by = bytearray([int(b) for b in |
157 [int(b) for b in self.readElementText().split(",")]) |
162 self.readElementText().split(",")]) |
158 val = by |
163 val = by |
159 elif self.name() == "tuple": |
164 elif self.name() == "tuple": |
160 val = self.__readTuple() |
165 val = self.__readTuple() |
161 return val |
166 return val |
162 elif self.name() == "list": |
167 elif self.name() == "list": |
174 elif self.name() == "pickle": |
179 elif self.name() == "pickle": |
175 encoding = self.attribute("encoding") |
180 encoding = self.attribute("encoding") |
176 if encoding != "base64": |
181 if encoding != "base64": |
177 self.raiseError(QCoreApplication.translate( |
182 self.raiseError(QCoreApplication.translate( |
178 "XMLStreamReaderBase", |
183 "XMLStreamReaderBase", |
179 "Pickle data encoding '{0}' is not supported.")\ |
184 "Pickle data encoding '{0}' is not" |
180 .format(encoding)) |
185 " supported.").format(encoding)) |
181 continue |
186 continue |
182 b64 = self.readElementText() |
187 b64 = self.readElementText() |
183 pic = base64.b64decode(b64.encode("ASCII")) |
188 pic = base64.b64decode(b64.encode("ASCII")) |
184 val = pickle.loads(pic) |
189 val = pickle.loads(pic) |
185 else: |
190 else: |
187 except ValueError as err: |
192 except ValueError as err: |
188 self.raiseError(str(err)) |
193 self.raiseError(str(err)) |
189 continue |
194 continue |
190 |
195 |
191 if self.isEndElement(): |
196 if self.isEndElement(): |
192 if self.name() in ["tuple", "list", "dict", "set", "frozenset"]: |
197 if self.name() in [ |
|
198 "tuple", "list", "dict", "set", "frozenset"]: |
193 return None |
199 return None |
194 else: |
200 else: |
195 return val |
201 return val |
196 |
202 |
197 def __readTuple(self): |
203 def __readTuple(self): |