eric6/E5XML/XMLStreamWriterBase.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7780
41420f82c0ac
child 8218
7c09585bd960
permissions
-rw-r--r--

Updated copyright for 2021.

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

eric ide

mercurial