From: Ben Pfaff Date: Fri, 1 Jul 2011 17:11:30 +0000 (-0700) Subject: python: Make invalid UTF-8 sequence messages consistent across Python versions. X-Git-Tag: v1.1.2~4 X-Git-Url: http://git.onelab.eu/?p=sliver-openvswitch.git;a=commitdiff_plain;h=7b3855c50706c6f5805f6b320508ecf9b22cd3b7 python: Make invalid UTF-8 sequence messages consistent across Python versions. Given the invalid input , some versions of Python report as the invalid sequence and other versions report as the invalid sequence. Similarly, given input , some report and others report as the invalid sequence. This caused spurious test failures for the test "no invalid UTF-8 sequences in strings - Python", so this commit makes the messages consistent by dropping the extra trailing byte from the message. I first noticed the longer sequences and on Ubuntu 10.04 with python version 2.6.5-0ubuntu1, but undoubtedly it exists elsewhere also. --- diff --git a/python/ovs/json.py b/python/ovs/json.py index f8b02d180..67470fcbc 100644 --- a/python/ovs/json.py +++ b/python/ovs/json.py @@ -113,7 +113,8 @@ def from_string(s): try: s = unicode(s, 'utf-8') except UnicodeDecodeError, e: - seq = ' '.join(["0x%2x" % ord(c) for c in e.object[e.start:e.end]]) + seq = ' '.join(["0x%2x" % ord(c) + for c in e.object[e.start:e.end] if ord(c) >= 0x80]) return ("not a valid UTF-8 string: invalid UTF-8 sequence %s" % seq) p = Parser(check_trailer=True) p.feed(s)