From e98c372d1587af657031640c0df23ee7e7cdddba Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 6 Apr 2015 01:27:09 -0400 Subject: [PATCH] Python 3.x Support Python 3.x Support (force_unicode only works in Python 2.x) Django 1.6+ Support (force_unicode is deprecated) Removed unused imports --- anora/templatetags/anora.py | 13 +++++-------- anora/tests.py | 5 +++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/anora/templatetags/anora.py b/anora/templatetags/anora.py index d9eb0ab..4d1d5f8 100644 --- a/anora/templatetags/anora.py +++ b/anora/templatetags/anora.py @@ -1,17 +1,14 @@ import re from django import template -from django.conf import settings -from django.utils.encoding import force_unicode -from django.template.defaultfilters import stringfilter register = template.Library() -CONSONANT_SOUND = re.compile(r'''one(![ir])''', re.IGNORECASE|re.VERBOSE) -VOWEL_SOUND = re.compile(r'''[aeio]|u([aeiou]|[^n][^aeiou]|ni[^dmnl]|nil[^l])|h(ier|onest|onou?r|ors\b|our(!i))|[fhlmnrsx]\b''', re.IGNORECASE|re.VERBOSE) +CONSONANT_SOUND = re.compile(r'''one(![ir])''', re.IGNORECASE | re.VERBOSE) +VOWEL_SOUND = re.compile(r'''[aeio]|u([aeiou]|[^n][^aeiou]|ni[^dmnl]|nil[^l])|h(ier|onest|onou?r|ors\b|our(!i))|[fhlmnrsx]\b''', re.IGNORECASE | re.VERBOSE) + @register.filter def anora(text): - text = force_unicode(text) - anora = 'an' if not CONSONANT_SOUND.match(text) and VOWEL_SOUND.match(text) else 'a' - return anora + ' ' + text \ No newline at end of file + anora = 'an' if not CONSONANT_SOUND.match(text) and VOWEL_SOUND.match(text) else 'a' + return anora + ' ' + text diff --git a/anora/tests.py b/anora/tests.py index de4202d..2b9270f 100644 --- a/anora/tests.py +++ b/anora/tests.py @@ -1,12 +1,13 @@ from django.utils import unittest from anora.templatetags.anora import anora -class AnoraTestCase(unittest.TestCase): +class AnoraTestCase(unittest.TestCase): + def test_anora(self): awords = ['rabbit', 'mole', 'fox'] anwords = ['owl', 'ox', 'octopus'] for an_a, word_list in (('a', awords), ('an', anwords)): for word in word_list: - self.assertEqual(' '.join((an_a, word)), anora(word)) \ No newline at end of file + self.assertEqual(' '.join((an_a, word)), anora(word))