diff options
author | Ben Pfaff <blp@nicira.com> | 2011-07-01 10:11:30 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2011-07-06 09:00:51 -0700 |
commit | 070de9bd4137b78b1a74e287fea475ac7aa39bf6 (patch) | |
tree | 1c13e7c40c729af0f60a1f0b3a471e4e2bec7fe1 /python/ovs/json.py | |
parent | 391614125ff1adc3cc157124480a50008b8a7801 (diff) |
python: Make invalid UTF-8 sequence messages consistent across Python versions.
Given the invalid input <C0 22>, some versions of Python report <C0> as the
invalid sequence and other versions report <C0 22> as the invalid sequence.
Similarly, given input <ED 80 7F>, some report <ED 80> and others report
<ED 80 7F> 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 <C0 22> and <ED 80 7F> on Ubuntu
10.04 with python version 2.6.5-0ubuntu1, but undoubtedly it exists
elsewhere also.
Diffstat (limited to 'python/ovs/json.py')
-rw-r--r-- | python/ovs/json.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/python/ovs/json.py b/python/ovs/json.py index f8b02d18..67470fcb 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) |