E5XML/XMLStreamWriterBase.py

Sat, 05 Jul 2014 11:41:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 05 Jul 2014 11:41:14 +0200
changeset 3669
ac84ac3c0f05
parent 3656
441956d8fce5
child 3670
f0cb7579c0b4
permissions
-rw-r--r--

Continued renaming eric5 for PyQt5 to eric6.

573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
3 # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a base class for all of eric5s XML stream writers.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3057
diff changeset
10 from __future__ import unicode_literals
2551
d51f443e21f4 Fix for saving projects.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
11 try:
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3178
diff changeset
12 str = unicode
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3178
diff changeset
13 except NameError:
2551
d51f443e21f4 Fix for saving projects.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
14 pass
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
15
2551
d51f443e21f4 Fix for saving projects.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
16 import sys
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import pickle
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import base64
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
20 from PyQt5.QtCore import QXmlStreamWriter
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
22
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 class XMLStreamWriterBase(QXmlStreamWriter):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Class implementing a base class for all of eric5s XML stream writers.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 def __init__(self, device):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Constructor
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param device reference to the I/O device to write to (QIODevice)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
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
33 super(XMLStreamWriterBase, self).__init__(device)
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.basics = {
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
36 type(None): self._write_none,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
37 int: self._write_int,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
38 float: self._write_float,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
39 complex: self._write_complex,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
40 bool: self._write_bool,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
41 str: self._write_string,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
42 bytearray: self._write_bytearray,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
43 tuple: self._write_tuple,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
44 list: self._write_list,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
45 dict: self._write_dictionary,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
46 set: self._write_set,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
47 frozenset: self._write_frozenset,
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 }
2551
d51f443e21f4 Fix for saving projects.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
49 # 'bytes' is identical to 'str' in Py2
d51f443e21f4 Fix for saving projects.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
50 if sys.version_info[0] >= 3:
d51f443e21f4 Fix for saving projects.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
51 self.basics[bytes] = self._write_bytes
d51f443e21f4 Fix for saving projects.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
52
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.setAutoFormatting(True)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.setAutoFormattingIndent(2)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 def writeXML(self):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 Public method to write the XML to the file.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 # write the XML header
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.writeStartDocument()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
610
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
63 def writeBasics(self, tag, pyobject):
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
64 """
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
65 Public method to write a tag with a basic Python object dump.
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
66
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
67 @param tag tag name (string)
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
68 @param pyobject object to be dumped
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
69 """
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
70 self.writeStartElement(tag)
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
71 self._writeBasics(pyobject)
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
72 self.writeEndElement()
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
73
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 def _writeBasics(self, pyobject):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 Protected method to dump an object of a basic Python type.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 @param pyobject object to be dumped
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
80 writeMethod = self.basics.get(type(pyobject)) or \
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
81 self._write_unimplemented
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 writeMethod(pyobject)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
84 ###########################################################################
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 ## The various writer methods for basic types
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
86 ###########################################################################
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 def _write_none(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 Protected method to dump a NoneType object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 @param value value to be dumped (None) (ignored)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.writeEmptyElement("none")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 def _write_int(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 Protected method to dump an int object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 @param value value to be dumped (integer)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 self.writeTextElement("int", str(value))
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 def _write_bool(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 Protected method to dump a bool object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 @param value value to be dumped (boolean)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.writeTextElement("bool", str(value))
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 def _write_float(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 Protected method to dump a float object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @param value value to be dumped (float)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 self.writeTextElement("float", str(value))
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 def _write_complex(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 Protected method to dump a complex object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 @param value value to be dumped (complex)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.writeTextElement("complex", '{0} {1}'.format(
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 value.real, value.imag))
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 def _write_string(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 Protected method to dump a str object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 @param value value to be dumped (string)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 self.writeTextElement("string", str(value))
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 def _write_bytes(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 Protected method to dump a bytes object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 @param value value to be dumped (bytes)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
143 self.writeTextElement(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
144 "bytes", ",".join(["{0:d}".format(b) for b in value]))
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 def _write_bytearray(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 Protected method to dump a bytearray object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 @param value value to be dumped (bytearray)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
152 self.writeTextElement(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
153 "bytearray", ",".join(["{0:d}".format(b) for b in value]))
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 def _write_tuple(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 Protected method to dump a tuple object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 @param value value to be dumped (tuple)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.writeStartElement("tuple")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 def _write_list(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 Protected method to dump a list object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 @param value value to be dumped (list)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 self.writeStartElement("list")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 def _write_dictionary(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 Protected method to dump a dict object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 @param value value to be dumped (dictionary)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.writeStartElement("dict")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 try:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 keys = sorted(list(value.keys()))
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 except TypeError:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 keys = list(value.keys())
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 for key in keys:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 self.writeStartElement("key")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 self._writeBasics(key)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 self.writeStartElement("value")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 self._writeBasics(value[key])
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 def _write_set(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 Protected method to dump a set object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 @param value value to be dumped (set)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 self.writeStartElement("set")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 def _write_frozenset(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 Protected method to dump a frozenset object.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 @param value value to be dumped (frozenset)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 self.writeStartElement("frozenset")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 def _write_unimplemented(self, value):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 Protected method to dump a type, that has no special method.
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 @param value value to be dumped (any pickleable object)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 self.writeStartElement("pickle")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 self.writeAttribute("method", "pickle")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 self.writeAttribute("encoding", "base64")
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
229 self.writeCharacters(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
230 str(base64.b64encode(pickle.dumps(value)), "ASCII"))
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 self.writeEndElement()

eric ide

mercurial