From cfe552ccb39e15544bbb1ab1eccc41081e0c6441 Mon Sep 17 00:00:00 2001 From: Not Carl Date: Sat, 28 Apr 2012 03:29:42 -0400 Subject: [PATCH 1/3] Modified phone2numeric to not use regular expression or lambdas --- django/utils/text.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/django/utils/text.py b/django/utils/text.py index eaafb96d7cca1..7d0a86e820688 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -266,14 +266,12 @@ def recapitalize(text): def phone2numeric(phone): "Converts a phone number with letters into its numeric equivalent." - letters = re.compile(r'[A-Z]', re.I) - char2number = lambda m: {'a': '2', 'b': '2', 'c': '2', 'd': '3', 'e': '3', - 'f': '3', 'g': '4', 'h': '4', 'i': '4', 'j': '5', 'k': '5', 'l': '5', - 'm': '6', 'n': '6', 'o': '6', 'p': '7', 'q': '7', 'r': '7', 's': '7', - 't': '8', 'u': '8', 'v': '8', 'w': '9', 'x': '9', 'y': '9', 'z': '9', - }.get(m.group(0).lower()) - return letters.sub(char2number, phone) -phone2numeric = allow_lazy(phone2numeric) + char2number = {'a': '2', 'b': '2', 'c': '2', 'd': '3', 'e': '3', 'f': '3', + 'g': '4', 'h': '4', 'i': '4', 'j': '5', 'k': '5', 'l': '5', 'm': '6', + 'n': '6', 'o': '6', 'p': '7', 'q': '7', 'r': '7', 's': '7', 't': '8', + 'u': '8', 'v': '8', 'w': '9', 'x': '9', 'y': '9', 'z': '9', + } + return u''.join(char2number.get(c,c) for c in phone.lower()) # From http://www.xhaus.com/alan/python/httpcomp.html#gzip # Used with permission. From a7829f33349f0778d52c35615465b11e42e573b4 Mon Sep 17 00:00:00 2001 From: Not Carl Date: Sat, 28 Apr 2012 03:33:37 -0400 Subject: [PATCH 2/3] forgot the allow_lazy(phone2numeric) --- django/utils/text.py | 1 + 1 file changed, 1 insertion(+) diff --git a/django/utils/text.py b/django/utils/text.py index 7d0a86e820688..42a2b50f16ae2 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -272,6 +272,7 @@ def phone2numeric(phone): 'u': '8', 'v': '8', 'w': '9', 'x': '9', 'y': '9', 'z': '9', } return u''.join(char2number.get(c,c) for c in phone.lower()) +phone2numeric = allow_lazy(phone2numeric) # From http://www.xhaus.com/alan/python/httpcomp.html#gzip # Used with permission. From 6b430b883f3cfdc8a8016c539dd590c9f7e211b1 Mon Sep 17 00:00:00 2001 From: Not Carl Date: Sat, 28 Apr 2012 14:58:11 -0400 Subject: [PATCH 3/3] Whitespace formatting --- django/utils/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/utils/text.py b/django/utils/text.py index 42a2b50f16ae2..606b15c0cec8f 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -271,7 +271,7 @@ def phone2numeric(phone): 'n': '6', 'o': '6', 'p': '7', 'q': '7', 'r': '7', 's': '7', 't': '8', 'u': '8', 'v': '8', 'w': '9', 'x': '9', 'y': '9', 'z': '9', } - return u''.join(char2number.get(c,c) for c in phone.lower()) + return u''.join(char2number.get(c, c) for c in phone.lower()) phone2numeric = allow_lazy(phone2numeric) # From http://www.xhaus.com/alan/python/httpcomp.html#gzip