X-Git-Url: https://git.korewanetadesu.com/?p=python-collate.git;a=blobdiff_plain;f=collate%2Fsyslocale.py;h=e48ee8252a86c89bab595c7a00c6d5418b8ad808;hp=1ee292402da1d72f859cfe7349359d8454e64f83;hb=HEAD;hpb=e4b16f225fadb8868f6040c7798f2dd4c4d197e1 diff --git a/collate/syslocale.py b/collate/syslocale.py index 1ee2924..e48ee82 100644 --- a/collate/syslocale.py +++ b/collate/syslocale.py @@ -12,17 +12,18 @@ locale of all previous collators and anything else using the system locale information. Use this collation backend if... - - You are on a system without ICU or UCA datafiles for the locale, - and DUCET results are not acceptable. + - You are on a system without ICU. Avoid this backend if... - - ICU or UCA support is available for the current locale. + - ICU 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. """ +__all__ = ["Collator"] + import locale import collate.errors @@ -33,6 +34,7 @@ class Collator(collate._abcollator.Collator): """C library locale-based collation.""" def __init__(self, locale_code, encoding=None): + super(Collator, self).__init__(locale, encoding) locale_code, encoding = collate._locale.getpair(locale_code, encoding) try: setlocale = locale_code + "." + encoding @@ -51,18 +53,5 @@ class Collator(collate._abcollator.Collator): """ try: return locale.strxfrm(string) - except UnicodeEncodeError: - return locale.strxfrm(string.encode(self.encoding, "replace")) - - def cmp(self, a, b): - """Return negative if a < b, zero if a == b, positive if a > b. - - 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): - b = b.decode(self.encoding, "replace") - return locale.strcoll(a, b) - + except UnicodeError: + return locale.strxfrm(string.str(self.encoding))