X-Git-Url: https://git.korewanetadesu.com/?p=python-collate.git;a=blobdiff_plain;f=collate%2Ficu%2F__init__.py;h=6d27a6fa95cf2b2690d1a2f50174e4819bc27dc1;hp=6f9647e4141c3238e456a0acdd40a4057da81638;hb=HEAD;hpb=2a37219e2d9c0fe58e78d987a21f6e37cfd33940 diff --git a/collate/icu/__init__.py b/collate/icu/__init__.py index 6f9647e..6d27a6f 100644 --- a/collate/icu/__init__.py +++ b/collate/icu/__init__.py @@ -11,6 +11,8 @@ Avoid this backend if... """ +__all__ = ["Collator"] + import collate._abcollator import collate._locale import collate.errors @@ -21,6 +23,7 @@ class Collator(collate._abcollator.Collator): """ICU-based collation.""" def __init__(self, locale, encoding=None): + super(Collator, self).__init__(locale, encoding) locale, encoding = collate._locale.getpair(locale, encoding) icu_locale = "root" if locale == "C" else locale self._collator = _icu.Collator(icu_locale) @@ -37,9 +40,9 @@ class Collator(collate._abcollator.Collator): self._breaker = _icu.WordBreaker("root") def words(self, string): - if isinstance(string, str): - string = string.decode(self.encoding, 'replace') - return filter(lambda u: not u.isspace(), self._breaker.words(string)) + """Split the string along word boundries.""" + string = self.unicode(string) + return self._breaker.words(string) def key(self, string): """Sort key for a string. @@ -48,18 +51,6 @@ class Collator(collate._abcollator.Collator): instance according to the 'encoding' attribute of the Collator. """ - if isinstance(string, str): - string = string.decode(self.encoding, 'replace') + string = self.unicode(string) return self._collator.key(string) - 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 self._collator.cmp(a, b)