mirror of
https://github.com/openvswitch/ovs
synced 2025-10-17 14:28:02 +00:00
python: make python idl unicode-tolerant
Ensure that JSON is utf-8 encoded and that bytes sent/received on the stream sockets are in utf-8 form. Add a test case to verify that unicode data can be sent/received successfully using Python IDL module. Co-authored-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Lance Richardson <lrichard@redhat.com> Signed-off-by: Russell Bryant <russell@ovn.org>
This commit is contained in:
committed by
Russell Bryant
parent
f88ee3a599
commit
e7164d96bc
@@ -386,8 +386,10 @@ class Stream(object):
|
||||
try:
|
||||
# Python 3 has separate types for strings and bytes. We must have
|
||||
# bytes here.
|
||||
if six.PY3 and not isinstance(buf, six.binary_type):
|
||||
buf = six.binary_type(buf, 'utf-8')
|
||||
if six.PY3 and not isinstance(buf, bytes):
|
||||
buf = bytes(buf, 'utf-8')
|
||||
elif six.PY2:
|
||||
buf = buf.encode('utf-8')
|
||||
return self.socket.send(buf)
|
||||
except socket.error as e:
|
||||
return -ovs.socket_util.get_exception_errno(e)
|
||||
|
Reference in New Issue
Block a user