Skip to content

Commit

Permalink
Merge pull request #119 from timgraham/trove
Browse files Browse the repository at this point in the history
Drop support for Django < 1.8 and related cleanups
  • Loading branch information
sebleier authored Aug 26, 2016
2 parents a073a3e + 88cd582 commit 86cc01a
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 129 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
env:
- DJANGO_VERSION=1.5
- DJANGO_VERSION=1.6
- DJANGO_VERSION=1.7
- DJANGO_VERSION=1.8
# command to run tests
install: ./install_redis.sh
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/.
Changelog
=========

1.7.0
-----

* Drops support for Django < 1.8 and Python 3.2.

1.5.0
-----

Expand Down
5 changes: 3 additions & 2 deletions redis_cache/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
from django.core.cache.backends.base import (
BaseCache, DEFAULT_TIMEOUT, InvalidCacheBackendError,
)
from django.core.exceptions import ImproperlyConfigured

try:
Expand All @@ -10,7 +12,6 @@

from redis.connection import DefaultParser

from redis_cache.compat import DEFAULT_TIMEOUT
from redis_cache.connection import pool
from redis_cache.utils import (
CacheKey, get_servers, parse_connection_kwargs, import_class
Expand Down
3 changes: 2 additions & 1 deletion redis_cache/backends/multiple.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from collections import defaultdict

from django.core.cache.backends.base import DEFAULT_TIMEOUT

from redis_cache.backends.base import BaseRedisCache
from redis_cache.compat import DEFAULT_TIMEOUT
from redis_cache.sharder import HashRing


Expand Down
4 changes: 2 additions & 2 deletions redis_cache/backends/single.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from redis_cache.compat import DEFAULT_TIMEOUT

try:
import cPickle as pickle
except ImportError:
import pickle
import random

from django.core.cache.backends.base import DEFAULT_TIMEOUT

from redis_cache.backends.base import BaseRedisCache


Expand Down
44 changes: 0 additions & 44 deletions redis_cache/compat.py

This file was deleted.

8 changes: 4 additions & 4 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 redis_cache.compat import smart_bytes, smart_text
from django.utils.encoding import force_bytes, force_text


class BaseSerializer(object):
Expand All @@ -39,7 +39,7 @@ def serialize(self, value):
return pickle.dumps(value, self.pickle_version)

def deserialize(self, value):
return pickle.loads(smart_bytes(value))
return pickle.loads(force_bytes(value))


class JSONSerializer(BaseSerializer):
Expand All @@ -48,10 +48,10 @@ def __init__(self, **kwargs):
super(JSONSerializer, self).__init__(**kwargs)

def serialize(self, value):
return smart_bytes(json.dumps(value))
return force_bytes(json.dumps(value))

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


class MSGPackSerializer(BaseSerializer):
Expand Down
8 changes: 4 additions & 4 deletions redis_cache/sharder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from bisect import insort, bisect
import hashlib
from redis_cache.compat import smart_text
from django.utils.encoding import force_text


DIGITS = 8
Expand All @@ -17,8 +17,8 @@ def __init__(self, node, i):
self._node = node
self._i = i
key = "{0}:{1}".format(
smart_text(i),
smart_text(self._node),
force_text(i),
force_text(self._node),
)
self._position = get_slot(key)

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

def get_node(self, key):
i = bisect(self._nodes, get_slot(smart_text(key))) - 1
i = bisect(self._nodes, get_slot(force_text(key))) - 1
return self._nodes[i]._node
27 changes: 9 additions & 18 deletions redis_cache/utils.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import importlib
import warnings

from django.core.exceptions import ImproperlyConfigured
from redis.connection import SSLConnection

from redis_cache.compat import (
smart_text, python_2_unicode_compatible, parse_qs, urlparse
)
from django.utils import six
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.six.moves.urllib.parse import parse_qs, urlparse

try:
import importlib
except ImportError:
from django.utils import importlib

try:
basestring
except NameError:
basestring = str
from redis.connection import SSLConnection


@python_2_unicode_compatible
Expand All @@ -30,20 +21,20 @@ def __init__(self, key, versioned_key):
def __eq__(self, other):
return self._versioned_key == other

def __unicode__(self):
return smart_text(self._versioned_key)
def __str__(self):
return force_text(self._versioned_key)

def __hash__(self):
return hash(self._versioned_key)

__repr__ = __str__ = __unicode__
__repr__ = __str__


def get_servers(location):
"""Returns a list of servers given the server argument passed in from
Django.
"""
if isinstance(location, basestring):
if isinstance(location, six.string_types):
servers = location.split(',')
elif hasattr(location, '__iter__'):
servers = location
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
hiredis==0.2.0
django-nose==1.4
nose==1.3.6
unittest2==1.0.1
msgpack-python==0.4.6
pyyaml==3.11
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
install_requires=['redis>=2.10.3'],
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries",
"Topic :: Utilities",
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 1.8",
],
)
18 changes: 3 additions & 15 deletions tests/testapp/tests/base_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
from hashlib import sha1
import os
import subprocess
import sys
import time

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest


