aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2015-11-15 23:49:33 +0100
committerMichał Górny <mgorny@gentoo.org>2015-11-15 23:49:33 +0100
commit90ccd027ee56f4ff0afaf67825aceea92ce633a5 (patch)
tree5f6c997d579a45096a8e8a324f87c4e2f59b5250
parentEnable EAPI 6 (diff)
downloadportage-90ccd027ee56f4ff0afaf67825aceea92ce633a5.tar.gz
portage-90ccd027ee56f4ff0afaf67825aceea92ce633a5.tar.bz2
portage-90ccd027ee56f4ff0afaf67825aceea92ce633a5.zip
util/locale: Cache check_locale() results for specific locales
-rw-r--r--pym/portage/util/locale.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/pym/portage/util/locale.py b/pym/portage/util/locale.py
index 27a28068d..58ecb2a43 100644
--- a/pym/portage/util/locale.py
+++ b/pym/portage/util/locale.py
@@ -27,6 +27,9 @@ locale_categories = (
)
+_check_locale_cache = {}
+
+
def _check_locale(silent):
"""
The inner locale check function.
@@ -82,17 +85,22 @@ def check_locale(silent=False, env=None):
can not be executed due to platform limitations.
"""
+ if env is not None:
+ for v in ("LC_ALL", "LC_CTYPE", "LANG"):
+ if v in env:
+ mylocale = env[v]
+ break
+ else:
+ mylocale = "C"
+
+ try:
+ return _check_locale_cache[mylocale]
+ except KeyError:
+
pid = os.fork()
if pid == 0:
try:
if env is not None:
- for v in ("LC_ALL", "LC_CTYPE", "LANG"):
- if v in env:
- mylocale = env[v]
- break
- else:
- mylocale = "C"
-
try:
locale.setlocale(locale.LC_CTYPE, mylocale)
except locale.Error:
@@ -109,11 +117,15 @@ def check_locale(silent=False, env=None):
pid2, ret = os.waitpid(pid, 0)
assert pid == pid2
+ pyret = None
if os.WIFEXITED(ret):
ret = os.WEXITSTATUS(ret)
if ret != 2:
- return ret == 0
- return None
+ pyret = ret == 0
+
+ if env is not None:
+ _check_locale_cache[mylocale] = pyret
+ return pyret
def split_LC_ALL(env):