Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Modified phone2numeric to not use regular expression or lambdas

  • Loading branch information...
commit cfe552ccb39e15544bbb1ab1eccc41081e0c6441 1 parent f4cc782
Definitely Not Carl authored April 28, 2012

Showing 1 changed file with 6 additions and 8 deletions. Show diff stats Hide diff stats

  1. 14  django/utils/text.py
14  django/utils/text.py
@@ -266,14 +266,12 @@ def recapitalize(text):
266 266
 
267 267
 def phone2numeric(phone):
268 268
     "Converts a phone number with letters into its numeric equivalent."
269  
-    letters = re.compile(r'[A-Z]', re.I)
270  
-    char2number = lambda m: {'a': '2', 'b': '2', 'c': '2', 'd': '3', 'e': '3',
271  
-         'f': '3', 'g': '4', 'h': '4', 'i': '4', 'j': '5', 'k': '5', 'l': '5',
272  
-         'm': '6', 'n': '6', 'o': '6', 'p': '7', 'q': '7', 'r': '7', 's': '7',
273  
-         't': '8', 'u': '8', 'v': '8', 'w': '9', 'x': '9', 'y': '9', 'z': '9',
274  
-        }.get(m.group(0).lower())
275  
-    return letters.sub(char2number, phone)
276  
-phone2numeric = allow_lazy(phone2numeric)
  269
+    char2number = {'a': '2', 'b': '2', 'c': '2', 'd': '3', 'e': '3', 'f': '3',
  270
+         'g': '4', 'h': '4', 'i': '4', 'j': '5', 'k': '5', 'l': '5', 'm': '6',
  271
+         'n': '6', 'o': '6', 'p': '7', 'q': '7', 'r': '7', 's': '7', 't': '8',
  272
+         'u': '8', 'v': '8', 'w': '9', 'x': '9', 'y': '9', 'z': '9',
  273
+        }
  274
+    return u''.join(char2number.get(c,c) for c in phone.lower())
277 275
 
278 276
 # From http://www.xhaus.com/alan/python/httpcomp.html#gzip
279 277
 # Used with permission.

0 notes on commit cfe552c

Please sign in to comment.
Something went wrong with that request. Please try again.