E4XML/XMLHandlerBase.py

changeset 42
23b45a742e17
parent 15
f6ccc31d6e72
child 44
fe5cd20cb0eb
equal deleted inserted replaced
41:572a009369f0 42:23b45a742e17
21 """ 21 """
22 Constructor 22 Constructor
23 """ 23 """
24 self.startDocumentSpecific = None 24 self.startDocumentSpecific = None
25 25
26 # TODO: add support for bytes, bytearray, set, frozenset
26 self.elements = { 27 self.elements = {
27 'none' : (self.defaultStartElement, self.endNone), 28 'none' : (self.defaultStartElement, self.endNone),
28 'int' : (self.defaultStartElement, self.endInt), 29 'int' : (self.defaultStartElement, self.endInt),
29 'long' : (self.defaultStartElement, self.endLong),
30 'float' : (self.defaultStartElement, self.endFloat), 30 'float' : (self.defaultStartElement, self.endFloat),
31 'complex' : (self.defaultStartElement, self.endComplex), 31 'complex' : (self.defaultStartElement, self.endComplex),
32 'bool' : (self.defaultStartElement, self.endBool), 32 'bool' : (self.defaultStartElement, self.endBool),
33 'string' : (self.defaultStartElement, self.endString), 33 'string' : (self.defaultStartElement, self.endString),
34 'unicode' : (self.defaultStartElement, self.endUnicode),
35 'tuple' : (self.startTuple, self.endTuple), 34 'tuple' : (self.startTuple, self.endTuple),
36 'list' : (self.startList, self.endList), 35 'list' : (self.startList, self.endList),
37 'dict' : (self.startDictionary, self.endDictionary), 36 'dict' : (self.startDictionary, self.endDictionary),
38 'pickle' : (self.startPickle, self.endPickle), 37 'pickle' : (self.startPickle, self.endPickle),
38 # for backward compatibility
39 'long' : (self.defaultStartElement, self.endInt),
40 'unicode' : (self.defaultStartElement, self.endString),
39 } 41 }
40 42
41 self.buffer = "" 43 self.buffer = ""
42 self.stack = [] 44 self.stack = []
43 self._marker = '__MARKER__' 45 self._marker = '__MARKER__'
150 """ 152 """
151 Handler method for the "int" end tag. 153 Handler method for the "int" end tag.
152 """ 154 """
153 self.stack.append(int(self.buffer.strip())) 155 self.stack.append(int(self.buffer.strip()))
154 156
155 def endLong(self):
156 """
157 Handler method for the "long" end tag.
158 """
159 self.stack.append(int(self.buffer.strip()))
160
161 def endBool(self): 157 def endBool(self):
162 """ 158 """
163 Handler method for the "bool" end tag. 159 Handler method for the "bool" end tag.
164 """ 160 """
165 if self.buffer.strip() == "True": 161 if self.buffer.strip() == "True":
185 Handler method for the "string" end tag. 181 Handler method for the "string" end tag.
186 """ 182 """
187 s = str(self.utf8_to_code(self.unescape(self.buffer))) 183 s = str(self.utf8_to_code(self.unescape(self.buffer)))
188 self.stack.append(s) 184 self.stack.append(s)
189 185
190 def endUnicode(self): 186 ## def endUnicode(self):
191 """ 187 ## """
192 Handler method for the "unicode" end tag. 188 ## Handler method for the "unicode" end tag.
193 """ 189 ## """
194 u = str(self.utf8_to_code(self.unescape(self.buffer))) 190 ## u = str(self.utf8_to_code(self.unescape(self.buffer)))
195 self.stack.append(u) 191 ## self.stack.append(u)
196 192 ##
197 def startList(self, attrs): 193 def startList(self, attrs):
198 """ 194 """
199 Handler method for the "list" start tag. 195 Handler method for the "list" start tag.
200 196
201 @param attrs list of tag attributes 197 @param attrs list of tag attributes

eric ide

mercurial