diff --git a/gramps/gen/soundex.py b/gramps/gen/soundex.py index 412cd9f4c..6040b8f14 100644 --- a/gramps/gen/soundex.py +++ b/gramps/gen/soundex.py @@ -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]