diff options
author | Jon Parise <jon@pinterest.com> | 2021-02-04 13:55:59 -0800 |
---|---|---|
committer | Jon Parise <jon@indelible.org> | 2021-02-04 15:32:46 -0800 |
commit | b9e61f61e42e2121af731eb40ca27894d8f95e57 (patch) | |
tree | 370d146e5e521219715073f5566665c4e75ecaac | |
parent | d81526c54cad94e1b4158e04b54256abc52a449f (diff) | |
download | pymemcache-b9e61f61e42e2121af731eb40ca27894d8f95e57.tar.gz |
Move _check_cas() check into cas() method
_check_cas() does a good job of normalizing a CAS value and raising
MemcacheIllegalInputError when fed an invalid value. We were only using
this function in the `cas is not None` path within _store_cmd().
By moving this check into cas() itself, it allows us to also raise
MemcacheIllegalInputError when `cas is None`, which can happen when this
pattern is used for a new key:
val, cas = c.gets('key')
c.cas('key', 'value', cas)
-rw-r--r-- | pymemcache/client/base.py | 2 | ||||
-rw-r--r-- | pymemcache/test/test_client.py | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/pymemcache/client/base.py b/pymemcache/client/base.py index 3d790bc..2b5d3a7 100644 --- a/pymemcache/client/base.py +++ b/pymemcache/client/base.py @@ -517,6 +517,7 @@ class Client(object): the key didn't exist, False if it existed but had a different cas value and True if it existed and was changed. """ + cas = self._check_cas(cas) return self._store_cmd(b'cas', {key: value}, expire, noreply, flags=flags, cas=cas)[key] @@ -933,7 +934,6 @@ class Client(object): extra = b'' if cas is not None: - cas = self._check_cas(cas) extra += b' ' + cas if noreply: extra += b' noreply' diff --git a/pymemcache/test/test_client.py b/pymemcache/test/test_client.py index 7d99126..91655ed 100644 --- a/pymemcache/test/test_client.py +++ b/pymemcache/test/test_client.py @@ -486,6 +486,9 @@ class TestClient(ClientTestMixin, unittest.TestCase): def test_cas_malformed(self): client = self.make_client([b'STORED\r\n']) with pytest.raises(MemcacheIllegalInputError): + client.cas(b'key', b'value', None, noreply=False) + + with pytest.raises(MemcacheIllegalInputError): client.cas(b'key', b'value', 'nonintegerstring', noreply=False) with pytest.raises(MemcacheIllegalInputError): |