Commit d9034195 authored by Nicolas Delaby's avatar Nicolas Delaby

Add support of unicode type

parent b7a8d1d8
......@@ -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(ElementTreeContentHandler):
'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(ElementTreeContentHandler):
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(ElementTreeContentHandler):
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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment