diff options
| author | Olivier Dony <odo@odoo.com> | 2018-07-23 16:15:10 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@odoo.com> | 2018-07-23 16:15:10 +0200 |
| commit | 21bb14d17764f16ca2727622d7892d38104e2ec3 (patch) | |
| tree | 6203afab7b4c199e2c70c6caca56ab2e76dc8f25 /odoo/tools/misc.py | |
| parent | 1e42cbc1f425d31bbc83f3994f3bd8836aa201a2 (diff) | |
[FIX] base: always preload dateutil
The dateutil package uses lazy import to selectively expose its
features: `parser`, `relativedelta`, `rrule`, `tz`.
Depending on installed modules and order of initialization, there was no
guarantee that a given feature was already loaded during the preparation
of the action context.
This patch ensures that we always preload the feature set we need, and
only that feature set. This way we have a consistent `dateutil` lib in
the action context at all times.
Diffstat (limited to 'odoo/tools/misc.py')
| -rw-r--r-- | odoo/tools/misc.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py index 17518ce1525..a036932f6fc 100644 --- a/odoo/tools/misc.py +++ b/odoo/tools/misc.py @@ -1151,3 +1151,23 @@ pickle.load = _pickle_load pickle.loads = lambda text, encoding='ASCII': _pickle_load(io.BytesIO(text), encoding=encoding) pickle.dump = pickle_.dump pickle.dumps = pickle_.dumps + +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() |
