Fix some pychecker errors.
[python-collate.git] / collate / _abcollator.py
1 import collate.strings
2
3 class Collator(object):
4 encoding = "ascii"
5
6 def cmp(self, string1, string2):
7 """Return negative if a < b, zero if a == b, positive if a > b."""
8 return cmp(self.key(string1), self.key(string2))
9
10 def key(self, string):
11 return string
12
13 def words(self, string):
14 """Split the string along word boundries."""
15 if isinstance(string, str):
16 string = string.decode(self.encoding, 'replace')
17 return string.split()
18
19 def sortemekey(self, string):
20 """Return a key based on sortemes of a string.
21
22 If the string is a str instance, it is decoded to a unicode
23 instance according to the 'encoding' attribute of the
24 Collator.
25 """
26 if isinstance(string, str):
27 string = string.decode(self.encoding, 'replace')
28
29 # Shove the sortkeyed original string on the end to resolve
30 # ties intelligently.
31 return (collate.strings.sortemes(string, self.key),
32 self.key(string))
33