Ensure to decode bytes or fail

The commit fcf289797c 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
This commit is contained in:
Cedric Brandily
2015-10-06 22:22:09 +02:00
committed by Armando Migliaccio
parent ebebd90206
commit 88eb5845b7

View File

@@ -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