E5XML/XMLWriterBase.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 412
569efd7f2716
permissions
-rw-r--r--

Implemented the plug-in repository reader.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
13
1af94a91f439 Changed copyright for 2010.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 12
diff changeset
3 # Copyright (c) 2004 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
7 Module implementing a base class for all of eric5s XML writers.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
10 import pickle
45
9a18f4dbb493 Did a lot of encoding related stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 44
diff changeset
11 import base64
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 class XMLWriterBase(object):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 """
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
15 Class implementing a base class for all of eric5s XML writers.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 def __init__(self, file):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @param file open file (like) object for writing
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 self.pf = file
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 self.basics = {
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
26 type(None) : self._write_none,
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
27 int : self._write_int,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
28 float : self._write_float,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
29 complex : self._write_complex,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
30 bool : self._write_bool,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
31 str : self._write_string,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
32 bytes : self._write_bytes,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
33 bytearray : self._write_bytearray,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
34 tuple : self._write_tuple,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
35 list : self._write_list,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
36 dict : self._write_dictionary,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
37 set : self._write_set,
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
38 frozenset : self._write_frozenset,
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 }
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
41 self.NEWPARA = chr(0x2029)
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
42 self.NEWLINE = chr(0x2028)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 def _write(self, s, newline = True):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 Protected method used to do the real write operation.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @param s string to be written to the XML file
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @param newline flag indicating a linebreak
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
51 self.pf.write("{0}{1}".format(s,
245
de5c4effc747 Fixed some issues related to Python's universal newline support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 110
diff changeset
52 newline and "\n" or ""))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def writeXML(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Public method to write the XML to the file.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 # write the XML header
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self._write('<?xml version="1.0" encoding="UTF-8"?>')
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 def escape(self, data, attribute=False):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 Function to escape &, <, and > in a string of data.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @param data data to be escaped (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 @param attribute flag indicating escaping is done for an attribute
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 @return the escaped data (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 # must do ampersand first
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 data = data.replace("&", "&amp;")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 data = data.replace(">", "&gt;")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 data = data.replace("<", "&lt;")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 if attribute:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 data = data.replace('"', "&quot;")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 return data
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 def encodedNewLines(self, text):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 Public method to encode newlines and paragraph breaks.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
110
c9a969db1469 Fixed doc string still containing QString and QStringList.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 50
diff changeset
82 @param text text to encode (string)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 return text.replace("\n\n", self.NEWPARA).replace("\n", self.NEWLINE)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 def _writeBasics(self, pyobject, indent = 0):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 Protected method to dump an object of a basic Python type.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 @param pyobject object to be dumped
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 writeMethod = self.basics.get(type(pyobject)) or self._write_unimplemented
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 writeMethod(pyobject, indent)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 ############################################################################
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 ## The various writer methods for basic types
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 ############################################################################
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 def _write_none(self, value, indent):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 Protected method to dump a NoneType object.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 @param value value to be dumped (None) (ignored)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
107 self._write('{0}<none />'.format(" " * indent))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 def _write_int(self, value, indent):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
111 Protected method to dump an int object.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @param value value to be dumped (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
116 self._write('{0}<int>{1}</int>'.format(" " * indent, value))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 def _write_bool(self, value, indent):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
120 Protected method to dump a bool object.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 @param value value to be dumped (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
125 self._write('{0}<bool>{1}</bool>'.format(" " * indent, value))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 def _write_float(self, value, indent):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 """
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
129 Protected method to dump a float object.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 @param value value to be dumped (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
134 self._write('{0}<float>{1}</float>'.format(" " * indent, value))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 def _write_complex(self, value, indent):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 """
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
138 Protected method to dump a complex object.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 @param value value to be dumped (complex)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
143 self._write('{0}<complex>{1} {2}</complex>'.format(
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
144 " " * indent, value.real, value.imag))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 def _write_string(self, value, indent):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
148 Protected method to dump a str object.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 @param value value to be dumped (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
153 self._write('{0}<string>{1}</string>'.format(" " * indent, self.escape(value)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
155 def _write_bytes(self, value, indent):
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
156 """
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
157 Protected method to dump a bytes object.
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
158
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
159 @param value value to be dumped (bytes)
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
160 @param indent indentation level for prettier output (integer)
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
161 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
162 self._write('{0}<bytes>{1}</bytes>'.format(
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
163 " " * indent, ",".join(["{0:d}".format(b) for b in value])))
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
164
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
165 def _write_bytearray(self, value, indent):
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
166 """
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
167 Protected method to dump a bytearray object.
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
168
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
169 @param value value to be dumped (bytearray)
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
170 @param indent indentation level for prettier output (integer)
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
171 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
172 self._write('{0}<bytearray>{1}</bytearray>'.format(
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
173 " " * indent, ",".join(["{0:d}".format(b) for b in value])))
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
174
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 def _write_tuple(self, value, indent):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
177 Protected method to dump a tuple object.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 @param value value to be dumped (tuple)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
182 self._write('{0}<tuple>'.format(" " * indent))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 nindent = indent + 1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 for elem in value:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 self._writeBasics(elem, nindent)
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
186 self._write('{0}</tuple>'.format(" " * indent))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 def _write_list(self, value, indent):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 """
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
190 Protected method to dump a list object.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 @param value value to be dumped (list)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
195 self._write('{0}<list>'.format(" " * indent))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 nindent = indent + 1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 for elem in value:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 self._writeBasics(elem, nindent)
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
199 self._write('{0}</list>'.format(" " * indent))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 def _write_dictionary(self, value, indent):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 """
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
203 Protected method to dump a dict object.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 @param value value to be dumped (dictionary)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
208 self._write('{0}<dict>'.format(" " * indent))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 nindent1 = indent + 1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 nindent2 = indent + 2
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
211 keys = sorted(list(value.keys()))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 for key in keys:
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
213 self._write('{0}<key>'.format(" " * nindent1))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self._writeBasics(key, nindent2)
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
215 self._write('{0}</key>'.format(" " * nindent1))
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
216 self._write('{0}<value>'.format(" " * nindent1))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 self._writeBasics(value[key], nindent2)
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
218 self._write('{0}</value>'.format(" " * nindent1))
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
219 self._write('{0}</dict>'.format(" " * indent))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
221 def _write_set(self, value, indent):
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
222 """
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
223 Protected method to dump a set object.
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
224
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
225 @param value value to be dumped (set)
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
226 @param indent indentation level for prettier output (integer)
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
227 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
228 self._write('{0}<set>'.format(" " * indent))
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
229 nindent = indent + 1
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
230 for elem in value:
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
231 self._writeBasics(elem, nindent)
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
232 self._write('{0}</set>'.format(" " * indent))
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
233
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
234 def _write_frozenset(self, value, indent):
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
235 """
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
236 Protected method to dump a frozenset object.
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
237
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
238 @param value value to be dumped (frozenset)
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
239 @param indent indentation level for prettier output (integer)
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
240 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
241 self._write('{0}<frozenset>'.format(" " * indent))
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
242 nindent = indent + 1
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
243 for elem in value:
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
244 self._writeBasics(elem, nindent)
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
245 self._write('{0}</frozenset>'.format(" " * indent))
44
fe5cd20cb0eb Added new Python3 types to XMLWriterBase and XMLHandlerBase.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
246
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 def _write_unimplemented(self, value, indent):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 Protected method to dump a type, that has no special method.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 @param value value to be dumped (any pickleable object)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 @param indent indentation level for prettier output (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 """
412
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
254 self._write('{0}<pickle method="pickle" encoding="base64">{1}</pickle>'.format(
569efd7f2716 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
255 " " * indent, str(base64.b64encode(pickle.dumps(value)), "ASCII")))

eric ide

mercurial