Skip to content

Commit

Permalink
Dropping Python 2.X support.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebleier committed Oct 14, 2020
1 parent 3ed6418 commit 9352ba8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 58 deletions.
32 changes: 3 additions & 29 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
dist: xenial
language: python
python:
- 2.7
- 3.5
- 3.6
- 3.7
- 3.8
- 3.9
env:
- DJANGO_VERSION='<2.0'
- DJANGO_VERSION='>=2.0,<2.1'
- DJANGO_VERSION='>=2.1,<2.2'
- DJANGO_VERSION='>=2.2,<3.0'
- DJANGO_VERSION='>=3.0,<3.1'
- DJANGO_VERSION='>=3.1a1,<3.2'
matrix:
exclude:
- python: 2.7
env: DJANGO_VERSION='>=2.0,<2.1'
- python: 2.7
env: DJANGO_VERSION='>=2.1,<2.2'
- python: 2.7
env: DJANGO_VERSION='>=2.2,<3.0'
- python: 2.7
env: DJANGO_VERSION='>=3.0,<3.1'
- python: 2.7
env: DJANGO_VERSION='>=3.1a1,<3.2'
- python: 3.5
env: DJANGO_VERSION='<2.0'
- python: 3.5
env: DJANGO_VERSION='>=3.0,<3.1'
- python: 3.5
env: DJANGO_VERSION='>=3.1a1,<3.2'
- python: 3.6
env: DJANGO_VERSION='<2.0'
- python: 3.7
env: DJANGO_VERSION='<2.0'
- DJANGO_VERSION='>=3.1,<3.2'
# command to run tests
install: ./install_redis.sh
script: make test DJANGO_VERSION=$DJANGO_VERSION
Expand Down
4 changes: 2 additions & 2 deletions redis_cache/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
except ImportError:
pass

from django.utils.encoding import force_bytes, force_text
from django.utils.encoding import force_bytes, force_str


class BaseSerializer(object):
Expand Down Expand Up @@ -51,7 +51,7 @@ def serialize(self, value):
return force_bytes(json.dumps(value))

def deserialize(self, value):
return json.loads(force_text(value))
return json.loads(force_str(value))


class MSGPackSerializer(BaseSerializer):
Expand Down
18 changes: 7 additions & 11 deletions redis_cache/sharder.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
from bisect import insort, bisect
import hashlib
from django.utils.encoding import force_text
from bisect import insort, bisect


DIGITS = 8
MAX_SLOTS = 2**16


def get_slot(s):
_hash = hashlib.md5(s.encode('utf-8')).hexdigest()
return int(_hash[-DIGITS:], 16)
def get_slot(key):
digest = hashlib.md5(key.encode('utf-8')).hexdigest()
return int(digest, 16) % MAX_SLOTS


class Node(object):

def __init__(self, node, i):
self._node = node
self._i = i
key = "{0}:{1}".format(
force_text(i),
force_text(self._node),
)
key = f"{i}:{self._node}"
self._position = get_slot(key)

def __gt__(self, other):
Expand Down Expand Up @@ -52,5 +48,5 @@ def remove(self, node):
del self._nodes[n - i - 1]

def get_node(self, key):
i = bisect(self._nodes, get_slot(force_text(key))) - 1
i = bisect(self._nodes, get_slot(key)) - 1
return self._nodes[i]._node
9 changes: 3 additions & 6 deletions redis_cache/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
import warnings

from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import force_text
from six import python_2_unicode_compatible, string_types
from six.moves.urllib.parse import parse_qs, urlparse

from redis.connection import SSLConnection
from urllib.parse import parse_qs
from urllib.parse import urlparse


def get_servers(location):
"""Returns a list of servers given the server argument passed in from
Django.
"""
if isinstance(location, string_types):
if isinstance(location, str):
servers = location.split(',')
elif hasattr(location, '__iter__'):
servers = location
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
redis<4.0
six
13 changes: 4 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,23 @@
url="http://github.com/sebleier/django-redis-cache/",
author="Sean Bleier",
author_email="[email protected]",
version="2.1.3",
version="3.0.0",
license="BSD",
packages=["redis_cache", "redis_cache.backends"],
description="Redis Cache Backend for Django",
install_requires=['redis<4.0', 'six'],
install_requires=['redis<4.0'],
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries",
"Topic :: Utilities",
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 1.11",
"Framework :: Django :: 2.0",
"Framework :: Django :: 2.1",
"Framework :: Django :: 2.2",
"Framework :: Django :: 3.0",
"Framework :: Django :: 3.1",
],
Expand Down

0 comments on commit 9352ba8

Please sign in to comment.