Commit 3ddd714c authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: ZODB Components: New Exception ModuleNotFoundError which avoids a hack in Python2.

parent 88f40296
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
# There is absolutely no reason to use relative imports when loading a Component # There is absolutely no reason to use relative imports when loading a Component
from __future__ import absolute_import from __future__ import absolute_import
import six
import sys import sys
import imp import imp
import collections import collections
...@@ -51,6 +52,12 @@ class ComponentVersionPackage(ModuleType): ...@@ -51,6 +52,12 @@ class ComponentVersionPackage(ModuleType):
""" """
__path__ = [] __path__ = []
try:
ModuleNotFoundError
except NameError: # < 3.6
class ModuleNotFoundError(ImportError):
pass
class ComponentDynamicPackage(ModuleType): class ComponentDynamicPackage(ModuleType):
""" """
A top-level component is a package as it contains modules, this is required A top-level component is a package as it contains modules, this is required
...@@ -420,8 +427,10 @@ class ComponentDynamicPackage(ModuleType): ...@@ -420,8 +427,10 @@ class ComponentDynamicPackage(ModuleType):
# load_module(), and returning module 'name' in contrary to __import__ # load_module(), and returning module 'name' in contrary to __import__
# returning 'erp5' (requiring fromlist parameter which is slower) # returning 'erp5' (requiring fromlist parameter which is slower)
return import_module(fullname) return import_module(fullname)
except ModuleNotFoundError:
pass
except ImportError as e: except ImportError as e:
if str(e) != "No module named " + name: if six.PY3 or str(e) != "No module named " + name:
LOG("ERP5Type.dynamic", WARNING, LOG("ERP5Type.dynamic", WARNING,
"Could not load Component module %r" % fullname, error=True) "Could not load Component module %r" % fullname, error=True)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment