diff --git a/wagtail/contrib/wagtailfrontendcache/utils.py b/wagtail/contrib/wagtailfrontendcache/utils.py index 18d57afd4..8f0217bfb 100644 --- a/wagtail/contrib/wagtailfrontendcache/utils.py +++ b/wagtail/contrib/wagtailfrontendcache/utils.py @@ -1,15 +1,8 @@ import logging -try: - from importlib import import_module -except ImportError: - # for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7) - from django.utils.importlib import import_module - -import sys - from django.utils import six from django.conf import settings +from django.utils.module_loading import import_string from django.core.exceptions import ImproperlyConfigured @@ -20,30 +13,6 @@ class InvalidFrontendCacheBackendError(ImproperlyConfigured): pass -# Pinched from django 1.7 source code. -# TODO: Replace this with "from django.utils.module_loading import import_string" -# when django 1.7 is released -def import_string(dotted_path): - """ - Import a dotted module path and return the attribute/class designated by the - last name in the path. Raise ImportError if the import failed. - """ - try: - module_path, class_name = dotted_path.rsplit('.', 1) - except ValueError: - msg = "%s doesn't look like a module path" % dotted_path - six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) - - module = import_module(module_path) - - try: - return getattr(module, class_name) - except AttributeError: - msg = 'Module "%s" does not define a "%s" attribute/class' % ( - dotted_path, class_name) - six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) - - def get_backends(backend_settings=None, backends=None): # Get backend settings from WAGTAILFRONTENDCACHE setting if backend_settings is None: diff --git a/wagtail/wagtailembeds/embeds.py b/wagtail/wagtailembeds/embeds.py index b78027e67..c41611d70 100644 --- a/wagtail/wagtailembeds/embeds.py +++ b/wagtail/wagtailembeds/embeds.py @@ -1,14 +1,6 @@ -import sys from datetime import datetime import json -try: - from importlib import import_module -except ImportError: - # for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7) - from django.utils.importlib import import_module - - # Needs to be imported like this to allow @patch to work in tests from six.moves.urllib import request as urllib_request @@ -16,6 +8,7 @@ from six.moves.urllib.request import Request from six.moves.urllib.error import URLError from six.moves.urllib.parse import urlencode +from django.utils.module_loading import import_string from django.conf import settings from django.utils import six @@ -23,35 +16,11 @@ from wagtail.wagtailembeds.oembed_providers import get_oembed_provider from wagtail.wagtailembeds.models import Embed - class EmbedNotFoundException(Exception): pass class EmbedlyException(Exception): pass class AccessDeniedEmbedlyException(EmbedlyException): pass -# Pinched from django 1.7 source code. -# TODO: Replace this with "from django.utils.module_loading import import_string" when django 1.7 is released -def import_string(dotted_path): - """ - Import a dotted module path and return the attribute/class designated by the - last name in the path. Raise ImportError if the import failed. - """ - try: - module_path, class_name = dotted_path.rsplit('.', 1) - except ValueError: - msg = "%s doesn't look like a module path" % dotted_path - six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) - - module = import_module(module_path) - - try: - return getattr(module, class_name) - except AttributeError: - msg = 'Module "%s" does not define a "%s" attribute/class' % ( - dotted_path, class_name) - six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) - - def embedly(url, max_width=None, key=None): from embedly import Embedly diff --git a/wagtail/wagtailimages/backends/__init__.py b/wagtail/wagtailimages/backends/__init__.py index e60b89688..c13504006 100644 --- a/wagtail/wagtailimages/backends/__init__.py +++ b/wagtail/wagtailimages/backends/__init__.py @@ -2,46 +2,15 @@ # Based on the Django cache framework and wagtailsearch # https://github.com/django/django/blob/5d263dee304fdaf95e18d2f0619d6925984a7f02/django/core/cache/__init__.py -try: - from importlib import import_module -except ImportError: - # for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7) - from django.utils.importlib import import_module -import sys - -from django.utils import six -from django.conf import settings +from django.utils.module_loading import import_string from django.core.exceptions import ImproperlyConfigured +from django.conf import settings class InvalidImageBackendError(ImproperlyConfigured): pass -# Pinched from django 1.7 source code. -# TODO: Replace this with "from django.utils.module_loading import import_string" -# when django 1.7 is released -# TODO: This is not DRY - should be imported from a utils module -def import_string(dotted_path): - """ - Import a dotted module path and return the attribute/class designated by the - last name in the path. Raise ImportError if the import failed. - """ - try: - module_path, class_name = dotted_path.rsplit('.', 1) - except ValueError: - msg = "%s doesn't look like a module path" % dotted_path - six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) - - module = import_module(module_path) - - try: - return getattr(module, class_name) - except AttributeError: - msg = 'Module "%s" does not define a "%s" attribute/class' % ( - dotted_path, class_name) - six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) - def get_image_backend(backend='default', **kwargs): # Get configuration diff --git a/wagtail/wagtailsearch/backends/__init__.py b/wagtail/wagtailsearch/backends/__init__.py index a06f7a4f8..fa6fcf017 100644 --- a/wagtail/wagtailsearch/backends/__init__.py +++ b/wagtail/wagtailsearch/backends/__init__.py @@ -2,47 +2,16 @@ # Based on the Django cache framework # https://github.com/django/django/blob/5d263dee304fdaf95e18d2f0619d6925984a7f02/django/core/cache/__init__.py -try: - from importlib import import_module -except ImportError: - # for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7) - from django.utils.importlib import import_module -import sys - -from django.utils import six -from django.conf import settings +from django.utils.module_loading import import_string from django.core.exceptions import ImproperlyConfigured +from django.conf import settings class InvalidSearchBackendError(ImproperlyConfigured): pass -# Pinched from django 1.7 source code. -# TODO: Replace this with "from django.utils.module_loading import import_string" -# when django 1.7 is released -def import_string(dotted_path): - """ - Import a dotted module path and return the attribute/class designated by the - last name in the path. Raise ImportError if the import failed. - """ - try: - module_path, class_name = dotted_path.rsplit('.', 1) - except ValueError: - msg = "%s doesn't look like a module path" % dotted_path - six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) - - module = import_module(module_path) - - try: - return getattr(module, class_name) - except AttributeError: - msg = 'Module "%s" does not define a "%s" attribute/class' % ( - dotted_path, class_name) - six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) - - def get_search_backend(backend='default', **kwargs): # Get configuration default_conf = {