Deprecated django.utils.importlib

This was a shim for pre-Python 2.7 support.
This commit is contained in:
Claude Paroz 2013-07-29 15:50:58 +02:00
parent ac09558760
commit fdd7a355bf
38 changed files with 64 additions and 49 deletions

View File

@ -6,6 +6,7 @@ variable, and then from django.conf.global_settings; see the global settings fil
a list of all possible variables. a list of all possible variables.
""" """
import importlib
import logging import logging
import os import os
import sys import sys
@ -15,7 +16,6 @@ import warnings
from django.conf import global_settings from django.conf import global_settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils.functional import LazyObject, empty from django.utils.functional import LazyObject, empty
from django.utils import importlib
from django.utils.module_loading import import_by_path from django.utils.module_loading import import_by_path
from django.utils import six from django.utils import six

View File

@ -1,7 +1,8 @@
from importlib import import_module
from django.core.urlresolvers import (RegexURLPattern, from django.core.urlresolvers import (RegexURLPattern,
RegexURLResolver, LocaleRegexURLResolver) RegexURLResolver, LocaleRegexURLResolver)
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
from django.utils import six from django.utils import six

View File

@ -17,8 +17,8 @@ def autodiscover():
""" """
import copy import copy
from importlib import import_module
from django.conf import settings from django.conf import settings
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule from django.utils.module_loading import module_has_submodule
for app in settings.INSTALLED_APPS: for app in settings.INSTALLED_APPS:

View File

@ -1,3 +1,4 @@
from importlib import import_module
import inspect import inspect
import os import os
import re import re
@ -13,7 +14,6 @@ from django.http import Http404
from django.core import urlresolvers from django.core import urlresolvers
from django.contrib.admindocs import utils from django.contrib.admindocs import utils
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.utils.importlib import import_module
from django.utils._os import upath from django.utils._os import upath
from django.utils import six from django.utils import six
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _

View File

@ -3,11 +3,11 @@ from __future__ import unicode_literals
import base64 import base64
import binascii import binascii
import hashlib import hashlib
import importlib
from django.dispatch import receiver from django.dispatch import receiver
from django.conf import settings from django.conf import settings
from django.test.signals import setting_changed from django.test.signals import setting_changed
from django.utils import importlib
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from django.utils.encoding import force_bytes, force_str, force_text from django.utils.encoding import force_bytes, force_str, force_text
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured

View File

@ -1,10 +1,10 @@
from importlib import import_module
import warnings import warnings
from django.conf import settings from django.conf import settings
from django.core import urlresolvers from django.core import urlresolvers
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.contrib.comments.models import Comment from django.contrib.comments.models import Comment
from django.contrib.comments.forms import CommentForm from django.contrib.comments.forms import CommentForm
from django.utils.importlib import import_module
warnings.warn("django.contrib.comments is deprecated and will be removed before Django 1.8.", DeprecationWarning) warnings.warn("django.contrib.comments is deprecated and will be removed before Django 1.8.", DeprecationWarning)

View File

@ -1,8 +1,8 @@
from datetime import datetime from datetime import datetime
from importlib import import_module
from django.http import HttpRequest from django.http import HttpRequest
from django.conf import settings from django.conf import settings
from django.utils.importlib import import_module
from django.contrib.auth.models import User from django.contrib.auth.models import User

View File

@ -1,11 +1,12 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from importlib import import_module
from django import forms, http from django import forms, http
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils.importlib import import_module
from django.contrib.auth.models import User from django.contrib.auth.models import User

View File

@ -1,11 +1,12 @@
from importlib import import_module
from django.conf import settings from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
geom_backend = getattr(settings, 'GEOMETRY_BACKEND', 'geos') geom_backend = getattr(settings, 'GEOMETRY_BACKEND', 'geos')
try: try:
module = import_module('.%s' % geom_backend, 'django.contrib.gis.geometry.backend') module = import_module('django.contrib.gis.geometry.backend.%s' % geom_backend)
except ImportError: except ImportError:
try: try:
module = import_module(geom_backend) module = import_module(geom_backend)

View File

