diff options
author | John Koehl <jkoehl@gmail.com> | 2018-01-28 02:21:05 -0500 |
---|---|---|
committer | Omer Katz <omer.drow@gmail.com> | 2018-01-28 09:21:05 +0200 |
commit | 39e733c14347f982e38e27c9f9edd7c400798e69 (patch) | |
tree | df1094c8c2cd9c17b34c6cb433a007680cf42873 /kombu/utils | |
parent | c13d91634daaf138586dd37f6123d6aeb15f4aa5 (diff) | |
download | kombu-39e733c14347f982e38e27c9f9edd7c400798e69.tar.gz |
Fixes #791 - SQS queue name gets mangled in Python 2.7 environment (#794)
* Fixes #791
* Changing to recommended patch by @georgepsarakis
* Revert "Fixes #791"
This reverts commit 5593505dd9deea5d0089d03cddfb3728f09a2048.
* Updated to make tests pass
* Made _ensure_str a private function
* Code formatting for flake8
* Added a mock of the newstr and newbytes classes to create a failing test that simulates the issue with using python-future under 2.7.
Diffstat (limited to 'kombu/utils')
-rw-r--r-- | kombu/utils/encoding.py | 9 |
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( |