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