E5XML/XMLStreamWriterBase.py

Fri, 10 Sep 2010 08:54:33 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 10 Sep 2010 08:54:33 +0200
changeset 580
45c38566b001
parent 573
3fd49348ea83
child 605
9c7527ecbf6e
permissions
-rw-r--r--

Implemented the plug-in repository reader.

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
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de>
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
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import pickle
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
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt4.QtCore import QXmlStreamWriter
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 class XMLStreamWriterBase(QXmlStreamWriter):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 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
18 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 def __init__(self, device):
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 Constructor
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 @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
24 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 QXmlStreamWriter.__init__(self, device)
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 self.basics = {
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 type(None) : self._write_none,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 int : self._write_int,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 float : self._write_float,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 complex : self._write_complex,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 bool : self._write_bool,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 str : self._write_string,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 bytes : self._write_bytes,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 bytearray : self._write_bytearray,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 tuple : self._write_tuple,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 list : self._write_list,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 dict : self._write_dictionary,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 set : self._write_set,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 frozenset : self._write_frozenset,
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 }
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.NEWPARA = chr(0x2029)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.NEWLINE = chr(0x2028)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.setAutoFormatting(True)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.setAutoFormattingIndent(2)
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 def writeXML(self):
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 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
52 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 # write the XML header
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.writeStartDocument()
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 encodedNewLines(self, text):
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 encode newlines and paragraph breaks.
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 @param text text to encode (string)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 return text.replace("\n\n", self.NEWPARA).replace("\n", self.NEWLINE)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 def _writeBasics(self, pyobject):
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 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
67
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @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
69 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 writeMethod = self.basics.get(type(pyobject)) or self._write_unimplemented
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 writeMethod(pyobject)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 ############################################################################
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 ## The various writer methods for basic types
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
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 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
78 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 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
80
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 @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
82 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.writeEmptyElement("none")
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 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
86 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 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
88
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 @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
90 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 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
92
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 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
94 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 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
96
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 @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
98 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 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
100
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 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
102 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 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
104
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 @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
106 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 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
108
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 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
110 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 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
112
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @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
114 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 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
116 value.real, value.imag))
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 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
119 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 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
121
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 @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
123 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 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
125
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 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
127 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 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
129
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 @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
131 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.writeTextElement("bytes", ",".join(["{0:d}".format(b) for b in value]))
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 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
135 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 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
137
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 @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
139 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.writeTextElement("bytearray", ",".join(["{0:d}".format(b) for b in 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 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
143 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 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
145
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 @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
147 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 self.writeStartElement("tuple")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 self.writeEndElement()
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 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
154 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 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
156
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @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
158 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 self.writeStartElement("list")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 self.writeEndElement()
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 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
165 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 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
167
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 @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
169 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 self.writeStartElement("dict")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 try:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 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
173 except TypeError:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 keys = list(value.keys())
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 for key in keys:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 self.writeStartElement("key")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 self._writeBasics(key)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 self.writeStartElement("value")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 self._writeBasics(value[key])
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.writeEndElement()
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 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
186 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 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
188
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 @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
190 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self.writeStartElement("set")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 self.writeEndElement()
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 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
197 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 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
199
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 @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
201 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 self.writeStartElement("frozenset")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 for elem in value:
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 self._writeBasics(elem)
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 self.writeEndElement()
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 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
208 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 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
210
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 @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
212 """
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 self.writeStartElement("pickle")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self.writeAttribute("method", "pickle")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 self.writeAttribute("encoding", "base64")
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 self.writeCharacters(str(base64.b64encode(pickle.dumps(value)), "ASCII"))
3fd49348ea83 Started moving the XML handling code to QXmlStreamReader and QXmlStreamWriter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 self.writeEndElement()

eric ide

mercurial