Typo.
[python-collate.git] / collate / __init__.py
1 import collate.errors
2 import collate._locale
3
4 try:
5 import collate.codepoint as default
6 except ImportError:
7 pass
8 try:
9 import collate.syslocale as default
10 except ImportError:
11 pass
12 try:
13 import collate.icu as default
14 except ImportError:
15 pass
16
17 collator = None
18
19 def set_default(backend=None, locale=None, encoding=None):
20 global collator
21 global default
22
23 if backend is None:
24 backend = default
25 locales = collate._locale.localelist(locale)
26 c = None
27 for locale in locales:
28 locale, encoding_ = collate._locale.getpair(locale, encoding)
29 try:
30 c = backend.Collator(locale, encoding_)
31 except collate.errors.InvalidLocaleError:
32 pass
33 else:
34 break
35 if c is not None:
36 collator = c
37 default = backend
38
39 def key(string):
40 return collator.key(string)
41
42 def cmp(a, b):
43 return collator.cmp(a, b)
44
45 set_default()