3 class Collator(object):
4 def cmp(self
, string1
, string2
):
5 """Return negative if a < b, zero if a == b, positive if a > b."""
6 return cmp(self
.key(string1
), self
.key(string2
))
8 def words(self
, string
):
9 """Split the string along word boundries."""
10 if isinstance(string
, str):
11 string
= string
.decode(self
.encoding
, 'replace')
14 def sortemekey(self
, string
, invalid
=float('inf')):
15 """Return a key based on sortemes of a string.
17 If the string is a str instance, it is decoded to a unicode
18 instance according to the 'encoding' attribute of the
21 if isinstance(string
, str):
22 string
= string
.decode(self
.encoding
, 'replace')
24 # Shove the sortkeyed original string on the end to resolve
26 return (collate
.strings
.sortemes(string
, self
.key
),