1 |
--- |
2 |
pym/portage/util/locale.py | 30 +++++++++++++++++++++--------- |
3 |
1 file changed, 21 insertions(+), 9 deletions(-) |
4 |
|
5 |
diff --git a/pym/portage/util/locale.py b/pym/portage/util/locale.py |
6 |
index 27a2806..58ecb2a 100644 |
7 |
--- a/pym/portage/util/locale.py |
8 |
+++ b/pym/portage/util/locale.py |
9 |
@@ -27,6 +27,9 @@ locale_categories = ( |
10 |
) |
11 |
|
12 |
|
13 |
+_check_locale_cache = {} |
14 |
+ |
15 |
+ |
16 |
def _check_locale(silent): |
17 |
""" |
18 |
The inner locale check function. |
19 |
@@ -82,17 +85,22 @@ def check_locale(silent=False, env=None): |
20 |
can not be executed due to platform limitations. |
21 |
""" |
22 |
|
23 |
+ if env is not None: |
24 |
+ for v in ("LC_ALL", "LC_CTYPE", "LANG"): |
25 |
+ if v in env: |
26 |
+ mylocale = env[v] |
27 |
+ break |
28 |
+ else: |
29 |
+ mylocale = "C" |
30 |
+ |
31 |
+ try: |
32 |
+ return _check_locale_cache[mylocale] |
33 |
+ except KeyError: |
34 |
+ |
35 |
pid = os.fork() |
36 |
if pid == 0: |
37 |
try: |
38 |
if env is not None: |
39 |
- for v in ("LC_ALL", "LC_CTYPE", "LANG"): |
40 |
- if v in env: |
41 |
- mylocale = env[v] |
42 |
- break |
43 |
- else: |
44 |
- mylocale = "C" |
45 |
- |
46 |
try: |
47 |
locale.setlocale(locale.LC_CTYPE, mylocale) |
48 |
except locale.Error: |
49 |
@@ -109,11 +117,15 @@ def check_locale(silent=False, env=None): |
50 |
|
51 |
pid2, ret = os.waitpid(pid, 0) |
52 |
assert pid == pid2 |
53 |
+ pyret = None |
54 |
if os.WIFEXITED(ret): |
55 |
ret = os.WEXITSTATUS(ret) |
56 |
if ret != 2: |
57 |
- return ret == 0 |
58 |
- return None |
59 |
+ pyret = ret == 0 |
60 |
+ |
61 |
+ if env is not None: |
62 |
+ _check_locale_cache[mylocale] = pyret |
63 |
+ return pyret |
64 |
|
65 |
|
66 |
def split_LC_ALL(env): |
67 |
-- |
68 |
2.6.3 |