summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Abramowitz <marc@marc-abramowitz.com>2014-03-24 21:40:56 -0700
committerMarc Abramowitz <marc@marc-abramowitz.com>2014-03-24 21:40:56 -0700
commit178a2632e29152bf03c55d0ece1323750d62a96a (patch)
treed8f25657937edb32670077ca2d1e07107049d6c8
parent0cdaad5e89fbed325ab620cff634d430ce4c0f18 (diff)
downloadpython-memcached-178a2632e29152bf03c55d0ece1323750d62a96a.tar.gz
check_key: Auto-convert unicode keys to bytes for better Python 3
compat It would be a bit of a pain (and ugly) in Python 3 to have to prefix all literal keys with the "b" literal notation for bytes.
-rw-r--r--memcache.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/memcache.py b/memcache.py
index daa3781..7326c53 100644
--- a/memcache.py
+++ b/memcache.py
@@ -1121,14 +1121,12 @@ class Client(threading.local):
key = key[1]
if not key:
raise Client.MemcachedKeyNoneError("Key is None")
- if isinstance(key, unicode):
- raise Client.MemcachedStringEncodingError(
- "Keys must be str()'s, not unicode. Convert your unicode "
- "strings using mystring.encode(charset)!")
- if not isinstance(key, str):
+ if isinstance(key, six.text_type):
+ key = key.encode('ascii')
+ if not isinstance(key, six.binary_type):
raise Client.MemcachedKeyTypeError("Key must be str()'s")
- if isinstance(key, basestring):
+ if isinstance(key, six.string_types):
if self.server_max_key_length != 0 and \
len(key) + key_extra_len > self.server_max_key_length:
raise Client.MemcachedKeyLengthError(