GrampsLocale: Handle errors in getting collation key from locale module

svn: r21489
This commit is contained in:
John Ralls 2013-02-28 18:57:25 +00:00
parent 38dcbbae58
commit 991447264a

View File

@ -527,15 +527,21 @@ 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:
base_locale = locale.getlocale(locale.LC_COLLATE) try:
locale.setlocale(locale.LC_COLLATE, self.collation) base_locale = locale.getlocale(locale.LC_COLLATE)
locale.setlocale(locale.LC_COLLATE, self.collation)
#locale in Python2 can't. #locale in Python2 can't.
if sys.version_info[0] < 3 and isinstance(string, unicode): if sys.version_info[0] < 3 and isinstance(string, unicode):
key = locale.strxfrm(string.encode("utf-8", "replace")) key = locale.strxfrm(string.encode("utf-8", "replace"))
else: else:
key = locale.strxfrm(string) 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 return key
def strcoll(self, string1, string2): def strcoll(self, string1, string2):