Skip to content

Commit 3afd023

Browse files
committed
Fix compatibility issue between python 2.* and 3.*
1 parent 5722b85 commit 3afd023

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

redis_cache/sharder.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from bisect import insort, bisect
22
import hashlib
3-
from django.utils.encoding import force_text
43

4+
from django.utils.encoding import force_text
5+
from django.utils.six import integer_types
56

67
DIGITS = 8
78

@@ -23,17 +24,14 @@ def __init__(self, node, i):
2324
self._position = get_slot(key)
2425

2526
def __gt__(self, other):
26-
# WARNING PYTHON < 3 : in get_slot() if the hash value overflows integer a LONG is returned !
27-
if isinstance(other, (int, long)):
27+
if isinstance(other, integer_types):
2828
return self._position > other
2929
elif isinstance(other, Node):
3030
return self._position > other._position
3131
raise TypeError(
3232
'Cannot compare this class with "%s" type' % type(other)
3333
)
3434

35-
def __str__(self):
36-
return 'Node(position=%s, i=%s, node=%s)' % (self._position, self._i, self.node)
3735

3836
class HashRing(object):
3937

tests/testapp/tests/serializers_tests.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,15 @@ class BaseSerializerTestCase(SetupMixin, TestCase):
2323
converts_tuple_to_list = False
2424
serializes_objects = True
2525

26-
def assertion_message(self, name):
27-
return '%s %s' % (self.__class__.__name__, name)
28-
2926
def test_string(self):
3027
self.cache.set('a', 'a')
31-
self.assertEqual(self.cache.get('a'), 'a', self.assertion_message('test_string'))
28+
self.assertEqual(self.cache.get('a'), 'a')
3229

3330
def test_unicode(self):
3431
self.cache.set('Iñtërnâtiônàlizætiøn', 'Iñtërnâtiônàlizætiøn2')
3532
self.assertEqual(
3633
self.cache.get('Iñtërnâtiônàlizætiøn'),
37-
'Iñtërnâtiônàlizætiøn2',
38-
self.assertion_message('test_unicode')
34+
'Iñtërnâtiônàlizætiøn2'
3935
)
4036

4137
def test_number(self):
@@ -71,7 +67,7 @@ def test_dictionary(self):
7167
'function': f,
7268
'class': C,
7369
})
74-
self.assertEqual(stuff, data, self.assertion_message('test_dictionary'))
70+
self.assertEqual(stuff, data)
7571

7672

7773
@override_settings(CACHES={

0 commit comments

Comments
 (0)