[Erp5-report] r37203 nicolas - /erp5/trunk/utils/xml_marshaller/xml_marshaller/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Jul 20 18:51:20 CEST 2010
Author: nicolas
Date: Tue Jul 20 18:51:17 2010
New Revision: 37203
URL: http://svn.erp5.org?rev=37203&view=rev
Log:
Add support of unicode type
Modified:
erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py
Modified: erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py
URL: http://svn.erp5.org/erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py?rev=37203&r1=37202&r2=37203&view=diff
==============================================================================
--- erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py [utf8] (original)
+++ erp5/trunk/utils/xml_marshaller/xml_marshaller/xml_marshaller.py [utf8] Tue Jul 20 18:51:17 2010
@@ -48,6 +48,7 @@ class Marshaller(object):
self.tag_float = E.float
self.tag_long = E.long
self.tag_string = E.string
+ self.tag_unicode = E.unicode
self.tag_tuple = E.tuple
self.tag_list = E.list
self.tag_dictionary = E.dictionary
@@ -136,6 +137,8 @@ class Marshaller(object):
def m_string(self, value, kw):
return self.tag_string(escape(str(value)))
+ def m_unicode(self, value, kw):
+ return self.tag_unicode(value)
# Since Python 2.2, the string type has a name of 'str'
# To avoid having to rewrite all classes that implement m_string
# we delegate m_str to m_string.
@@ -259,6 +262,7 @@ class Unmarshaller(ElementTreeContentHan
'float': ('um_start_float', 'um_end_float'),
'long': ('um_start_long', 'um_end_long'),
'string': ('um_start_string', 'um_end_string'),
+ 'unicode': ('um_start_unicode', 'um_end_unicode'),
'tuple': ('um_start_tuple', 'um_end_tuple'),
'list': ('um_start_list', 'um_end_list'),
'dictionary': ('um_start_dictionary', 'um_end_dictionary'),
@@ -408,7 +412,7 @@ class Unmarshaller(ElementTreeContentHan
self.data_stack.append([])
self.accumulating_chars = 1
- um_start_float = um_start_long = um_start_string = um_start_generic
+ um_start_float = um_start_long = um_start_string = um_start_unicode = um_start_generic
um_start_complex = um_start_code = um_start_none = um_start_generic
um_start_int = um_start_generic
@@ -418,6 +422,12 @@ class Unmarshaller(ElementTreeContentHan
ds[-1] = unescape(''.join(ds[-1]))
self.accumulating_chars = 0
+ def um_end_unicode(self, name):
+ ds = self.data_stack
+ # might need to convert unicode string to byte string
+ ds[-1] = unescape(''.join(ds[-1]))
+ self.accumulating_chars = 0
+
def um_end_int(self, name):
ds = self.data_stack
ds[-1] = ''.join(ds[-1])
@@ -599,7 +609,8 @@ def runtests(namespace_uri=None):
"here is a string & a <fake tag>",
(1, 2, 3),
['alpha', 'beta', 'gamma'],
- {'key': 'value', 1: 2}
+ {'key': 'value', 1: 2},
+ 'éàù^ç'.decode('utf-8'),
]
if namespace_uri:
test(load, loads, dump_ns, dumps_ns, L)
More information about the Erp5-report
mailing list