summaryrefslogtreecommitdiff
path: root/pymemcache/client
diff options
context:
space:
mode:
authorJoe Gordon <jogo@pinterest.com>2018-09-06 17:08:04 -0700
committerJoe Gordon <jogo@pinterest.com>2018-09-06 17:38:30 -0700
commit9ed0caa19ac3843c3449e2d4603bc0ec9327b2a1 (patch)
treeed9a1c696905741dd788d2d5c0eb30fd86e4dd87 /pymemcache/client
parentb80eb74ba6878fed12a543a4dbdd4154cfdc0c06 (diff)
downloadpymemcache-9ed0caa19ac3843c3449e2d4603bc0ec9327b2a1.tar.gz
Fix support newbytes from future
Previously python2 code using python-future to backport the py3 bytes behavior would trigger the following exception: code: from builtins import bytes as newbytes from pymemcache.client.base import Client client = Client(('localhost', 11211)) client.set(newbytes('key'), 'value') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/site-packages/pymemcache/client/base.py", line 297, in set return self._store_cmd(b'set', key, expire, noreply, value) File "/usr/local/lib/python2.7/site-packages/pymemcache/client/base.py", line 770, in _store_cmd key = self.check_key(key) File "/usr/local/lib/python2.7/site-packages/pymemcache/client/base.py", line 251, in check_key key_prefix=self.key_prefix) File "/usr/local/lib/python2.7/site-packages/pymemcache/client/base.py", line 91, in _check_key key = key.encode('ascii') File "/usr/local/lib/python2.7/site-packages/future/types/newbytes.py", line 381, in __getattribute__ raise AttributeError("encode method has been disabled in newbytes") AttributeError: encode method has been disabled in newbytes Add a test case for this and fix.
Diffstat (limited to 'pymemcache/client')
-rw-r--r--pymemcache/client/base.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/pymemcache/client/base.py b/pymemcache/client/base.py
index 6e9de0f..846adda 100644
--- a/pymemcache/client/base.py
+++ b/pymemcache/client/base.py
@@ -88,7 +88,10 @@ def _check_key(key, allow_unicode_keys, key_prefix=b''):
key = key.encode('utf8')
elif isinstance(key, VALID_STRING_TYPES):
try:
- key = key.encode('ascii')
+ if isinstance(key, bytes):
+ key = key.decode().encode('ascii')
+ else:
+ key = key.encode('ascii')
except (UnicodeEncodeError, UnicodeDecodeError):
raise MemcacheIllegalInputError("Non-ASCII key: '%r'" % key)