Loading django/conf/__init__.py +2 −3 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ from django.conf import global_settings from django.core.exceptions import ImproperlyConfigured from django.utils.functional import LazyObject, empty from django.utils import importlib from django.utils.module_loading import import_by_path from django.utils import six ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE" Loading Loading @@ -68,9 +69,7 @@ class LazySettings(LazyObject): if self.LOGGING_CONFIG: from django.utils.log import DEFAULT_LOGGING # First find the logging configuration function ... logging_config_path, logging_config_func_name = self.LOGGING_CONFIG.rsplit('.', 1) logging_config_module = importlib.import_module(logging_config_path) logging_config_func = getattr(logging_config_module, logging_config_func_name) logging_config_func = import_by_path(self.LOGGING_CONFIG) logging_config_func(DEFAULT_LOGGING) Loading django/contrib/admin/tests.py +2 −6 Original line number Diff line number Diff line from django.test import LiveServerTestCase from django.utils.importlib import import_module from django.utils.module_loading import import_by_path from django.utils.unittest import SkipTest from django.utils.translation import ugettext as _ Loading @@ -9,11 +9,7 @@ class AdminSeleniumWebDriverTestCase(LiveServerTestCase): @classmethod def setUpClass(cls): try: # Import and start the WebDriver class. module, attr = cls.webdriver_class.rsplit('.', 1) mod = import_module(module) WebDriver = getattr(mod, attr) cls.selenium = WebDriver() cls.selenium = import_by_path(cls.webdriver_class)() except Exception as e: raise SkipTest('Selenium webdriver "%s" not installed or not ' 'operational: %s' % (cls.webdriver_class, str(e))) Loading django/contrib/auth/__init__.py +3 −15 Original line number Diff line number Diff line import re from django.core.exceptions import ImproperlyConfigured, PermissionDenied from django.utils.importlib import import_module from django.contrib.auth.signals import user_logged_in, user_logged_out, user_login_failed from django.core.exceptions import ImproperlyConfigured, PermissionDenied from django.utils.module_loading import import_by_path SESSION_KEY = '_auth_user_id' BACKEND_SESSION_KEY = '_auth_user_backend' Loading @@ -10,19 +10,7 @@ REDIRECT_FIELD_NAME = 'next' def load_backend(path): i = path.rfind('.') module, attr = path[:i], path[i + 1:] try: mod = import_module(module) except ImportError as e: raise ImproperlyConfigured('Error importing authentication backend %s: "%s"' % (path, e)) except ValueError: raise ImproperlyConfigured('Error importing authentication backends. Is AUTHENTICATION_BACKENDS a correctly defined list or tuple?') try: cls = getattr(mod, attr) except AttributeError: raise ImproperlyConfigured('Module "%s" does not define a "%s" authentication backend' % (module, attr)) return cls() return import_by_path(path)() def get_backends(): Loading django/contrib/auth/hashers.py +2 −7 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ from django.utils.encoding import force_bytes, force_str from django.core.exceptions import ImproperlyConfigured from django.utils.crypto import ( pbkdf2, constant_time_compare, get_random_string) from django.utils.module_loading import import_by_path from django.utils.translation import ugettext_noop as _ Loading Loading @@ -84,13 +85,7 @@ def load_hashers(password_hashers=None): if not password_hashers: password_hashers = settings.PASSWORD_HASHERS for backend in password_hashers: try: mod_path, cls_name = backend.rsplit('.', 1) mod = importlib.import_module(mod_path) hasher_cls = getattr(mod, cls_name) except (AttributeError, ImportError, ValueError): raise ImproperlyConfigured("hasher not found: %s" % backend) hasher = hasher_cls() hasher = import_by_path(backend)() if not getattr(hasher, 'algorithm'): raise ImproperlyConfigured("hasher doesn't specify an " "algorithm name: %s" % backend) Loading django/contrib/formtools/tests/wizard/loadstorage.py +4 −8 Original line number Diff line number Diff line from django.test import TestCase from django.contrib.formtools.wizard.storage import (get_storage, MissingStorageModule, MissingStorageClass) from django.contrib.formtools.wizard.storage import get_storage, MissingStorage from django.contrib.formtools.wizard.storage.base import BaseStorage Loading @@ -12,11 +10,9 @@ class TestLoadStorage(TestCase): type(get_storage('django.contrib.formtools.wizard.storage.base.BaseStorage', 'wizard1')), BaseStorage) def test_missing_module(self): self.assertRaises(MissingStorageModule, get_storage, def test_missing_storage(self): self.assertRaises(MissingStorage, get_storage, 'django.contrib.formtools.wizard.storage.idontexist.IDontExistStorage', 'wizard1') def test_missing_class(self): self.assertRaises(MissingStorageClass, get_storage, self.assertRaises(MissingStorage, get_storage, 'django.contrib.formtools.wizard.storage.base.IDontExistStorage', 'wizard1') Loading
django/conf/__init__.py +2 −3 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ from django.conf import global_settings from django.core.exceptions import ImproperlyConfigured from django.utils.functional import LazyObject, empty from django.utils import importlib from django.utils.module_loading import import_by_path from django.utils import six ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE" Loading Loading @@ -68,9 +69,7 @@ class LazySettings(LazyObject): if self.LOGGING_CONFIG: from django.utils.log import DEFAULT_LOGGING # First find the logging configuration function ... logging_config_path, logging_config_func_name = self.LOGGING_CONFIG.rsplit('.', 1) logging_config_module = importlib.import_module(logging_config_path) logging_config_func = getattr(logging_config_module, logging_config_func_name) logging_config_func = import_by_path(self.LOGGING_CONFIG) logging_config_func(DEFAULT_LOGGING) Loading
django/contrib/admin/tests.py +2 −6 Original line number Diff line number Diff line from django.test import LiveServerTestCase from django.utils.importlib import import_module from django.utils.module_loading import import_by_path from django.utils.unittest import SkipTest from django.utils.translation import ugettext as _ Loading @@ -9,11 +9,7 @@ class AdminSeleniumWebDriverTestCase(LiveServerTestCase): @classmethod def setUpClass(cls): try: # Import and start the WebDriver class. module, attr = cls.webdriver_class.rsplit('.', 1) mod = import_module(module) WebDriver = getattr(mod, attr) cls.selenium = WebDriver() cls.selenium = import_by_path(cls.webdriver_class)() except Exception as e: raise SkipTest('Selenium webdriver "%s" not installed or not ' 'operational: %s' % (cls.webdriver_class, str(e))) Loading
django/contrib/auth/__init__.py +3 −15 Original line number Diff line number Diff line import re from django.core.exceptions import ImproperlyConfigured, PermissionDenied from django.utils.importlib import import_module from django.contrib.auth.signals import user_logged_in, user_logged_out, user_login_failed from django.core.exceptions import ImproperlyConfigured, PermissionDenied from django.utils.module_loading import import_by_path SESSION_KEY = '_auth_user_id' BACKEND_SESSION_KEY = '_auth_user_backend' Loading @@ -10,19 +10,7 @@ REDIRECT_FIELD_NAME = 'next' def load_backend(path): i = path.rfind('.') module, attr = path[:i], path[i + 1:] try: mod = import_module(module) except ImportError as e: raise ImproperlyConfigured('Error importing authentication backend %s: "%s"' % (path, e)) except ValueError: raise ImproperlyConfigured('Error importing authentication backends. Is AUTHENTICATION_BACKENDS a correctly defined list or tuple?') try: cls = getattr(mod, attr) except AttributeError: raise ImproperlyConfigured('Module "%s" does not define a "%s" authentication backend' % (module, attr)) return cls() return import_by_path(path)() def get_backends(): Loading
django/contrib/auth/hashers.py +2 −7 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ from django.utils.encoding import force_bytes, force_str from django.core.exceptions import ImproperlyConfigured from django.utils.crypto import ( pbkdf2, constant_time_compare, get_random_string) from django.utils.module_loading import import_by_path from django.utils.translation import ugettext_noop as _ Loading Loading @@ -84,13 +85,7 @@ def load_hashers(password_hashers=None): if not password_hashers: password_hashers = settings.PASSWORD_HASHERS for backend in password_hashers: try: mod_path, cls_name = backend.rsplit('.', 1) mod = importlib.import_module(mod_path) hasher_cls = getattr(mod, cls_name) except (AttributeError, ImportError, ValueError): raise ImproperlyConfigured("hasher not found: %s" % backend) hasher = hasher_cls() hasher = import_by_path(backend)() if not getattr(hasher, 'algorithm'): raise ImproperlyConfigured("hasher doesn't specify an " "algorithm name: %s" % backend) Loading
django/contrib/formtools/tests/wizard/loadstorage.py +4 −8 Original line number Diff line number Diff line from django.test import TestCase from django.contrib.formtools.wizard.storage import (get_storage, MissingStorageModule, MissingStorageClass) from django.contrib.formtools.wizard.storage import get_storage, MissingStorage from django.contrib.formtools.wizard.storage.base import BaseStorage Loading @@ -12,11 +10,9 @@ class TestLoadStorage(TestCase): type(get_storage('django.contrib.formtools.wizard.storage.base.BaseStorage', 'wizard1')), BaseStorage) def test_missing_module(self): self.assertRaises(MissingStorageModule, get_storage, def test_missing_storage(self): self.assertRaises(MissingStorage, get_storage, 'django.contrib.formtools.wizard.storage.idontexist.IDontExistStorage', 'wizard1') def test_missing_class(self): self.assertRaises(MissingStorageClass, get_storage, self.assertRaises(MissingStorage, get_storage, 'django.contrib.formtools.wizard.storage.base.IDontExistStorage', 'wizard1')