@ -1,6 +1,7 @@
from importlib import import_module
from django.conf import settings from django.conf import settings
from django.core.management.base import NoArgsCommand from django.core.management.base import NoArgsCommand
from django.utils.importlib import import_module
class Command(NoArgsCommand): class Command(NoArgsCommand):

View File

@ -1,9 +1,9 @@
from importlib import import_module
import time import time
from django.conf import settings from django.conf import settings
from django.utils.cache import patch_vary_headers from django.utils.cache import patch_vary_headers
from django.utils.http import cookie_date from django.utils.http import cookie_date
from django.utils.importlib import import_module
class SessionMiddleware(object): class SessionMiddleware(object):
def __init__(self): def __init__(self):

View File

@ -1,5 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import hashlib import hashlib
from importlib import import_module
import os import os
import posixpath import posixpath
import re import re
@ -18,7 +19,6 @@ from django.core.files.storage import FileSystemStorage, get_storage_class
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from django.utils.encoding import force_bytes, force_text from django.utils.encoding import force_bytes, force_text
from django.utils.functional import LazyObject from django.utils.functional import LazyObject
from django.utils.importlib import import_module
from django.utils._os import upath from django.utils._os import upath
from django.contrib.staticfiles.utils import check_settings, matches_patterns from django.contrib.staticfiles.utils import check_settings, matches_patterns

View File

@ -14,6 +14,7 @@ cache class.
See docs/topics/cache.txt for information on the public API. See docs/topics/cache.txt for information on the public API.
""" """
import importlib
try: try:
from urllib.parse import parse_qsl from urllib.parse import parse_qsl
except ImportError: # Python 2 except ImportError: # Python 2
@ -24,7 +25,6 @@ from django.core import signals
from django.core.cache.backends.base import ( from django.core.cache.backends.base import (
InvalidCacheBackendError, CacheKeyWarning, BaseCache) InvalidCacheBackendError, CacheKeyWarning, BaseCache)
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils import importlib
from django.utils.module_loading import import_by_path from django.utils.module_loading import import_by_path

View File

@ -1,13 +1,13 @@
import collections import collections
import imp
from importlib import import_module
from optparse import OptionParser, NO_DEFAULT
import os import os
import sys import sys
from optparse import OptionParser, NO_DEFAULT
import imp
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.management.base import BaseCommand, CommandError, handle_default_options from django.core.management.base import BaseCommand, CommandError, handle_default_options
from django.core.management.color import color_style from django.core.management.color import color_style
from django.utils.importlib import import_module
from django.utils import six from django.utils import six
# For backwards compatibility: get_version() used to be in this module. # For backwards compatibility: get_version() used to be in this module.

View File

@ -1,4 +1,5 @@
import sys import sys
from importlib import import_module
from optparse import make_option from optparse import make_option
from django.conf import settings from django.conf import settings
@ -7,7 +8,6 @@ from django.core.management import call_command
from django.core.management.base import NoArgsCommand, CommandError from django.core.management.base import NoArgsCommand, CommandError
from django.core.management.color import no_style from django.core.management.color import no_style
from django.core.management.sql import sql_flush, emit_post_sync_signal from django.core.management.sql import sql_flush, emit_post_sync_signal
from django.utils.importlib import import_module
from django.utils.six.moves import input from django.utils.six.moves import input
from django.utils import six from django.utils import six

View File

@ -1,6 +1,7 @@
from importlib import import_module
from django.core.management.base import CommandError from django.core.management.base import CommandError
from django.core.management.templates import TemplateCommand from django.core.management.templates import TemplateCommand
from django.utils.importlib import import_module
class Command(TemplateCommand): class Command(TemplateCommand):

View File

@ -1,7 +1,8 @@
from importlib import import_module
from django.core.management.base import CommandError from django.core.management.base import CommandError
from django.core.management.templates import TemplateCommand from django.core.management.templates import TemplateCommand
from django.utils.crypto import get_random_string from django.utils.crypto import get_random_string
from django.utils.importlib import import_module
class Command(TemplateCommand): class Command(TemplateCommand):

View File

@ -1,3 +1,4 @@
from importlib import import_module
from optparse import make_option from optparse import make_option
import itertools import itertools
import traceback import traceback
@ -9,7 +10,6 @@ from django.core.management.color import no_style
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal, emit_pre_sync_signal from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal, emit_pre_sync_signal
from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
class Command(NoArgsCommand): class Command(NoArgsCommand):

