From 991447264aa748cae539c6f8342dbc97e250d9f7 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Thu, 28 Feb 2013 18:57:25 +0000 Subject: [PATCH] GrampsLocale: Handle errors in getting collation key from locale module svn: r21489 --- gramps/gen/utils/grampslocale.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index 3e881c0fd..95289644d 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -527,15 +527,21 @@ class GrampsLocale(object): #ICU can digest strings and unicode return self.collator.getCollationKey(string).getByteArray() else: - base_locale = locale.getlocale(locale.LC_COLLATE) - locale.setlocale(locale.LC_COLLATE, self.collation) + try: + base_locale = locale.getlocale(locale.LC_COLLATE) + locale.setlocale(locale.LC_COLLATE, self.collation) #locale in Python2 can't. - if sys.version_info[0] < 3 and isinstance(string, unicode): - key = locale.strxfrm(string.encode("utf-8", "replace")) - else: - key = locale.strxfrm(string) + if sys.version_info[0] < 3 and isinstance(string, unicode): + key = locale.strxfrm(string.encode("utf-8", "replace")) + else: + key = locale.strxfrm(string) + + locale.setlocale(locale.LC_COLLATE, base_locale) + except Exception as err: + LOG.warn("Failed to obtain key for %s because %s", + self.collation, str(err)) + return string - locale.setlocale(locale.LC_COLLATE, base_locale) return key def strcoll(self, string1, string2):