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 |
|
27 self.elements = { |
26 self.elements = { |
28 'none' : (self.defaultStartElement, self.endNone), |
27 'none' : (self.defaultStartElement, self.endNone), |
29 'int' : (self.defaultStartElement, self.endInt), |
28 'int' : (self.defaultStartElement, self.endInt), |
30 'float' : (self.defaultStartElement, self.endFloat), |
29 'float' : (self.defaultStartElement, self.endFloat), |
31 'complex' : (self.defaultStartElement, self.endComplex), |
30 'complex' : (self.defaultStartElement, self.endComplex), |
49 self._marker = '__MARKER__' |
48 self._marker = '__MARKER__' |
50 |
49 |
51 self.NEWPARA = chr(0x2029) |
50 self.NEWPARA = chr(0x2029) |
52 self.NEWLINE = chr(0x2028) |
51 self.NEWLINE = chr(0x2028) |
53 |
52 |
54 def utf8_to_code(self, text): |
|
55 """ |
|
56 Public method to convert a string to unicode and encode it for XML. |
|
57 |
|
58 @param text the text to encode (string) |
|
59 """ |
|
60 # TODO: convert calls to this method to not use it anymore |
|
61 ## if not isinstance(text, UnicodeType): |
|
62 ## text = str(text, "utf-8") |
|
63 return text |
|
64 |
|
65 def unescape(self, text, attribute = False): |
53 def unescape(self, text, attribute = False): |
66 """ |
54 """ |
67 Public method used to unescape certain characters. |
55 Public method used to unescape certain characters. |
68 |
56 |
69 @param text the text to unescape (string) |
57 @param text the text to unescape (string) |
198 """ |
186 """ |
199 Handler method for the "bytearray" end tag. |
187 Handler method for the "bytearray" end tag. |
200 """ |
188 """ |
201 by = bytearray([int(b) for b in self.buffer.strip().split(",")]) |
189 by = bytearray([int(b) for b in self.buffer.strip().split(",")]) |
202 self.stack.append(by) |
190 self.stack.append(by) |
203 ## def endUnicode(self): |
191 |
204 ## """ |
|
205 ## Handler method for the "unicode" end tag. |
|
206 ## """ |
|
207 ## u = str(self.utf8_to_code(self.unescape(self.buffer))) |
|
208 ## self.stack.append(u) |
|
209 ## |
|
210 def startList(self, attrs): |
192 def startList(self, attrs): |
211 """ |
193 """ |
212 Handler method for the "list" start tag. |
194 Handler method for the "list" start tag. |
213 |
195 |
214 @param attrs list of tag attributes |
196 @param attrs list of tag attributes |