1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
import sys
# flake8: noqa
def import_attribute(import_path, exception_handler=None):
try:
from importlib import import_module
except ImportError: # pragma: no cover
from django.utils.importlib import import_module
module_name, object_name = import_path.rsplit('.', 1)
try:
module = import_module(module_name)
except: # pragma: no cover
if callable(exception_handler):
exctype, excvalue, tb = sys.exc_info()
return exception_handler(import_path, exctype, excvalue, tb)
else:
raise
try:
return getattr(module, object_name)
except: # pragma: no cover
if callable(exception_handler):
exctype, excvalue, tb = sys.exc_info()
return exception_handler(import_path, exctype, excvalue, tb)
else:
raise
|