diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2015-05-04 12:27:45 -0400 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2015-05-04 12:27:45 -0400 |
commit | a4d6e9fd06c5fe9e38eb8cf2cd32fff75b7d24b1 (patch) | |
tree | a2a9a4ae808342ad67df92ea17094f708976d673 | |
parent | bc61eb925af5de3317937529413cca4a49c4cd3b (diff) | |
parent | 19d48d81ce3227d5f9544072c9c6915133b0f75c (diff) | |
download | redis-py-a4d6e9fd06c5fe9e38eb8cf2cd32fff75b7d24b1.tar.gz |
Merge pull request #614 from duxiaoyao/master
Connection.encode complains when value is an object having unicode characters in its printable representation
-rwxr-xr-x | redis/connection.py | 2 | ||||
-rw-r--r-- | tests/test_encoding.py | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/redis/connection.py b/redis/connection.py index 790997b..0229d28 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -588,7 +588,7 @@ class Connection(object): elif isinstance(value, float): value = b(repr(value)) elif not isinstance(value, basestring): - value = str(value) + value = unicode(value) if isinstance(value, unicode): value = value.encode(self.encoding, self.encoding_errors) return value diff --git a/tests/test_encoding.py b/tests/test_encoding.py index b1df0a5..f0c67be 100644 --- a/tests/test_encoding.py +++ b/tests/test_encoding.py @@ -23,6 +23,13 @@ class TestEncoding(object): r.rpush('a', *result) assert r.lrange('a', 0, -1) == result + def test_object_value(self, r): + unicode_string = unichr(3456) + u('abcd') + unichr(3421) + r['unicode-string'] = Exception(unicode_string) + cached_val = r['unicode-string'] + assert isinstance(cached_val, unicode) + assert unicode_string == cached_val + class TestCommandsAndTokensArentEncoded(object): @pytest.fixture() |