summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Brandily <zzelle@gmail.com>2015-10-06 22:22:09 +0200
committerAkihiro Motoki <motoki@da.jp.nec.com>2015-12-03 19:51:44 +0900
commitc5e1d2b827e16b761aa9601355fc91d969527d73 (patch)
tree817ca0cd16a172b976ffedca43e05f67e3d72eed
parentc8167991853884b37a0687970d4d721713a61a28 (diff)
downloadpython-neutronclient-c5e1d2b827e16b761aa9601355fc91d969527d73.tar.gz
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 (cherry picked from commit 88eb5845b77fa06a12c096706093329f82dba54c)
-rw-r--r--neutronclient/tests/unit/test_cli20.py8
1 files changed, 1 insertions, 7 deletions
diff --git a/neutronclient/tests/unit/test_cli20.py b/neutronclient/tests/unit/test_cli20.py
index 240d8c9..0ceca4a 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