From 4a1c769a7ed82715c82f1068709e11487870b830 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 22 Jan 2013 19:21:29 +0000 Subject: [PATCH] [Bug #6361] try to run soundex tool Updated for python3 svn: r21199 --- gramps/gen/soundex.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) 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]