From 3880914e9668bbc601dde99e9776a3fa806e8b84 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Thu, 12 Jun 2014 22:00:35 +0100 Subject: [PATCH] 7471: Fix python3 sort key errors Ensure input to strxfrm is correct type. Apply patch by Marc Hulsman. --- gramps/gen/utils/grampslocale.py | 10 +++++----- gramps/gui/views/treemodels/treebasemodel.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index 42995ba96..5f57936cb 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -852,12 +852,12 @@ class GrampsLocale(object): #ICU can digest strings and unicode return self.collator.getCollationKey(string).getByteArray() 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: - if sys.version_info[0] < 3 and isinstance(string, unicode): - key = locale.strxfrm(string.encode("utf-8", "replace")) - else: - key = locale.strxfrm(string) - + key = locale.strxfrm(string) except Exception as err: LOG.warn("Failed to obtain key for %s because %s", self.collation, str(err)) diff --git a/gramps/gui/views/treemodels/treebasemodel.py b/gramps/gui/views/treemodels/treebasemodel.py index ad8b35702..285d913da 100644 --- a/gramps/gui/views/treemodels/treebasemodel.py +++ b/gramps/gui/views/treemodels/treebasemodel.py @@ -92,10 +92,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