View File

@ -16,8 +16,9 @@ To add your own serializers, use the SERIALIZATION_MODULES setting::
""" """
import importlib
from django.conf import settings from django.conf import settings
from django.utils import importlib
from django.utils import six from django.utils import six
from django.core.serializers.base import SerializerDoesNotExist from django.core.serializers.base import SerializerDoesNotExist

View File

@ -12,9 +12,9 @@ Run with the extra option "help" for a list of additional options you can
pass to this server. pass to this server.
""" """
import importlib
import os import os
import sys import sys
from django.utils import importlib
__version__ = "0.1" __version__ = "0.1"
__all__ = ["runfastcgi"] __all__ = ["runfastcgi"]

View File

@ -8,6 +8,7 @@ a string) and returns a tuple in this format:
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from importlib import import_module
import re import re
from threading import local from threading import local
@ -17,7 +18,6 @@ from django.utils.datastructures import MultiValueDict
from django.utils.encoding import force_str, force_text, iri_to_uri from django.utils.encoding import force_str, force_text, iri_to_uri
from django.utils.functional import memoize, lazy from django.utils.functional import memoize, lazy
from django.utils.http import urlquote from django.utils.http import urlquote
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule from django.utils.module_loading import module_has_submodule
from django.utils.regex_helper import normalize from django.utils.regex_helper import normalize
from django.utils import six from django.utils import six

View File

@ -9,6 +9,7 @@ except ImportError:
from django.utils.six.moves import _dummy_thread as thread from django.utils.six.moves import _dummy_thread as thread
from collections import namedtuple from collections import namedtuple
from contextlib import contextmanager from contextlib import contextmanager
from importlib import import_module
from django.conf import settings from django.conf import settings
from django.db import DEFAULT_DB_ALIAS from django.db import DEFAULT_DB_ALIAS
@ -17,7 +18,6 @@ from django.db.backends import util
from django.db.transaction import TransactionManagementError from django.db.transaction import TransactionManagementError
from django.db.utils import DatabaseErrorWrapper from django.db.utils import DatabaseErrorWrapper
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.importlib import import_module
from django.utils import six from django.utils import six
from django.utils import timezone from django.utils import timezone

View File

@ -1,17 +1,17 @@
"Utilities for loading models and the modules that contain them." "Utilities for loading models and the modules that contain them."
import imp
from importlib import import_module
import os
import sys
from django.conf import settings from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule from django.utils.module_loading import module_has_submodule
from django.utils._os import upath from django.utils._os import upath
from django.utils import six from django.utils import six
import imp
import sys
import os
__all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models', __all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models',
'load_app', 'app_cache_ready') 'load_app', 'app_cache_ready')
@ -100,7 +100,7 @@ class AppCache(object):
self.nesting_level += 1 self.nesting_level += 1
app_module = import_module(app_name) app_module = import_module(app_name)
try: try:
models = import_module('.' + MODELS_MODULE_NAME, app_name) models = import_module('%s.%s' % (app_name, MODELS_MODULE_NAME))
except ImportError: except ImportError:
self.nesting_level -= 1 self.nesting_level -= 1
# If the app doesn't have a models module, we can just ignore the # If the app doesn't have a models module, we can just ignore the

View File

@ -1,4 +1,5 @@
from functools import wraps from functools import wraps
from importlib import import_module
import os import os
import pkgutil import pkgutil
from threading import local from threading import local
@ -7,7 +8,6 @@ import warnings
from django.conf import settings from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.importlib import import_module
from django.utils.module_loading import import_by_path from django.utils.module_loading import import_by_path
from django.utils._os import upath from django.utils._os import upath
from django.utils import six from django.utils import six
@ -104,7 +104,7 @@ class DatabaseErrorWrapper(object):
def load_backend(backend_name): def load_backend(backend_name):
# Look for a fully qualified database backend name # Look for a fully qualified database backend name
try: try:
return import_module('.base', backend_name) return import_module('%s.base' % backend_name)
except ImportError as e_user: except ImportError as e_user:
# The database backend wasn't found. Display a helpful error message # The database backend wasn't found. Display a helpful error message
# listing all possible (built-in) database backends. # listing all possible (built-in) database backends.

