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 c8df231cd7
commit 3880914e96
2 changed files with 7 additions and 7 deletions

View File

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

View File

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