From 88eb5845b77fa06a12c096706093329f82dba54c Mon Sep 17 00:00:00 2001 From: Cedric Brandily Date: Tue, 6 Oct 2015 22:22:09 +0200 Subject: [PATCH] Ensure to decode bytes or fail The commit fcf289797c063088f9003359dfd1c7d4f41ed5ef introduces the pattern: if isinstance(line, bytes): try: line = line.decode(encoding='utf-8') except UnicodeError: pass # concat line with a string which is not working in PY3K if an UnicodeError is raised because line is not decoded and concatened to a string. This change delegates decoding to safe_decode[1] which returns a text object or raises an error. [1] oslo_utils.encodeutils Closes-Bug: #1503415 Related-Bug: #1499004 Change-Id: I16b8013f33aa3efad65be8040d3210120e047bbd --- neutronclient/tests/unit/test_cli20.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/neutronclient/tests/unit/test_cli20.py b/neutronclient/tests/unit/test_cli20.py index 240d8c911..0ceca4a16 100644 --- a/neutronclient/tests/unit/test_cli20.py +++ b/neutronclient/tests/unit/test_cli20.py @@ -73,13 +73,7 @@ class FakeStdout(object): def make_string(self): result = '' for line in self.content: - if six.PY3: - if isinstance(line, bytes): - try: - line = line.decode(encoding='utf-8') - except UnicodeError: - pass - result = result + line + result += encodeutils.safe_decode(line, 'utf-8') return result