summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-13 19:50:50 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-13 19:50:50 +0000
commit9fb1e4762ddbf1e6a449ec611b37d558ab5911cf (patch)
tree9e1e1f30efa965f9513ee18f2e0f3d49ddae2cf5
parent01550dbb932439aef6167bbbf017f4ea2400a52d (diff)
downloadportage-9fb1e4762ddbf1e6a449ec611b37d558ab5911cf.tar.gz
portage-9fb1e4762ddbf1e6a449ec611b37d558ab5911cf.tar.bz2
portage-9fb1e4762ddbf1e6a449ec611b37d558ab5911cf.zip
Add support for unwrapped/overridden attributes in _unicode_module_wrapper().
svn path=/main/trunk/; revision=14017
-rw-r--r--pym/portage/__init__.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 79b0508c5..cac628a6e 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -167,17 +167,24 @@ class _unicode_module_wrapper(object):
"""
Wraps a module and wraps all functions with _unicode_func_wrapper.
"""
- __slots__ = ('_mod',)
+ __slots__ = ('_mod', '_overrides')
- def __init__(self, mod):
+ def __init__(self, mod, overrides=None):
object.__setattr__(self, '_mod', mod)
+ object.__setattr__(self, '_overrides', overrides)
def __getattribute__(self, attr):
result = getattr(object.__getattribute__(self, '_mod'), attr)
- if isinstance(result, type):
+ overrides = object.__getattribute__(self, '_overrides')
+ override = None
+ if overrides is not None:
+ override = overrides.get(id(result))
+ if override is not None:
+ result = override
+ elif isinstance(result, type):
pass
elif type(result) is types.ModuleType:
- result = _unicode_module_wrapper(result)
+ result = _unicode_module_wrapper(result, overrides=overrides)
elif hasattr(result, '__call__'):
result = _unicode_func_wrapper(result)
return result
@@ -189,7 +196,7 @@ if sys.hexversion >= 0x3000000:
return mod
import os
-os = _unicode_module_wrapper(os)
+os = _unicode_module_wrapper(os, overrides={id(os.read):os.read})
import shutil
shutil = _unicode_module_wrapper(shutil)