From 09b01ac93bcf68a9ac6fb3454e50b73afb390848 Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Tue, 17 Dec 2013 22:44:14 +0100 Subject: [PATCH] Sync strutils from oslo Sync strutils from oslo which fix safe_encode under py3, this gets keystone CLI to properly output results. 84d461 Fix a bug in safe_encode where it returns a bytes object in py3 Closes-Bug: 1260824 Change-Id: Idf0f3a51f5cfe3077395b53da66a12955449861f --- keystoneclient/openstack/common/strutils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/keystoneclient/openstack/common/strutils.py b/keystoneclient/openstack/common/strutils.py index be238d521..8630aa8fd 100644 --- a/keystoneclient/openstack/common/strutils.py +++ b/keystoneclient/openstack/common/strutils.py @@ -152,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