summaryrefslogtreecommitdiff
path: root/kombu/utils
diff options
context:
space:
mode:
Diffstat (limited to 'kombu/utils')
-rw-r--r--kombu/utils/encoding.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/kombu/utils/encoding.py b/kombu/utils/encoding.py
index 21b6d903..b1ddeeb3 100644
--- a/kombu/utils/encoding.py
+++ b/kombu/utils/encoding.py
@@ -122,11 +122,18 @@ if is_py3k: # pragma: no cover
return '<Unrepresentable {0!r}: {1!r} {2!r}>'.format(
type(s), exc, '\n'.join(traceback.format_stack()))
else:
+ def _ensure_str(s, encoding, errors):
+ if isinstance(s, bytes):
+ return s.decode(encoding, errors)
+ return s
+
+
def _safe_str(s, errors='replace', file=None): # noqa
encoding = default_encoding(file)
try:
if isinstance(s, unicode):
- return s.encode(encoding, errors)
+ return _ensure_str(s.encode(encoding, errors),
+ encoding, errors)
return unicode(s, encoding, errors)
except Exception as exc:
return '<Unrepresentable {0!r}: {1!r} {2!r}>'.format(