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