summaryrefslogtreecommitdiff
path: root/pymemcache
diff options
context:
space:
mode:
authorJoe Gordon <jogo@pinterest.com>2021-07-06 11:45:34 -0700
committerJoe Gordon <jogo@pinterest.com>2021-07-20 11:49:20 -0700
commit09e4c0520482beab2faba9253178e34ec459054e (patch)
tree54643b558a90513c632be5d01e692e5244ea322b /pymemcache
parent00f3dd5edbb208c17e096ae858ac9f181c1c144a (diff)
downloadpymemcache-09e4c0520482beab2faba9253178e34ec459054e.tar.gz
Fixes for rebase and further cleanups
Diffstat (limited to 'pymemcache')
-rw-r--r--pymemcache/client/base.py5
-rw-r--r--pymemcache/client/hash.py2
-rw-r--r--pymemcache/client/rendezvous.py3
-rw-r--r--pymemcache/serde.py6
-rw-r--r--pymemcache/test/test_benchmark.py4
-rw-r--r--pymemcache/test/test_client.py34
-rw-r--r--pymemcache/test/test_client_retry.py2
-rw-r--r--pymemcache/test/test_serde.py6
8 files changed, 22 insertions, 40 deletions
diff --git a/pymemcache/client/base.py b/pymemcache/client/base.py
index cf19ed6..8935947 100644
--- a/pymemcache/client/base.py
+++ b/pymemcache/client/base.py
@@ -99,10 +99,7 @@ def check_key_helper(key, allow_unicode_keys, key_prefix=b''):
key = key.encode('utf8')
elif isinstance(key, str):
try:
- if isinstance(key, bytes):
- key = key.decode().encode('ascii')
- else:
- key = key.encode('ascii')
+ key = key.encode('ascii')
except (UnicodeEncodeError, UnicodeDecodeError):
raise MemcacheIllegalInputError("Non-ASCII key: %r" % key)
diff --git a/pymemcache/client/hash.py b/pymemcache/client/hash.py
index d97f26c..82f46a8 100644
--- a/pymemcache/client/hash.py
+++ b/pymemcache/client/hash.py
@@ -344,7 +344,7 @@ class HashClient:
if not self.ignore_exc:
return succeeded, failed, e
- succeeded = [key for key in six.iterkeys(values) if key not in failed]
+ succeeded = [key for key in values if key not in failed]
return succeeded, failed, None
def close(self):
diff --git a/pymemcache/client/rendezvous.py b/pymemcache/client/rendezvous.py
index 43a78ed..00583fc 100644
--- a/pymemcache/client/rendezvous.py
+++ b/pymemcache/client/rendezvous.py
@@ -35,8 +35,7 @@ class RendezvousHash:
winner = None
for node in self.nodes:
- score = self.hash_function(
- f"{node}-{key}")
+ score = self.hash_function(f"{node}-{key}")
if score > high_score:
(high_score, winner) = (score, node)
diff --git a/pymemcache/serde.py b/pymemcache/serde.py
index 400c5c1..daa24c0 100644
--- a/pymemcache/serde.py
+++ b/pymemcache/serde.py
@@ -17,12 +17,6 @@ import logging
from io import BytesIO
import pickle
-try:
- long_type = long # noqa
-except NameError:
- long_type = None
-
-
FLAG_BYTES = 0
FLAG_PICKLE = 1 << 0
FLAG_INTEGER = 1 << 1
diff --git a/pymemcache/test/test_benchmark.py b/pymemcache/test/test_benchmark.py
index 2565fbe..408ea7b 100644
--- a/pymemcache/test/test_benchmark.py
+++ b/pymemcache/test/test_benchmark.py
@@ -78,7 +78,7 @@ def benchmark(count, func, *args, **kwargs):
@pytest.mark.benchmark()
def test_bench_get(request, client, pairs, count):
- key, value = next(pairs.items())
+ key, value = next(pairs)
client.set(key, value)
benchmark(count, client.get, key)
@@ -102,7 +102,7 @@ def test_bench_set_multi(request, client, pairs, count):
@pytest.mark.benchmark()
def test_bench_delete(request, client, pairs, count):
- benchmark(count, client.delete, next(pairs.keys()))
+ benchmark(count, client.delete, next(pairs))
@pytest.mark.benchmark()
diff --git a/pymemcache/test/test_client.py b/pymemcache/test/test_client.py
index 1bf8d57..1d445f2 100644
--- a/pymemcache/test/test_client.py
+++ b/pymemcache/test/test_client.py
@@ -15,13 +15,12 @@
import collections
import errno
import functools
+import ipaddress
import json
import os
import platform
from unittest import mock
-import re
import socket
-import sys
import unittest
import pytest
@@ -46,31 +45,30 @@ from pymemcache import pool
from pymemcache.test.utils import MockMemcacheClient
-# TODO: Use ipaddress module when dropping support for Python < 3.3
def is_ipv6(address):
- return re.match(r'^[0-9a-f:]+$', address)
+ try:
+ return ipaddress.ip_address(address).version == 6
+ except ValueError:
+ # Fail to parse as valid ip address
+ return False
@pytest.mark.parametrize(
- 'key,allow_unicode_keys,key_prefix,ex_exception,ex_excinfo,ignore_py27',
+ 'key,allow_unicode_keys,key_prefix,ex_exception,ex_excinfo',
[
- (u'b'*251, True, b'',
- MemcacheIllegalInputError, 'Key is too long', False),
- (u'foo bar', True, b'',
- MemcacheIllegalInputError, 'Key contains whitespace', False),
- (u'\00', True, b'',
- MemcacheIllegalInputError, 'Key contains null', False),
- (None, True, b'', TypeError, None, False),
- # The following test won't fail with a TypeError with python 2.7
- (b"", False, '', TypeError, None, True),
+ ('b'*251, True, b'',
+ MemcacheIllegalInputError, 'Key is too long'),
+ ('foo bar', True, b'',
+ MemcacheIllegalInputError, 'Key contains whitespace'),
+ ('\00', True, b'',
+ MemcacheIllegalInputError, 'Key contains null'),
+ (None, True, b'', TypeError, None),
])
@pytest.mark.unit()
def test_check_key_helper_failing_conditions(key, allow_unicode_keys,
key_prefix, ex_exception,
- ex_excinfo, ignore_py27):
+ ex_excinfo):
- if ignore_py27 and sys.version_info < (3, 0, 0):
- pytest.skip("skipping for Python 2.7")
with pytest.raises(ex_exception) as excinfo:
check_key_helper(key, allow_unicode_keys, key_prefix)
@@ -1376,7 +1374,7 @@ class TestPooledClientIdleTimeout(ClientTestMixin, unittest.TestCase):
return client
def test_free_idle(self):
- class Counter(object):
+ class Counter:
count = 0
def increment(self, obj):
diff --git a/pymemcache/test/test_client_retry.py b/pymemcache/test/test_client_retry.py
index 230a941..de64a46 100644
--- a/pymemcache/test/test_client_retry.py
+++ b/pymemcache/test/test_client_retry.py
@@ -2,8 +2,8 @@
import functools
import unittest
+from unittest import mock
-import mock
import pytest
from .test_client import ClientTestMixin, MockSocket
diff --git a/pymemcache/test/test_serde.py b/pymemcache/test/test_serde.py
index af62991..d4c58dc 100644
--- a/pymemcache/test/test_serde.py
+++ b/pymemcache/test/test_serde.py
@@ -45,12 +45,6 @@ class TestSerde(TestCase):
def test_int(self):
self.check(1, FLAG_INTEGER)
- def test_long(self):
- # long only exists with Python 2, so we're just testing for another
- # integer with Python 3
- expected_flags = FLAG_INTEGER
- self.check(123123123123123123123, expected_flags)
-
def test_pickleable(self):
self.check({'a': 'dict'}, FLAG_PICKLE)