Commit 830cb13b authored by Nicolas Delaby's avatar Nicolas Delaby

Support boolean transformation

parent 7865e237
......@@ -58,6 +58,7 @@ class Marshaller(object):
self.tag_none = E.none
self.tag_instance = E.object
self.tag_set = E.set
self.tag_bool = E.bool
# The four basic functions that form the caller's interface
def dump(self, value, file):
......@@ -200,6 +201,9 @@ class Marshaller(object):
xml_tree.append(self._marshal(elem, kw))
return xml_tree
def m_bool(self, value, kw):
return self.tag_bool(value and '1' or '0')
# Python 2.2 renames dictionary to dict.
def m_dict(self, value, kw):
return self.m_dictionary(value, kw)
......@@ -284,6 +288,7 @@ class Unmarshaller(ElementTreeContentHandler):
'none': ('um_start_none', 'um_end_none'),
'object': ('um_start_instance', 'um_end_instance'),
'set': ('um_start_set', 'um_end_set'),
'bool': ('um_start_bool', 'um_end_bool'),
}
def __init__(self):
......@@ -428,6 +433,7 @@ class Unmarshaller(ElementTreeContentHandler):
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
um_start_bool = um_start_generic
def um_end_string(self, name):
ds = self.data_stack
......@@ -497,6 +503,11 @@ class Unmarshaller(ElementTreeContentHandler):
self.kw[id] = S
self.data_stack.append(S)
def um_end_bool(self, name):
ds = self.data_stack
ds[-1] = bool(int(''.join(ds[-1])))
self.accumulating_chars = 0
def um_end_list(self, name):
ds = self.data_stack
for index in range(len(ds)-1, -1, -1):
......@@ -644,6 +655,8 @@ def runtests(namespace_uri=None):
{'key': 'value', 1: 2},
'éàù^ç'.decode('utf-8'),
set(('a', 1,)),
True,
False
]
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