diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-08-07 17:01:16 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-08-07 17:01:16 +0200 |
| commit | 65a80cf3fd2fd0c47c774ac9cc183d9d3bc4af55 (patch) | |
| tree | df78f525ff8140df45de948a02203d63c1108c54 /odoo/tools/misc.py | |
| parent | 43eca3079e488683983cd6ac2161c828b676f697 (diff) | |
| parent | 0c5cbbe0bb4209dd6924494cd0c4d07dd3892b9e (diff) | |
[MERGE] forward port branch saas-14 up to 0c5cbbe0bb4
Diffstat (limited to 'odoo/tools/misc.py')
| -rw-r--r-- | odoo/tools/misc.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py index 05c772e71e4..2e0bc23ed30 100644 --- a/odoo/tools/misc.py +++ b/odoo/tools/misc.py @@ -21,6 +21,7 @@ import socket import sys import threading import time +import types import werkzeug.utils import zipfile from cStringIO import StringIO @@ -1253,3 +1254,23 @@ class Pickle(object): dump = cPickle.dump pickle = Pickle + +def wrap_module(module, attr_list): + """Helper for wrapping a package/module to expose selected attributes + + :param Module module: the actual package/module to wrap, as returned by ``import <module>`` + :param iterable attr_list: a global list of attributes to expose, usually the top-level + attributes and their own main attributes. No support for hiding attributes in case + of name collision at different levels. + """ + attr_list = set(attr_list) + class WrappedModule(object): + def __getattr__(self, attrib): + if attrib in attr_list: + target = getattr(module, attrib) + if isinstance(target, types.ModuleType): + return wrap_module(target, attr_list) + return target + raise AttributeError(attrib) + # module and attr_list are in the closure + return WrappedModule() |
