X-Git-Url: https://git.korewanetadesu.com/?p=python-collate.git;a=blobdiff_plain;f=collate%2Fsyslocale.py;h=e48ee8252a86c89bab595c7a00c6d5418b8ad808;hp=e2aeed9bdeaba636098c13a5a8e41bf90186569c;hb=HEAD;hpb=f73c4c6cd3ed326c5735ab33a6896697227d07e3 diff --git a/collate/syslocale.py b/collate/syslocale.py index e2aeed9..e48ee82 100644 --- a/collate/syslocale.py +++ b/collate/syslocale.py @@ -22,8 +22,9 @@ Avoid this backend if... """ +__all__ = ["Collator"] + import locale -import re import collate.errors import collate._abcollator @@ -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,25 +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) - - def words(self, string, sep=re.compile(r"\W+", re.UNICODE)): - """Split the string into separate words. - - This split is done using the locale's notion of a word boundry. - """ - return re.split(sep, string) - + except UnicodeError: + return locale.strxfrm(string.str(self.encoding))