Skip to content

Commit

Permalink
Work around Python/C JSON unicode differences
Browse files Browse the repository at this point in the history
The OVS C-based JSON parser operates on bytes, so the parser_feed
function returns the number of bytes that are processed. The pure
Python JSON parser currently operates on unicode, so it expects
that Parser.feed() returns a number of characters. This difference
leads to parsing errors when unicode characters are passed to the
C JSON parser from Python.

Signed-off-by: Terry Wilson <twilson@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
  • Loading branch information
otherwiseguy authored and blp committed Oct 11, 2018
1 parent a7be68a commit 4617d1f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python/ovs/jsonrpc.py
Expand Up @@ -272,7 +272,8 @@ def recv(self):
# data, so we convert it here as soon as possible.
if data and not error:
try:
data = decoder.decode(data)
if six.PY3 or ovs.json.PARSER == ovs.json.PARSER_PY:
data = decoder.decode(data)
except UnicodeError:
error = errno.EILSEQ
if error:
Expand All @@ -298,7 +299,11 @@ def recv(self):
else:
if self.parser is None:
self.parser = ovs.json.Parser()
self.input = self.input[self.parser.feed(self.input):]
if six.PY3 and ovs.json.PARSER == ovs.json.PARSER_C:
self.input = self.input.encode('utf-8')[
self.parser.feed(self.input):].decode()
else:
self.input = self.input[self.parser.feed(self.input):]
if self.parser.is_done():
msg = self.__process_msg()
if msg:
Expand Down

0 comments on commit 4617d1f

Please sign in to comment.