Skip to content

Commit

Permalink
Fixes for rebase and further cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jogo committed Jul 13, 2021
1 parent f48a559 commit 7e7742a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 39 deletions.
5 changes: 1 addition & 4 deletions pymemcache/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pymemcache/client/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def _set_many(self, client, values, *args, **kwargs):
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):
Expand Down
6 changes: 0 additions & 6 deletions pymemcache/serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
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
Expand Down
34 changes: 16 additions & 18 deletions pymemcache/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,31 +45,30 @@
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)

Expand Down Expand Up @@ -1376,7 +1374,7 @@ def make_client(self, mock_socket_values, **kwargs):
return client

def test_free_idle(self):
class Counter(object):
class Counter:
count = 0

def increment(self, obj):
Expand Down
6 changes: 0 additions & 6 deletions pymemcache/test/test_serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ def test_unicode(self):
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)

Expand Down
4 changes: 0 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ commands =
pip install -e .
py.test {posargs:pymemcache/test/ -m integration}

<<<<<<< HEAD
[testenv:flake8]
# Avoid pulling all the base requirements only to run flake8
deps = flake8
Expand All @@ -29,9 +28,6 @@ commands =
python setup.py check --restructuredtext

[testenv:coverage]
=======
[testenv:py39-flake8]
>>>>>>> 290ad0c (Drop python support 2.7, 3.4 and 3.5)
commands =
py.test --cov=pymemcache

Expand Down

0 comments on commit 7e7742a

Please sign in to comment.