Sun, 12 Sep 2010 12:02:39 +0200
Extended the stream reader API and adjusted the tasks reader accordingly.
E5XML/TasksReader.py | file | annotate | diff | comparison | revisions | |
E5XML/XMLStreamReaderBase.py | file | annotate | diff | comparison | revisions |
--- a/E5XML/TasksReader.py Sun Sep 12 11:58:19 2010 +0200 +++ b/E5XML/TasksReader.py Sun Sep 12 12:02:39 2010 +0200 @@ -74,20 +74,8 @@ "description" : "", } task["priority"] = int(self.attribute("priority", "1")) - - val = self.attribute("completed", "False") - if val in ["True", "False"]: - val = (val == "True") - else: - val = bool(int(val)) - task["completed"] = val - - val = self.attribute("bugfix", "False") - if val in ["True", "False"]: - val = (val == "True") - else: - val = bool(int(val)) - task["bugfix"] = val + task["completed"] = self.toBool(self.attribute("completed", "False")) + task["bugfix"] = self.toBool(self.attribute("bugfix", "False")) while not self.atEnd(): self.readNext()
--- a/E5XML/XMLStreamReaderBase.py Sun Sep 12 11:58:19 2010 +0200 +++ b/E5XML/XMLStreamReaderBase.py Sun Sep 12 12:02:39 2010 +0200 @@ -37,6 +37,22 @@ """ return text.replace(self.NEWPARA, "\n\n").replace(self.NEWLINE, "\n") + def toBool(self, value): + """ + Public method to convert the given value to bool. + + @param value value to be converted ("True", "False", "1", "0") + @return converted value (boolean) or None in case of an error + """ + if value.lower() in ["true", "false"]: + return value.lower() == "true" + + if value in ["1", "0"]: + return bool(int(value)) + + self.raiseBadValue(value) + return None + def showErrorMessage(self): """ Public method to show an error message. @@ -68,6 +84,15 @@ self.raiseError(QCoreApplication.translate("XMLStreamReaderBase", "File format version '{0}' is not supported.".format(version))) + def raiseBadValue(self, value): + """ + Public method to raise an error for a bad value. + + @param value bad value (string) + """ + self.raiseError(QCoreApplication.translate("XMLStreamReaderBase", + "Bad value: {0}".format(value))) + def readXML(self): """ Public method to read and parse the XML document.