try:
import cPickle as pickle
Expand All @@ -20,17 +14,13 @@

from django.core.cache import get_cache
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
try:
from django.test import override_settings
except ImportError:
from django.test.utils import override_settings
from django.test import TestCase, override_settings
from django.utils.encoding import force_bytes

import redis

from tests.testapp.models import Poll, expensive_calculation
from redis_cache.cache import RedisCache, pool
from redis_cache.compat import DEFAULT_TIMEOUT, smart_bytes
from redis_cache.utils import get_servers, parse_connection_kwargs


Expand Down Expand Up @@ -299,7 +289,6 @@ def test_expiration(self):
self.assertEqual(self.cache.get("expire2"), "newvalue")
self.assertEqual("expire3" in self.cache, False)

@unittest.skipIf(DEFAULT_TIMEOUT is None, "Version of django doesn't support indefinite timeouts.")
def test_set_expiration_timeout_None(self):
key, value = 'key', 'value'
self.cache.set(key, value, timeout=None)
Expand Down Expand Up @@ -479,7 +468,7 @@ def test_clearing_using_version(self):
def test_reinsert_keys(self):
self.cache._pickle_version = 0
for i in range(2000):
s = sha1(smart_bytes(i)).hexdigest()
s = sha1(force_bytes(i)).hexdigest()
self.cache.set(s, self.cache)
self.cache._pickle_version = -1
self.cache.reinsert_keys()
Expand Down Expand Up @@ -563,7 +552,6 @@ def test_ttl_set_expiry(self):
ttl = self.cache.ttl('a')
self.assertAlmostEqual(ttl, 10)

@unittest.skipIf(DEFAULT_TIMEOUT is None, "Version of django doesn't support indefinite timeouts.")
def test_ttl_no_expiry(self):
self.cache.set('a', 'a', timeout=None)
ttl = self.cache.ttl('a')
Expand Down
7 changes: 1 addition & 6 deletions tests/testapp/tests/compressor_tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# -*- coding: utf-8 -*-
try:
from django.test import override_settings
except ImportError:
from django.test.utils import override_settings
from django.test import TestCase

from django.test import TestCase, override_settings

from tests.testapp.tests.base_tests import BaseRedisTestCase

Expand Down
6 changes: 1 addition & 5 deletions tests/testapp/tests/master_slave_tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import time

from django.test import TestCase
try:
from django.test import override_settings
except ImportError:
from django.test.utils import override_settings
from django.test import TestCase, override_settings

from redis_cache.connection import pool

Expand Down
7 changes: 1 addition & 6 deletions tests/testapp/tests/serializers_tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.test import TestCase
try:
from django.test import override_settings
except ImportError:
from django.test.utils import override_settings
from django.test import TestCase, override_settings

from tests.testapp.tests.base_tests import SetupMixin

Expand Down Expand Up @@ -171,4 +167,3 @@ class MSGPackSerializerTestCase(BaseSerializerTestCase):
class YAMLSerializerTestCase(BaseSerializerTestCase):
converts_tuple_to_list = False
serializes_objects = True

6 changes: 1 addition & 5 deletions tests/testapp/tests/socket_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from tests.testapp.tests.base_tests import BaseRedisTestCase
from tests.testapp.tests.multi_server_tests import MultiServerTests

try:
from django.test import override_settings
except ImportError:
from django.test.utils import override_settings
from django.test import TestCase
from django.test import TestCase, override_settings


LOCATION = "unix://:yadayada@/tmp/redis0.sock?db=15"
Expand Down
6 changes: 1 addition & 5 deletions tests/testapp/tests/socket_timeout_tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# -*- coding: utf-8 -*-
try:
from django.test import override_settings
except ImportError:
from django.test.utils import override_settings
from django.test import TestCase
from django.test import TestCase, override_settings

from redis.exceptions import ConnectionError
from tests.testapp.tests.base_tests import SetupMixin
Expand Down
6 changes: 1 addition & 5 deletions tests/testapp/tests/tcp_tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# -*- coding: utf-8 -*-
from tests.testapp.tests.base_tests import BaseRedisTestCase
from tests.testapp.tests.multi_server_tests import MultiServerTests
try:
from django.test import override_settings
except ImportError:
from django.test.utils import override_settings
from django.test import TestCase
from django.test import TestCase, override_settings

from redis_cache.cache import ImproperlyConfigured
from redis.connection import UnixDomainSocketConnection
Expand Down

0 comments on commit 86cc01a

Please sign in to comment.