X-Git-Url: https://git.korewanetadesu.com/?p=python-collate.git;a=blobdiff_plain;f=collate%2Fsyslocale.py;h=1ee292402da1d72f859cfe7349359d8454e64f83;hp=b9f9b920df28a68fa3948ffdd1cfcb07f6e21e48;hb=55e8d3e84b06336ab6c2d8b18958b5e3e6efa284;hpb=c519e411927761939a0461bdf8d0a12b26d965e9 diff --git a/collate/syslocale.py b/collate/syslocale.py index b9f9b92..1ee2924 100644 --- a/collate/syslocale.py +++ b/collate/syslocale.py @@ -19,6 +19,8 @@ Avoid this backend if... - ICU or UCA support is available for the current locale. - You are sorting strings from alphabets outside the primary locale. - You need to support collating multiple locales at once. + - You need the same results across multiple platforms. + """ import locale @@ -31,10 +33,12 @@ class Collator(collate._abcollator.Collator): """C library locale-based collation.""" def __init__(self, locale_code, encoding=None): + locale_code, encoding = collate._locale.getpair(locale_code, encoding) try: - locale.setlocale(locale.LC_COLLATE, locale_code) + setlocale = locale_code + "." + encoding + locale.setlocale(locale.LC_COLLATE, setlocale) except locale.Error: - raise collate.errors.InvalidLocaleError(locale_code) + raise collate.errors.InvalidLocaleError(setlocale) self.locale = locale.getlocale(locale.LC_COLLATE)[0] self.encoding = collate._locale.encoding(encoding) @@ -56,7 +60,6 @@ class Collator(collate._abcollator.Collator): If strs rather than unicodes are passed in, they are first decoded according to the 'encoding' attribute of the Collator. """ - if isinstance(a, str): a = a.decode(self.encoding, "replace") if isinstance(b, str):