Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2 from notcarl/master

Changed phone2numeric to use generator expressions instead of lambdas
  • Loading branch information...
commit 50b0984a8b83133e7108098da9807e94c853364b 2 parents 80d32b5 + 6b430b8
Adrian Holovaty adrianholovaty authored
Showing with 6 additions and 7 deletions.
  1. +6 −7 django/utils/text.py
13 django/utils/text.py
View
@@ -266,13 +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)
+ 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())
phone2numeric = allow_lazy(phone2numeric)
# From http://www.xhaus.com/alan/python/httpcomp.html#gzip
Please sign in to comment.
Something went wrong with that request. Please try again.