View File

@ -2,12 +2,12 @@ from __future__ import absolute_import, unicode_literals
import re import re
from functools import partial from functools import partial
from importlib import import_module
from inspect import getargspec from inspect import getargspec
from django.conf import settings from django.conf import settings
from django.template.context import (Context, RequestContext, from django.template.context import (Context, RequestContext,
ContextPopException) ContextPopException)
from django.utils.importlib import import_module
from django.utils.itercompat import is_iterable from django.utils.itercompat import is_iterable
from django.utils.text import (smart_split, unescape_string_literal, from django.utils.text import (smart_split, unescape_string_literal,
get_text_list) get_text_list)

View File

@ -3,6 +3,7 @@ Wrapper for loading templates from "templates" directories in INSTALLED_APPS
packages. packages.
""" """
from importlib import import_module
import os import os
import sys import sys
@ -11,7 +12,6 @@ from django.core.exceptions import ImproperlyConfigured
from django.template.base import TemplateDoesNotExist from django.template.base import TemplateDoesNotExist
from django.template.loader import BaseLoader from django.template.loader import BaseLoader
from django.utils._os import safe_join from django.utils._os import safe_join
from django.utils.importlib import import_module
from django.utils import six from django.utils import six
# At compile time, cache the directories to search. # At compile time, cache the directories to search.

View File

@ -5,6 +5,7 @@ import os
import re import re
import mimetypes import mimetypes
from copy import copy from copy import copy
from importlib import import_module
from io import BytesIO from io import BytesIO
try: try:
from urllib.parse import unquote, urlparse, urlsplit from urllib.parse import unquote, urlparse, urlsplit
@ -25,7 +26,6 @@ from django.test import signals
from django.utils.functional import curry from django.utils.functional import curry
from django.utils.encoding import force_bytes, force_str from django.utils.encoding import force_bytes, force_str
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils.importlib import import_module
from django.utils.itercompat import is_iterable from django.utils.itercompat import is_iterable
from django.utils import six from django.utils import six
from django.test.utils import ContextList from django.test.utils import ContextList

View File

@ -3,6 +3,7 @@ This module is pending deprecation as of Django 1.6 and will be removed in
version 1.8. version 1.8.
""" """
from importlib import import_module
import json import json
import re import re
import unittest as real_unittest import unittest as real_unittest
@ -15,7 +16,6 @@ from django.test.utils import compare_xml, strip_quotes
# django.utils.unittest is deprecated, but so is django.test.simple, # django.utils.unittest is deprecated, but so is django.test.simple,
# and the latter will be removed before the former. # and the latter will be removed before the former.
from django.utils import unittest from django.utils import unittest
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule from django.utils.module_loading import module_has_submodule
__all__ = ('DjangoTestSuiteRunner',) __all__ = ('DjangoTestSuiteRunner',)

View File

@ -1,10 +1,10 @@
import decimal import decimal
import datetime import datetime
from importlib import import_module
import unicodedata import unicodedata
from django.conf import settings from django.conf import settings
from django.utils import dateformat, numberformat, datetime_safe from django.utils import dateformat, numberformat, datetime_safe
from django.utils.importlib import import_module
from django.utils.encoding import force_str from django.utils.encoding import force_str
from django.utils.functional import lazy from django.utils.functional import lazy
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
@ -54,7 +54,7 @@ def iter_format_modules(lang):
for location in format_locations: for location in format_locations:
for loc in locales: for loc in locales:
try: try:
yield import_module('.formats', location % loc) yield import_module('%s.formats' % (location % loc))
except ImportError: except ImportError:
pass pass

View File

@ -1,6 +1,11 @@
# Taken from Python 2.7 with permission from/by the original author. # Taken from Python 2.7 with permission from/by the original author.
import warnings
import sys import sys
warnings.warn("django.utils.importlib will be removed in Django 1.9.",
PendingDeprecationWarning, stacklevel=2)
def _resolve_name(name, package, level): def _resolve_name(name, package, level):
"""Return the absolute name of the module to be imported.""" """Return the absolute name of the module to be imported."""
if not hasattr(package, 'rindex'): if not hasattr(package, 'rindex'):

View File

