1 """Codepoint-based collation.
3 This collation backend sorts using only the basic codepoint order. It
4 is primarily intended to be used as a baseline and example for other
7 Use this collation backend if...
8 - You are writing tests for pycollate.
9 - You are writing specialized Unicode software.
10 - You are on a system with no locale module.
12 Avoid this backend if...
13 - You are writing a normal program for a normal runtime environment.
14 - You are sorting strings to show normal humans.
18 import collate
._abcollator
19 import collate
._locale
23 class Collator(collate
._abcollator
.Collator
):
24 """Codepoint-based collation.
27 locale - all parts but encoding ignored, always 'C'
28 encoding - try to use this string encoding
31 def __init__(self
, locale
=None, encoding
=None):
32 dummy
, self
.encoding
= collate
._locale
.getpair(locale
, encoding
)
35 def key(self
, string
):
36 """Sort key for a string.
38 If string is a str instance, it is first decoded according to
39 the 'encoding' attribute of the Collator.
41 if isinstance(string
, str):
42 string
= string
.decode(self
.encoding
, 'replace')