[Bug #6361] try to run soundex tool

Updated for python3

svn: r21204
This commit is contained in:
John Ralls 2013-01-22 22:22:48 +00:00
parent a5ffbb5e08
commit 1e02a60f14

View File

@ -29,17 +29,23 @@ Provide soundex calculation
# Standard python modules
#
#-------------------------------------------------------------------------
import string
import sys
import unicodedata
if sys.version_info[0] < 3:
import string
#-------------------------------------------------------------------------
#
# constants
# constants
#
#-------------------------------------------------------------------------
IGNORE = "HW~!@#$%^&*()_+=-`[]\|;:'/?.,<>\" \t\f\v"
TABLE = string.maketrans('ABCDEFGIJKLMNOPQRSTUVXYZ',
'012301202245501262301202')
if sys.version_info[0] < 3:
TABLE = string.maketrans('ABCDEFGIJKLMNOPQRSTUVXYZ',
'012301202245501262301202')
else:
TABLE = bytes.maketrans(b'ABCDEFGIJKLMNOPQRSTUVXYZ',
b'012301202245501262301202')
from .constfunc import conv_to_unicode_direct
@ -55,9 +61,14 @@ def soundex(strval):
conv_to_unicode_direct(strval.upper().strip())).encode('ASCII', 'ignore')
if not strval:
return "Z000"
strval = strval.encode('iso-8859-1')
str2 = strval[0]
strval = strval.translate(TABLE, IGNORE)
if sys.version_info[0] < 3:
strval = strval.encode('iso-8859-1') # Really?
str2 = strval[0]
strval = strval.translate(TABLE, IGNORE)
else:
strval = strval.decode('ASCII', 'ignore')
str2 = strval[0]
strval = strval.translate(TABLE)
if not strval:
return "Z000"
prev = strval[0]