2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-27 15:18:06 +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:
Lance Richardson
2017-08-09 15:38:43 -04:00
committed by Russell Bryant
parent f88ee3a599
commit e7164d96bc
5 changed files with 30 additions and 7 deletions

View File

@@ -29,8 +29,13 @@ except ImportError:
__pychecker__ = 'no-stringiter'
SPACES_PER_LEVEL = 2
dumper = functools.partial(json.dumps, separators=(",", ":"),
ensure_ascii=False)
_dumper = functools.partial(json.dumps, separators=(",", ":"))
if six.PY2:
def dumper(*args, **kwargs):
return _dumper(*args, **kwargs).decode('raw-unicode-escape')
else:
dumper = _dumper
def to_stream(obj, stream, pretty=False, sort_keys=True):