@ -1,10 +1,10 @@
import imp import imp
from importlib import import_module
import os import os
import sys import sys
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils import six from django.utils import six
from django.utils.importlib import import_module
def import_by_path(dotted_path, error_prefix=''): def import_by_path(dotted_path, error_prefix=''):

View File

@ -6,10 +6,10 @@ import os
import re import re
import sys import sys
import gettext as gettext_module import gettext as gettext_module
from importlib import import_module
from threading import local from threading import local
import warnings import warnings
from django.utils.importlib import import_module
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from django.utils.encoding import force_str, force_text from django.utils.encoding import force_str, force_text
from django.utils.functional import memoize from django.utils.functional import memoize

View File

@ -1,3 +1,4 @@
import importlib
import json import json
import os import os
import gettext as gettext_module import gettext as gettext_module
@ -5,7 +6,6 @@ import gettext as gettext_module
from django import http from django import http
from django.conf import settings from django.conf import settings
from django.template import Context, Template from django.template import Context, Template
from django.utils import importlib
from django.utils.translation import check_for_language, to_locale, get_language from django.utils.translation import check_for_language, to_locale, get_language
from django.utils.encoding import smart_text from django.utils.encoding import smart_text
from django.utils.formats import get_format_modules, get_format from django.utils.formats import get_format_modules, get_format

View File

@ -412,6 +412,8 @@ these changes.
* ``django.utils.dictconfig`` will be removed. * ``django.utils.dictconfig`` will be removed.
* ``django.utils.importlib`` will be removed.
* ``django.utils.unittest`` will be removed. * ``django.utils.unittest`` will be removed.
* If models are organized in a package, Django will no longer look for * If models are organized in a package, Django will no longer look for

View File

@ -122,11 +122,12 @@ Miscellaneous
Features deprecated in 1.7 Features deprecated in 1.7
========================== ==========================
``django.utils.dictconfig`` ``django.utils.dictconfig``/``django.utils.importlib``
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``django.utils.dictconfig`` was a copy of :mod:`logging.config` provided for ``django.utils.dictconfig`` and ``django.utils.importlib`` were copies of
Python versions prior to 2.7. It has been deprecated. respectively :mod:`logging.config` and :mod:`importlib` provided for Python
versions prior to 2.7. They have been deprecated.
``django.utils.unittest`` ``django.utils.unittest``
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals
import datetime import datetime
import decimal import decimal
from importlib import import_module
import os import os
import pickle import pickle
from threading import local from threading import local
@ -17,7 +18,6 @@ from django.utils import translation
from django.utils.formats import (get_format, date_format, time_format, from django.utils.formats import (get_format, date_format, time_format,
localize, localize_input, iter_format_modules, get_format_modules, localize, localize_input, iter_format_modules, get_format_modules,
number_format, reset_format_cache, sanitize_separators) number_format, reset_format_cache, sanitize_separators)
from django.utils.importlib import import_module
from django.utils.numberformat import format as nformat from django.utils.numberformat import format as nformat
from django.utils._os import upath from django.utils._os import upath
from django.utils.safestring import mark_safe, SafeBytes, SafeString, SafeText from django.utils.safestring import mark_safe, SafeBytes, SafeString, SafeText

View File

@ -3,6 +3,7 @@ Tests for django test runner
""" """
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
from importlib import import_module
from optparse import make_option from optparse import make_option
import sys import sys
import unittest import unittest
@ -13,7 +14,6 @@ from django import db
from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature
from django.test.testcases import connections_support_transactions from django.test.testcases import connections_support_transactions
from django.test.utils import IgnoreAllDeprecationWarningsMixin from django.test.utils import IgnoreAllDeprecationWarningsMixin
from django.utils.importlib import import_module
from admin_scripts.tests import AdminScriptTestCase from admin_scripts.tests import AdminScriptTestCase
from .models import Person from .models import Person

View File

@ -1,11 +1,11 @@
import imp import imp
from importlib import import_module
import os import os
import sys import sys
import unittest import unittest
from zipimport import zipimporter from zipimport import zipimporter
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
from django.utils.module_loading import import_by_path, module_has_submodule from django.utils.module_loading import import_by_path, module_has_submodule
from django.utils._os import upath from django.utils._os import upath