7471: Fix python3 sort key errors

Ensure input to strxfrm is correct type.
Apply patch by Marc Hulsman.
This commit is contained in:
Nick Hall 2014-06-12 22:00:35 +01:00
parent ccd6c3143e
commit baf368c049
2 changed files with 7 additions and 7 deletions

View File

@ -862,12 +862,12 @@ class GrampsLocale(object):
#ICU can digest strings and unicode
return self.collator.getCollationKey(string).getByteArray()
else:
try:
if sys.version_info[0] < 3 and isinstance(string, unicode):
key = locale.strxfrm(string.encode("utf-8", "replace"))
else:
string = string.encode("utf-8", "replace")
if sys.version_info[0] >= 3 and isinstance(string, bytes):
string = string.decode("utf-8", "replace")
try:
key = locale.strxfrm(string)
except Exception as err:
LOG.warn("Failed to obtain key for %s because %s",
self.collation, str(err))

View File

@ -90,10 +90,10 @@ class Node(object):
#sortkey must be localized sort, so
self.sortkey = glocale.sort_key(sortkey)
if not self.sortkey:
self.sortkey = b''
self.sortkey = glocale.sort_key('')
else:
self.name = ''
self.sortkey = b''
self.sortkey = glocale.sort_key('')
self.ref = ref
self.handle = handle
self.secondary = secondary