Skip to content

Commit afc5dcf

Browse files
committed
Whoosh all but fully working under Python 3.
1 parent 8c95790 commit afc5dcf

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

haystack/backends/whoosh_backend.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def search(self, query_string, sort_by=None, start_offset=0, end_offset=None,
405405
page_length = end_offset - start_offset
406406

407407
if page_length and page_length > 0:
408-
page_num = start_offset / page_length
408+
page_num = int(start_offset / page_length)
409409

410410
# Increment because Whoosh uses 1-based page numbers.
411411
page_num += 1
@@ -517,7 +517,7 @@ def more_like_this(self, model_instance, additional_query_string=None,
517517
page_length = end_offset - start_offset
518518

519519
if page_length and page_length > 0:
520-
page_num = start_offset / page_length
520+
page_num = int(start_offset / page_length)
521521

522522
# Increment because Whoosh uses 1-based page numbers.
523523
page_num += 1
@@ -672,7 +672,7 @@ def _from_python(self, value):
672672
value = 'false'
673673
elif isinstance(value, (list, tuple)):
674674
value = u','.join([force_text(v) for v in value])
675-
elif isinstance(value, (int, long, float)):
675+
elif isinstance(value, (six.integer_types, float)):
676676
# Leave it alone.
677677
pass
678678
else:
@@ -706,7 +706,7 @@ def _to_python(self, value):
706706
converted_value = json.loads(value)
707707

708708
# Try to handle most built-in types.
709-
if isinstance(converted_value, (list, tuple, set, dict, int, float, long, complex)):
709+
if isinstance(converted_value, (list, tuple, set, dict, six.integer_types, float, complex)):
710710
return converted_value
711711
except:
712712
# If it fails (SyntaxError or its ilk) or we don't trust it,

haystack/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def autocomplete(self, **kwargs):
461461
}
462462
query_bits.append(SQ(**kwargs))
463463

464-
return clone.filter(reduce(operator.__and__, query_bits))
464+
return clone.filter(six.moves.reduce(operator.__and__, query_bits))
465465

466466
def using(self, connection_name):
467467
"""

tests/whoosh_tests/tests/forms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ class SpellingSuggestionTestCase(LiveWhooshRoundTripTestCase):
1212
def setUp(self):
1313
self.old_spelling_setting = settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING']
1414
settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING'] = True
15-
15+
1616
super(SpellingSuggestionTestCase, self).setUp()
17-
17+
1818
def tearDown(self):
1919
settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING'] = self.old_spelling_setting
2020
super(SpellingSuggestionTestCase, self).tearDown()
21-
21+
2222
def test_form_suggestion(self):
2323
form = SearchForm({'q': 'exampl'})
2424
self.assertEqual(form.get_suggestion(), '')
25-
25+
2626
def test_view_suggestion(self):
2727
view = SearchView(template='test_suggestion.html')
2828
mock = HttpRequest()
2929
mock.GET['q'] = 'exampl'
3030
resp = view(mock)
31-
self.assertEqual(resp.content, 'Suggestion: ')
31+
self.assertEqual(resp.content, b'Suggestion: ')

tests/whoosh_tests/tests/whoosh_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def test__from_python(self):
321321
self.assertEqual(self.sb._from_python(2653), 2653)
322322
self.assertEqual(self.sb._from_python(25.5), 25.5)
323323
self.assertEqual(self.sb._from_python([1, 2, 3]), u'1,2,3')
324-
self.assertEqual(self.sb._from_python({'a': 1, 'c': 3, 'b': 2}), u"{'a': 1, 'c': 3, 'b': 2}")
324+
self.assertTrue("a': 1" in self.sb._from_python({'a': 1, 'c': 3, 'b': 2}))
325325
self.assertEqual(self.sb._from_python(datetime(2009, 5, 9, 16, 14)), datetime(2009, 5, 9, 16, 14))
326326
self.assertEqual(self.sb._from_python(datetime(2009, 5, 9, 0, 0)), datetime(2009, 5, 9, 0, 0))
327327
self.assertEqual(self.sb._from_python(datetime(1899, 5, 18, 0, 0)), datetime(1899, 5, 18, 0, 0))
@@ -393,7 +393,7 @@ def test_writable(self):
393393
if not os.path.exists(settings.HAYSTACK_CONNECTIONS['default']['PATH']):
394394
os.makedirs(settings.HAYSTACK_CONNECTIONS['default']['PATH'])
395395

396-
os.chmod(settings.HAYSTACK_CONNECTIONS['default']['PATH'], 0400)
396+
os.chmod(settings.HAYSTACK_CONNECTIONS['default']['PATH'], 0o400)
397397

398398
try:
399399
self.sb.setup()
@@ -402,7 +402,7 @@ def test_writable(self):
402402
# Yay. We failed
403403
pass
404404

405-
os.chmod(settings.HAYSTACK_CONNECTIONS['default']['PATH'], 0755)
405+
os.chmod(settings.HAYSTACK_CONNECTIONS['default']['PATH'], 0o755)
406406

407407
def test_slicing(self):
408408
self.sb.update(self.wmmi, self.sample_objs)

0 commit comments

Comments
 (0)