Commit 6f4488a5 authored by Julien Muchembled's avatar Julien Muchembled

xml_marshaller: fix dump of bytes with Python 2 and update tests

parent 3e793e44
...@@ -29,10 +29,10 @@ For simple serialisation and unserialisation:: ...@@ -29,10 +29,10 @@ For simple serialisation and unserialisation::
>>> from xml_marshaller import xml_marshaller >>> from xml_marshaller import xml_marshaller
>>> xml_marshaller.dumps(['item1', {'key1': 1, 'key2': u'unicode string'}]) >>> xml_marshaller.dumps(['item1', {'key1': 1, 'key2': 'string'}])
'<marshal><list id="i2"><string>item1</string><dictionary id="i3"><string>key1</string><int>1</int><string>key2</string><unicode>unicode string</unicode></dictionary></list></marshal>' '<marshal><list id="i2"><string>item1</string><dictionary id="i3"><string>key1</string><int>1</int><string>key2</string><string>string</string></dictionary></list></marshal>'
>>> xml_marshaller.loads(xml_marshaller.dumps(['item1', {'key1': 1, 'key2': u'unicode string'}])) >>> xml_marshaller.loads(xml_marshaller.dumps(['item1', {'key1': 1, 'key2': 'string'}]))
['item1', {'key2': u'unicode string', 'key1': 1}] ['item1', {'key2': 'string', 'key1': 1}]
Can works with file like objects:: Can works with file like objects::
......
...@@ -60,7 +60,7 @@ class TestXMLMarhsaller(unittest.TestCase): ...@@ -60,7 +60,7 @@ class TestXMLMarhsaller(unittest.TestCase):
['alpha', 'beta', 'gamma', [None, 1, 1<<123, 19.72, ['alpha', 'beta', 'gamma', [None, 1, 1<<123, 19.72,
1+5j, "& a <fake tag>"]], 1+5j, "& a <fake tag>"]],
{'key': 'value', 1: 2}, {'key': 'value', 1: 2},
u'éàù^ç', 'éàù^ç',
{'a', 1}, {'a', 1},
True, True,
False, False,
...@@ -83,7 +83,7 @@ class TestXMLMarhsaller(unittest.TestCase): ...@@ -83,7 +83,7 @@ class TestXMLMarhsaller(unittest.TestCase):
['alpha', 'beta', 'gamma', [None, 1, 1<<123, 19.72, ['alpha', 'beta', 'gamma', [None, 1, 1<<123, 19.72,
1+5j, "& a <fake tag>"]], 1+5j, "& a <fake tag>"]],
{'key': 'value', 1: 2}, {'key': 'value', 1: 2},
u'éàù^ç', 'éàù^ç',
{'a', 1}, {'a', 1},
True, True,
False, False,
......
...@@ -161,7 +161,9 @@ class Marshaller(object): ...@@ -161,7 +161,9 @@ class Marshaller(object):
def m_bytes(self, value, kw): def m_bytes(self, value, kw):
return self.m_string(value.decode('utf-8'), kw) return self.m_string(value.decode('utf-8'), kw)
m_unicode = m_str if str is bytes:
m_unicode = m_str
m_str = m_bytes
def m_int(self, value, kw): def m_int(self, value, kw):
return (self.tag_int if -1e24 < value < 1e24 else return (self.tag_int if -1e24 < value < 1e24 else
......
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