Sync strutils from oslo

Sync strutils from oslo which fix safe_encode under py3, this gets
heat CLI to not output in bytes.

(there is a bit more to be done for complete py3 support)

84d461 Fix a bug in safe_encode where it returns a bytes object in py3

Change-Id: Ic29c0037bfbc612e954045c95edca68f273c4a1a
This commit is contained in:
Chmouel Boudjnah 2014-01-16 00:19:15 -08:00
parent 97d945e879
commit c3f389e92a
1 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,3 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 OpenStack Foundation.
# All Rights Reserved.
#
@ -154,11 +152,17 @@ def safe_encode(text, incoming=None,
sys.getdefaultencoding())
if isinstance(text, six.text_type):
return text.encode(encoding, errors)
if six.PY3:
return text.encode(encoding, errors).decode(incoming)
else:
return text.encode(encoding, errors)
elif text and encoding != incoming:
# Decode text before encoding it with `encoding`
text = safe_decode(text, incoming, errors)
return text.encode(encoding, errors)
if six.PY3:
return text.encode(encoding, errors).decode(incoming)
else:
return text.encode(encoding, errors)
return text