E5XML/XMLStreamReaderBase.py

Sun, 03 Sep 2017 17:08:26 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 03 Sep 2017 17:08:26 +0200
changeset 5870
82e04c70f969
parent 5389
9b1c800daff3
child 6048
82ad8ec9548c
permissions
-rw-r--r--

Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.

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
5389
9b1c800daff3 Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
3 # Copyright (c) 2010 - 2017 Detlev Offenbach <detlev@die-offenbachs.de>
574
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 """
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
7 Module implementing a base class for all of eric6s XML stream writers.
574
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
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
11
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import pickle
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import base64
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
15 from PyQt5.QtCore import QXmlStreamReader, QCoreApplication
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
17 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
18
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
19
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class XMLStreamReaderBase(QXmlStreamReader):
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
22 Class implementing a base class for all of eric6s XML stream readers.
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 def __init__(self, device):
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @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
29 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
30 super(XMLStreamReaderBase, self).__init__(device)
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
592
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
32 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
33 """
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
34 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
35
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
36 @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
37 @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
38 """
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
39 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
40 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
41
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
42 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
43 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
44
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
45 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
46 return None
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
47
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
48 def showErrorMessage(self):
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
49 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
50 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
51 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
52 if self.hasError():
5870
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
53 if self.device() is not None:
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
54 msg = QCoreApplication.translate(
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
55 "XMLStreamReaderBase",
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
56 "<p>XML parse error in file <b>{0}</b>, line {1},"
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
57 " column {2}</p><p>Error: {3}</p>").format(
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
58 self.device().fileName(),
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
59 self.lineNumber(), self.columnNumber(),
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
60 self.errorString())
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
61 else:
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
62 msg = QCoreApplication.translate(
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
63 "XMLStreamReaderBase",
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
64 "<p>XML parse error (line {0},"
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
65 " column {1})</p><p>Error: {2}</p>").format(
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
66 self.lineNumber(), self.columnNumber(),
82e04c70f969 Finished implementing a downloader and installer/uninstaller for web browser spell check dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
67 self.errorString())
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
68 E5MessageBox.warning(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
69 None,
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
70 QCoreApplication.translate(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
71 "XMLStreamReaderBase", "XML parse error"),
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
72 msg)
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
73
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
74 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
75 """
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
76 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
77
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 578
diff changeset
78 @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
79 """
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
80 self.raiseError(QCoreApplication.translate(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
81 "XMLStreamReaderBase", "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
82
590
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
83 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
84 """
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
85 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
86
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
87 @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
88 """
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
89 self.raiseError(QCoreApplication.translate(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
90 "XMLStreamReaderBase",
604
a2671d497b49 Updated translations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 592
diff changeset
91 "File format version '{0}' is not supported.").format(version))
590
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
92
592
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
93 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
94 """
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
95 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
96
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
97 @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
98 """
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
99 self.raiseError(QCoreApplication.translate(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
100 "XMLStreamReaderBase", "Bad value: {0}").format(value))
592
3ad07054e658 Extended the stream reader API and adjusted the tasks reader accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 590
diff changeset
101
578
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
102 def readXML(self):
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 and parse the XML document.
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 pass
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
107
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
108 def attribute(self, name, default=""):
578
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
109 """
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
110 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
111
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
112 @param name name of the attribute (string)
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
113 @param default default value (string)
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
114 @return value of the requested tag attribute (string)
578
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
115 """
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
116 att = self.attributes().value(name)
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
117 if att == "":
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
118 att = default
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
119 return att
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
120
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 def _skipUnknownElement(self):
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 Protected method to skip over all unknown elements.
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 if not self.isStartElement():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 return
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 while not self.atEnd():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self.readNext()
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 if self.isEndElement():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 break
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 if self.isStartElement():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 self._skipUnknownElement()
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 def _readBasics(self):
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 """
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
138 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
139
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 @return Python object read
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 """
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 while not self.atEnd():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 self.readNext()
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 if self.isStartElement():
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 try:
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 if self.name() == "none":
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
147 val = None
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 elif self.name() == "int":
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
149 val = int(self.readElementText())
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
150 elif self.name() == "long":
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
151 # backward compatibility to 4.6
617
97baf3ff9d9d Added some compatibility code to XMLStreamReaderBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
152 val = int(self.readElementText())
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 elif self.name() == "bool":
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 b = self.readElementText()
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 if b == "True":
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
156 val = True
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 else:
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
158 val = False
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 elif self.name() == "float":
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
160 val = float(self.readElementText())
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 elif self.name() == "complex":
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 real, imag = self.readElementText().split()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
163 val = float(real) + float(imag) * 1j
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 elif self.name() == "string":
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
165 val = self.readElementText()
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
166 elif self.name() == "unicode":
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
167 # backward compatibility to 4.6
617
97baf3ff9d9d Added some compatibility code to XMLStreamReaderBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
168 val = self.readElementText()
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 elif self.name() == "bytes":
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
170 by = bytes([int(b) for b in
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
171 self.readElementText().split(",")])
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
172 val = by
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 elif self.name() == "bytearray":
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
174 by = bytearray([int(b) for b in
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
175 self.readElementText().split(",")])
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
176 val = by
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
177 elif self.name() == "tuple":
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
178 val = self.__readTuple()
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
179 return val
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
180 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
181 val = self.__readList()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
182 return val
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
183 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
184 val = self.__readDict()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
185 return val
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
186 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
187 val = self.__readSet()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
188 return val
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
189 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
190 val = self.__readFrozenset()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
191 return val
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
192 elif self.name() == "pickle":
578
a0ecb2c68208 Extended the stream reader base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 577
diff changeset
193 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
194 if encoding != "base64":
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
195 self.raiseError(QCoreApplication.translate(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
196 "XMLStreamReaderBase",
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
197 "Pickle data encoding '{0}' is not"
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
198 " supported.").format(encoding))
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
199 continue
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
200 b64 = self.readElementText()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
201 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
202 val = pickle.loads(pic)
574
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 else:
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 self._skipUnknownElement()
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 except ValueError as err:
c45f896e4c66 Started implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 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
207 continue
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
208
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
209 if self.isEndElement():
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
210 if self.name() in [
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
211 "tuple", "list", "dict", "set", "frozenset"]:
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
212 return None
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
213 else:
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
214 return val
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
215
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
216 def __readTuple(self):
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
217 """
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
218 Private method to read a Python tuple.
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
219
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
220 @return Python tuple
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
221 """
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
222 li = []
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
223 while not self.atEnd():
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
224 val = self._readBasics()
576
ad8fdac5aff5 Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 575
diff changeset
225 if self.isEndElement() and self.name() == "tuple" and val is None:
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
226 return tuple(li)
575
5a008db344ea Continued implementing the XMLStreamReaderBase class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 574
diff changeset
227 else:
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
228 li.append(val)
577
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 __readList(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 list.
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 list
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
235 """
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
236 li = []
577
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 val = self._readBasics()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
239 if self.isEndElement() and self.name() == "list" and val is None:
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
240 return li
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
241 else:
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
242 li.append(val)
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
243
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
244 def __readDict(self):
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
245 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
246 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
247
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
248 @return Python dictionary
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 d = {}
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
251 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
252 self.readNext()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
253 if self.isStartElement():
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
254 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
255 key = self._readBasics()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
256 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
257 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
258 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
259 self.readNext()
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
260
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
261 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
262 return d
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 __readSet(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 """
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
270 li = []
577
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() == "set" and val is None:
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
274 return set(li)
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
275 else:
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
276 li.append(val)
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
277
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
278 def __readFrozenset(self):
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
279 """
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
280 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
281
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
282 @return Python set
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
283 """
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
284 li = []
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
285 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
286 val = self._readBasics()
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
287 if self.isEndElement() and \
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
288 self.name() == "frozenset" and \
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
289 val is None:
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
290 return frozenset(li)
577
ef42a81128ca Finished the XML stream reader for basic Python data types.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 576
diff changeset
291 else:
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
292 li.append(val)

eric ide

mercurial