Set unicode_errors handler to 'surrogateescape' in msgpack
External calls may return non-unicode data which cannot be encoded, eg: '\udc82'. As a result, we need to set a handler for unicode_errors. Change-Id: I8d913c12cc78b69957a750323cf229bc648c8927 Closes-Bug: 1806842
This commit is contained in:
parent
fc056e38c1
commit
966cace7aa
|
@ -51,7 +51,8 @@ class Serializer(object):
|
|||
self.writesock = writesock
|
||||
|
||||
def send(self, msg):
|
||||
buf = msgpack.packb(msg, use_bin_type=True)
|
||||
buf = msgpack.packb(msg, use_bin_type=True,
|
||||
unicode_errors='surrogateescape')
|
||||
self.writesock.sendall(buf)
|
||||
|
||||
def close(self):
|
||||
|
@ -64,7 +65,8 @@ class Serializer(object):
|
|||
class Deserializer(six.Iterator):
|
||||
def __init__(self, readsock):
|
||||
self.readsock = readsock
|
||||
self.unpacker = msgpack.Unpacker(use_list=False, encoding='utf-8')
|
||||
self.unpacker = msgpack.Unpacker(use_list=False, encoding='utf-8',
|
||||
unicode_errors='surrogateescape')
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
|
|
@ -72,7 +72,7 @@ class TestSerialization(base.BaseTestCase):
|
|||
self.assertSendable(data)
|
||||
|
||||
def test_unicode(self):
|
||||
data = u'\u4e09\u9df9'
|
||||
data = u'\u4e09\u9df9\udc82'
|
||||
self.assertSendable(data)
|
||||
|
||||
def test_tuple(self):
|
||||
|
|
Loading…
Reference in New Issue