1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import locale
20
21 from choice_tree import ChoiceTree
22
23 try:
24 import xml.dom
25 except ImportError:
26 pass
27
28
30 """Class for representing and comparing locale settings.
31 """
32
34 self.lang = None
35 self.country = None
36
37 if a_string is not None and len (a_string) >= 2:
38 self.lang = a_string[0:2]
39 if len (a_string) >= 5:
40 self.country = a_string[3:5]
41
42 self.__hash = hash (str (self))
43
47 fromDomElement = staticmethod (fromDomElement)
48
50 return Locale (locale.getdefaultlocale ()[0])
51 fromEnv = staticmethod (fromEnv)
52
53
55 if other.lang is None:
56 return True
57 else:
58 if self.lang == other.lang and other.country is None:
59 return True
60 else:
61 return False
62
65
67 try:
68 return self.lang == other.lang and self.country == self.country
69 except AttributeError:
70 pass
71 return False
72
73
75 if self.lang is None:
76 r = ''
77 elif self.country is None:
78 r = self.lang
79 else:
80 r = '%s_%s' % (self.lang, self.country)
81 return r
82
84 return "Locale('%s')" % str (self)
85
88
89
90 defaultLocale = Locale.fromEnv ()
91
93 """
94 A tree of element stored hierarchically with respect to their locale.
95 The =getBestFit= method returns the best fit element with respect to the
96 default locale.
97 """
98
101
103 if loc.lang is None:
104 return ()
105 elif loc.country is None:
106 return (loc.lang,)
107 else:
108 return (loc.lang, loc.country)
109
110 - def add (self, elt):
113
128