E5XML/XMLStreamReaderBase.py

Sun, 12 Sep 2010 12:02:39 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 12 Sep 2010 12:02:39 +0200
changeset 592
3ad07054e658
parent 590
beb60b9b3d8d
child 604
a2671d497b49
permissions
-rw-r--r--

Extended the stream reader API and adjusted the tasks reader accordingly.

574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de>
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a base class for all of eric5s XML stream writers.
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import pickle
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import base64
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt4.QtCore import QXmlStreamReader, QCoreApplication
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
15 from E5Gui import E5MessageBox
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
16
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class XMLStreamReaderBase(QXmlStreamReader):
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Class implementing a base class for all of eric5s XML stream readers.
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 def __init__(self, device):
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Constructor
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @param device reference to the I/O device to read from (QIODevice)
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 QXmlStreamReader.__init__(self, device)
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.NEWPARA = chr(0x2029)
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.NEWLINE = chr(0x2028)
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 def decodedNewLines(self, text):
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Public method to decode newlines and paragraph breaks.
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @param text text to decode (string)
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 return text.replace(self.NEWPARA, "\n\n").replace(self.NEWLINE, "\n")
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
592
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
40 def toBool(self, value):
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
41 """
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
42 Public method to convert the given value to bool.
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
43
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
44 @param value value to be converted ("True", "False", "1", "0")
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
45 @return converted value (boolean) or None in case of an error
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
46 """
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
47 if value.lower() in ["true", "false"]:
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
48 return value.lower() == "true"
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
49
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
50 if value in ["1", "0"]:
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
51 return bool(int(value))
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
52
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
53 self.raiseBadValue(value)
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
54 return None
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
55
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
56 def showErrorMessage(self):
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
57 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
58 Public method to show an error message.
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
59 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
60 if self.hasError():
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
61 msg = QCoreApplication.translate("XMLStreamReaderBase",
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
62 "<p>XML parse error in file <b>{0}</b>, line {1}, column {2}<p>"
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
63 "<p>Error: {3}").format(self.device().fileName(),
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
64 self.lineNumber(), self.columnNumber(), self.errorString())
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
65 E5MessageBox.warning(None,
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
66 QCoreApplication.translate("XMLStreamReaderBase", "XML parse error"),
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
67 msg)
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
68
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
69 def raiseUnexpectedStartTag(self, tag):
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
70 """
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
71 Public method to raise an error for an unexpected start tag.
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
72
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
73 @param tag name of the unexpected tag (string)
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
74 """
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
75 self.raiseError(QCoreApplication.translate("XMLStreamReaderBase",
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
76 "Unexpected start tag '{0}'.".format(tag)))
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
77
590
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
78 def raiseUnsupportedFormatVersion(self, version):
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
79 """
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
80 Public method to raise an error for an unsupported file format version.
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
81
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
82 @param version unsupported version (string)
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
83 """
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
84 self.raiseError(QCoreApplication.translate("XMLStreamReaderBase",
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
85 "File format version '{0}' is not supported.".format(version)))
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
86
592
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
87 def raiseBadValue(self, value):
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
88 """
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
89 Public method to raise an error for a bad value.
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
90
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
91 @param value bad value (string)
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
92 """
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
93 self.raiseError(QCoreApplication.translate("XMLStreamReaderBase",
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
94 "Bad value: {0}".format(value)))
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
95
578
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
96 def readXML(self):
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
97 """
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
98 Public method to read and parse the XML document.
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
99 """
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
100 pass
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
101
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
102 def attribute(self, name, default = ""):
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
103 """
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
104 Public method to read the given attribute of the current tag.
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
105
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
106 @param name name of the attribute (string)
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
107 @param default default value (string)
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
108 """
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
109 att = self.attributes().value(name)
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
110 if att == "":
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
111 att = default
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
112 return att
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
113
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 def _skipUnknownElement(self):
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 Protected method to skip over all unknown elements.
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 if not self.isStartElement():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 return
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 while not self.atEnd():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 self.readNext()
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 if self.isEndElement():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 break
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 if self.isStartElement():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 self._skipUnknownElement()
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 def _readBasics(self):
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
131 Protected method to read an object of a basic Python type.
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 @return Python object read
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 while not self.atEnd():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 self.readNext()
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 if self.isStartElement():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 try:
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 if self.name() == "none":
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
140 val = None
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 elif self.name() == "int":
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
142 val = int(self.readElementText())
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 elif self.name() == "bool":
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 b = self.readElementText()
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 if b == "True":
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
146 val = True
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 else:
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
148 val = False
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 elif self.name() == "float":
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
150 val = float(self.readElementText())
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 elif self.name() == "complex":
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 real, imag = self.readElementText().split()
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
153 val = float(real) + float(imag)*1j
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 elif self.name() == "string":
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
155 val = self.readElementText()
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 elif self.name() == "bytes":
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 by = bytes(
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 [int(b) for b in self.readElementText().split(",")])
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
159 val = by
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 elif self.name() == "bytearray":
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 by = bytearray(
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 [int(b) for b in self.readElementText().split(",")])
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
163 val = by
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
164 elif self.name() == "tuple":
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
165 val = self.__readTuple()
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
166 return val
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
167 elif self.name() == "list":
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
168 val = self.__readList()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
169 return val
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
170 elif self.name() == "dict":
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
171 val = self.__readDict()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
172 return val
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
173 elif self.name() == "set":
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
174 val = self.__readSet()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
175 return val
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
176 elif self.name() == "frozenset":
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
177 val = self.__readFrozenset()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
178 return val
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
179 elif self.name() == "pickle":
578
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
180 encoding = self.attribute("encoding")
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
181 if encoding != "base64":
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
182 self.raiseError(QCoreApplication.translate(
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
183 "XMLStreamReaderBase",
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
184 "Pickle data encoding '{0}' is not supported.")\
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
185 .format(encoding))
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
186 continue
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
187 b64 = self.readElementText()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
188 pic = base64.b64decode(b64.encode("ASCII"))
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
189 val = pickle.loads(pic)
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 else:
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self._skipUnknownElement()
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 except ValueError as err:
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 self.raiseError(str(err))
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
194 continue
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
195
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
196 if self.isEndElement():
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
197 if self.name() in ["tuple", "list", "dict", "set", "frozenset"]:
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
198 return None
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
199 else:
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
200 return val
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
201
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
202 def __readTuple(self):
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
203 """
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
204 Private method to read a Python tuple.
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
205
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
206 @return Python tuple
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
207 """
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
208 l = []
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
209 while not self.atEnd():
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
210 val = self._readBasics()
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
211 if self.isEndElement() and self.name() == "tuple" and val is None:
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
212 return tuple(l)
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
213 else:
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
214 l.append(val)
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
215
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
216 def __readList(self):
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
217 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
218 Private method to read a Python list.
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
219
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
220 @return Python list
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
221 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
222 l = []
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
223 while not self.atEnd():
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
224 val = self._readBasics()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
225 if self.isEndElement() and self.name() == "list" and val is None:
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
226 return l
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
227 else:
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
228 l.append(val)
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
229
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
230 def __readDict(self):
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
231 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
232 Private method to read a Python dictionary.
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
233
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
234 @return Python dictionary
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
235 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
236 d = {}
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
237 while not self.atEnd():
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
238 self.readNext()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
239 if self.isStartElement():
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
240 if self.name() == "key":
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
241 key = self._readBasics()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
242 elif self.name() == "value":
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
243 d[key] = self._readBasics()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
244 if self.isEndElement() and self.name() == "dict":
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
245 self.readNext()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
246
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
247 if self.isEndElement() and self.name() == "dict":
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
248 return d
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
249
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
250 def __readSet(self):
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
251 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
252 Private method to read a Python set.
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
253
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
254 @return Python set
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
255 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
256 l = []
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
257 while not self.atEnd():
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
258 val = self._readBasics()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
259 if self.isEndElement() and self.name() == "set" and val is None:
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
260 return set(l)
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
261 else:
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
262 l.append(val)
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
263
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
264 def __readFrozenset(self):
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
265 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
266 Private method to read a Python set.
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
267
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
268 @return Python set
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
269 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
270 l = []
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
271 while not self.atEnd():
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
272 val = self._readBasics()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
273 if self.isEndElement() and self.name() == "frozenset" and val is None:
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
274 return frozenset(l)
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
275 else:
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
276 l.append(val)

eric ide

mercurial