src/eric7/EricXML/XMLStreamReaderBase.py

branch
eric7
changeset 10423
299802979277
parent 9653
e67609152c5e
child 10439
21c28b0f9e41
equal deleted inserted replaced
10422:e28b89693f37 10423:299802979277
22 22
23 def __init__(self, device): 23 def __init__(self, device):
24 """ 24 """
25 Constructor 25 Constructor
26 26
27 @param device reference to the I/O device to read from (QIODevice) 27 @param device reference to the I/O device to read from
28 @type QIODevice
28 """ 29 """
29 super().__init__(device) 30 super().__init__(device)
30 31
31 def toBool(self, value): 32 def toBool(self, value):
32 """ 33 """
33 Public method to convert the given value to bool. 34 Public method to convert the given value to bool.
34 35
35 @param value value to be converted ("True", "False", "1", "0") 36 @param value value to be converted ("True", "False", "1", "0")
36 @return converted value (boolean) or None in case of an error 37 @type str
38 @return converted value or None in case of an error
39 @rtype bool
37 """ 40 """
38 if value.lower() in ["true", "false"]: 41 if value.lower() in ["true", "false"]:
39 return value.lower() == "true" 42 return value.lower() == "true"
40 43
41 if value in ["1", "0"]: 44 if value in ["1", "0"]:
73 76
74 def raiseUnexpectedStartTag(self, tag): 77 def raiseUnexpectedStartTag(self, tag):
75 """ 78 """
76 Public method to raise an error for an unexpected start tag. 79 Public method to raise an error for an unexpected start tag.
77 80
78 @param tag name of the unexpected tag (string) 81 @param tag name of the unexpected tag
82 @type str
79 """ 83 """
80 self.raiseError( 84 self.raiseError(
81 QCoreApplication.translate( 85 QCoreApplication.translate(
82 "XMLStreamReaderBase", "Unexpected start tag '{0}'.".format(tag) 86 "XMLStreamReaderBase", "Unexpected start tag '{0}'.".format(tag)
83 ) 87 )
85 89
86 def raiseUnsupportedFormatVersion(self, version): 90 def raiseUnsupportedFormatVersion(self, version):
87 """ 91 """
88 Public method to raise an error for an unsupported file format version. 92 Public method to raise an error for an unsupported file format version.
89 93
90 @param version unsupported version (string) 94 @param version unsupported version
95 @type str
91 """ 96 """
92 self.raiseError( 97 self.raiseError(
93 QCoreApplication.translate( 98 QCoreApplication.translate(
94 "XMLStreamReaderBase", "File format version '{0}' is not supported." 99 "XMLStreamReaderBase", "File format version '{0}' is not supported."
95 ).format(version) 100 ).format(version)
97 102
98 def raiseBadValue(self, value): 103 def raiseBadValue(self, value):
99 """ 104 """
100 Public method to raise an error for a bad value. 105 Public method to raise an error for a bad value.
101 106
102 @param value bad value (string) 107 @param value bad value
108 @type str
103 """ 109 """
104 self.raiseError( 110 self.raiseError(
105 QCoreApplication.translate("XMLStreamReaderBase", "Bad value: {0}").format( 111 QCoreApplication.translate("XMLStreamReaderBase", "Bad value: {0}").format(
106 value 112 value
107 ) 113 )
115 121
116 def attribute(self, name, default=""): 122 def attribute(self, name, default=""):
117 """ 123 """
118 Public method to read the given attribute of the current tag. 124 Public method to read the given attribute of the current tag.
119 125
120 @param name name of the attribute (string) 126 @param name name of the attribute
121 @param default default value (string) 127 @type str
122 @return value of the requested tag attribute (string) 128 @param default default value
129 @type str
130 @return value of the requested tag attribute
131 @rtype str
123 """ 132 """
124 try: 133 try:
125 att = self.attributes().value(name) 134 att = self.attributes().value(name)
126 if att == "": 135 if att == "":
127 att = default 136 att = default
157 def _readBasics(self): 166 def _readBasics(self):
158 """ 167 """
159 Protected method to read an object of a basic Python type. 168 Protected method to read an object of a basic Python type.
160 169
161 @return Python object read 170 @return Python object read
171 @rtype Any
162 """ 172 """
163 while not self.atEnd(): 173 while not self.atEnd():
164 self.readNext() 174 self.readNext()
165 if self.isStartElement(): 175 if self.isStartElement():
166 try: 176 try:
232 def __readTuple(self): 242 def __readTuple(self):
233 """ 243 """
234 Private method to read a Python tuple. 244 Private method to read a Python tuple.
235 245
236 @return Python tuple 246 @return Python tuple
247 @rtype tuple
237 """ 248 """
238 li = [] 249 li = []
239 while not self.atEnd(): 250 while not self.atEnd():
240 val = self._readBasics() 251 val = self._readBasics()
241 if self.isEndElement() and self.name() == "tuple" and val is None: 252 if self.isEndElement() and self.name() == "tuple" and val is None:
246 def __readList(self): 257 def __readList(self):
247 """ 258 """
248 Private method to read a Python list. 259 Private method to read a Python list.
249 260
250 @return Python list 261 @return Python list
262 @rtype list
251 """ 263 """
252 li = [] 264 li = []
253 while not self.atEnd(): 265 while not self.atEnd():
254 val = self._readBasics() 266 val = self._readBasics()
255 if self.isEndElement() and self.name() == "list" and val is None: 267 if self.isEndElement() and self.name() == "list" and val is None:
260 def __readDict(self): 272 def __readDict(self):
261 """ 273 """
262 Private method to read a Python dictionary. 274 Private method to read a Python dictionary.
263 275
264 @return Python dictionary 276 @return Python dictionary
277 @rtype dict
265 """ 278 """
266 d = {} 279 d = {}
267 while not self.atEnd(): 280 while not self.atEnd():
268 self.readNext() 281 self.readNext()
269 if self.isStartElement(): 282 if self.isStartElement():
280 def __readSet(self): 293 def __readSet(self):
281 """ 294 """
282 Private method to read a Python set. 295 Private method to read a Python set.
283 296
284 @return Python set 297 @return Python set
298 @rtype set
285 """ 299 """
286 li = [] 300 li = []
287 while not self.atEnd(): 301 while not self.atEnd():
288 val = self._readBasics() 302 val = self._readBasics()
289 if self.isEndElement() and self.name() == "set" and val is None: 303 if self.isEndElement() and self.name() == "set" and val is None:
291 else: 305 else:
292 li.append(val) 306 li.append(val)
293 307
294 def __readFrozenset(self): 308 def __readFrozenset(self):
295 """ 309 """
296 Private method to read a Python set. 310 Private method to read a Python frozenset.
297 311
298 @return Python set 312 @return Python frozenset
313 @rtype frozenset
299 """ 314 """
300 li = [] 315 li = []
301 while not self.atEnd(): 316 while not self.atEnd():
302 val = self._readBasics() 317 val = self._readBasics()
303 if self.isEndElement() and self.name() == "frozenset" and val is None: 318 if self.isEndElement() and self.name() == "frozenset" and val is None:

eric ide

mercurial