summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-09-20 18:54:57 +0000
committerZac Medico <zmedico@gentoo.org>2009-09-20 18:54:57 +0000
commitf16b2c8b2c8098d0794e6d1695166c45857c39f6 (patch)
treea2d2e28f4640921b6999740a258886855f519854 /pym
parent284039c4a9aa7d469c9f49adc2c92c2047559ce0 (diff)
downloadportage-f16b2c8b2c8098d0794e6d1695166c45857c39f6.tar.gz
portage-f16b2c8b2c8098d0794e6d1695166c45857c39f6.tar.bz2
portage-f16b2c8b2c8098d0794e6d1695166c45857c39f6.zip
Make _unicode_module_wrapper cache wrappers and reuse them. Thanks to
Marat Radchenko <marat@slonopotamus.org> for this patch from bug #276813. svn path=/main/trunk/; revision=14299
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/__init__.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 8837398cd..4b68cefb2 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -210,14 +210,24 @@ class _unicode_module_wrapper(object):
"""
Wraps a module and wraps all functions with _unicode_func_wrapper.
"""
- __slots__ = ('_mod', '_encoding', '_overrides')
+ __slots__ = ('_mod', '_encoding', '_overrides', '_cache')
- def __init__(self, mod, encoding=_encodings['fs'], overrides=None):
+ def __init__(self, mod, encoding=_encodings['fs'], overrides=None, cache=True):
object.__setattr__(self, '_mod', mod)
object.__setattr__(self, '_encoding', encoding)
object.__setattr__(self, '_overrides', overrides)
+ if cache:
+ cache = {}
+ else:
+ cache = None
+ object.__setattr__(self, '_cache', cache)
def __getattribute__(self, attr):
+ cache = object.__getattribute__(self, '_cache')
+ if cache is not None:
+ result = cache.get(attr)
+ if result is not None:
+ return result
result = getattr(object.__getattribute__(self, '_mod'), attr)
encoding = object.__getattribute__(self, '_encoding')
overrides = object.__getattribute__(self, '_overrides')
@@ -233,6 +243,8 @@ class _unicode_module_wrapper(object):
encoding=encoding, overrides=overrides)
elif hasattr(result, '__call__'):
result = _unicode_func_wrapper(result, encoding=encoding)
+ if cache is not None:
+ cache[attr] = result
return result
import os as _os