summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Rosen <sirosen@globus.org>2019-07-24 16:24:44 -0400
committerJon Parise <jon@pinterest.com>2019-07-24 13:24:44 -0700
commit8509e8a688aa6d50ba91627ef00e7a13518a6026 (patch)
tree8d9ef061efcd7d8d6b418aee47ccc9448ef5700f
parentc42453c336fece50a123f410554df0bb55b21859 (diff)
downloadpymemcache-8509e8a688aa6d50ba91627ef00e7a13518a6026.tar.gz
Be more consistent about using Client.encoding (#242)
This is a stylistic issue with little chance for actual impact. Some methods use 'ascii' verbatim and some use `self.encoding` (which defaults to 'ascii'). Those which are using `ascii` are only supposed to be accepting integer inputs, so this is actually fine. However, the result is a potentially confusing discrepancy -- why does `Client.touch` use `ascii` while `Client.add` uses `self.encoding`? To alleviate this potential confusion, be consistent about applying `self.encoding` to all memcached commands in the base client. This does not impact the `_check_key` func, which re-encodes potential unicode inputs as ASCII.
-rw-r--r--pymemcache/client/base.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/pymemcache/client/base.py b/pymemcache/client/base.py
index ff5a8d0..66e7dc7 100644
--- a/pymemcache/client/base.py
+++ b/pymemcache/client/base.py
@@ -594,7 +594,7 @@ class Client(object):
value of the key, or None if the key wasn't found.
"""
key = self.check_key(key)
- cmd = b'incr ' + key + b' ' + six.text_type(value).encode('ascii')
+ cmd = b'incr ' + key + b' ' + six.text_type(value).encode(self.encoding)
if noreply:
cmd += b' noreply'
cmd += b'\r\n'
@@ -619,7 +619,7 @@ class Client(object):
value of the key, or None if the key wasn't found.
"""
key = self.check_key(key)
- cmd = b'decr ' + key + b' ' + six.text_type(value).encode('ascii')
+ cmd = b'decr ' + key + b' ' + six.text_type(value).encode(self.encoding)
if noreply:
cmd += b' noreply'
cmd += b'\r\n'
@@ -648,7 +648,9 @@ class Client(object):
if noreply is None:
noreply = self.default_noreply
key = self.check_key(key)
- cmd = b'touch ' + key + b' ' + six.text_type(expire).encode('ascii')
+ cmd = (
+ b'touch ' + key + b' ' + six.text_type(expire).encode(self.encoding)
+ )
if noreply:
cmd += b' noreply'
cmd += b'\r\n'
@@ -729,7 +731,7 @@ class Client(object):
"""
if noreply is None:
noreply = self.default_noreply
- cmd = b'flush_all ' + six.text_type(delay).encode('ascii')
+ cmd = b'flush_all ' + six.text_type(delay).encode(self.encoding)
if noreply:
cmd += b' noreply'
cmd += b'\r\n'