eric6/E5XML/XMLStreamWriterBase.py

Sun, 02 Feb 2020 11:04:32 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 02 Feb 2020 11:04:32 +0100
changeset 7380
c99320e859ca
parent 7360
9190402e4505
child 7628
f904d0eef264
permissions
-rw-r--r--

Fixed an issue related to showing the application name in the menu bar of Gnome desktop under Wayland.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7253
diff changeset
3 # Copyright (c) 2010 - 2020 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 """
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.
573
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
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
10
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import pickle
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import base64
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
14 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
15
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
16
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class XMLStreamWriterBase(QXmlStreamWriter):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
19 Class implementing a base class for all of eric6s XML stream writers.
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 def __init__(self, device):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Constructor
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 @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
26 """
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
27 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
28
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 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
30 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
31 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
32 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
33 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
34 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
35 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
36 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
37 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
38 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
39 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
40 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
41 frozenset: self._write_frozenset,
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
42 bytes: self._write_bytes,
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 }
2551
d51f443e21f4 Fix for saving projects.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
44
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.setAutoFormatting(True)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.setAutoFormattingIndent(2)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 def writeXML(self):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 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
51 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 # write the XML header
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.writeStartDocument()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
610
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
55 def writeBasics(self, tag, pyobject):
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
56 """
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
57 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
58
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
59 @param tag tag name (string)
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
60 @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
61 """
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
62 self.writeStartElement(tag)
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
63 self._writeBasics(pyobject)
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
64 self.writeEndElement()
3a625b0793d8 Migrated the project writer to a stream writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 605
diff changeset
65
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 def _writeBasics(self, pyobject):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 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
69
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @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
71 """
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
72 writeMethod = (
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
73 self.basics.get(type(pyobject)) or
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
74 self._write_unimplemented
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
75 )
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 writeMethod(pyobject)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
78 ###########################################################################
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 ## 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
80 ###########################################################################
573
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 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
83 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 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
85
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 @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
87 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 self.writeEmptyElement("none")
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 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
91 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 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
93
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @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
95 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 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
97
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 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
99 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 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
101
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 @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
103 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 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
105
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 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
107 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 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
109
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 @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
111 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 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
113
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 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
115 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 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
117
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @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
119 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 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
121 value.real, value.imag))
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 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
124 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 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
126
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 @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
128 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 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
130
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 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
132 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 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
134
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 @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
136 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
137 self.writeTextElement(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
138 "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
139
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 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
141 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 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
143
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 @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
145 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
146 self.writeTextElement(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
147 "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
148
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 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
150 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 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
152
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 @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
154 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 self.writeStartElement("tuple")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 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
161 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 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
163
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 @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
165 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.writeStartElement("list")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 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
172 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 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
174
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 @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
176 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 self.writeStartElement("dict")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 try:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 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
180 except TypeError:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 keys = list(value.keys())
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 for key in keys:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.writeStartElement("key")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 self._writeBasics(key)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 self.writeStartElement("value")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 self._writeBasics(value[key])
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 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
193 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 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
195
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 @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
197 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 self.writeStartElement("set")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 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
204 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 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
206
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 @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
208 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 self.writeStartElement("frozenset")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 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
215 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 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
217
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 @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
219 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 self.writeStartElement("pickle")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 self.writeAttribute("method", "pickle")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 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
223 self.writeCharacters(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
224 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
225 self.writeEndElement()

eric ide

mercurial