Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #2968 -- Changed arguments to __import__ to use empty dictionar…

…y instead of empty string, for stricter compliance with Python library reference. Thanks for the patch, Yasushi Masuda

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3951 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 41d11a685f6563c175902fad6e39a55c01c49a0b 1 parent 6d1335c
@adrianholovaty adrianholovaty authored
View
4 django/conf/__init__.py
@@ -77,7 +77,7 @@ def __init__(self, settings_module):
self.SETTINGS_MODULE = settings_module
try:
- mod = __import__(self.SETTINGS_MODULE, '', '', [''])
+ mod = __import__(self.SETTINGS_MODULE, {}, {}, [''])
except ImportError, e:
raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
@@ -97,7 +97,7 @@ def __init__(self, settings_module):
new_installed_apps = []
for app in self.INSTALLED_APPS:
if app.endswith('.*'):
- appdir = os.path.dirname(__import__(app[:-2], '', '', ['']).__file__)
+ appdir = os.path.dirname(__import__(app[:-2], {}, {}, ['']).__file__)
for d in os.listdir(appdir):
if d.isalpha() and os.path.isdir(os.path.join(appdir, d)):
new_installed_apps.append('%s.%s' % (app[:-2], d))
View
8 django/contrib/admin/views/doc.py
@@ -98,13 +98,13 @@ def view_index(request):
return missing_docutils_page(request)
if settings.ADMIN_FOR:
- settings_modules = [__import__(m, '', '', ['']) for m in settings.ADMIN_FOR]
+ settings_modules = [__import__(m, {}, {}, ['']) for m in settings.ADMIN_FOR]
else:
settings_modules = [settings]
views = []
for settings_mod in settings_modules:
- urlconf = __import__(settings_mod.ROOT_URLCONF, '', '', [''])
+ urlconf = __import__(settings_mod.ROOT_URLCONF, {}, {}, [''])
view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
if Site._meta.installed:
site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
@@ -127,7 +127,7 @@ def view_detail(request, view):
mod, func = urlresolvers.get_mod_func(view)
try:
- view_func = getattr(__import__(mod, '', '', ['']), func)
+ view_func = getattr(__import__(mod, {}, {}, ['']), func)
except (ImportError, AttributeError):
raise Http404
title, body, metadata = utils.parse_docstring(view_func.__doc__)
@@ -235,7 +235,7 @@ def model_detail(request, app_label, model_name):
def template_detail(request, template):
templates = []
for site_settings_module in settings.ADMIN_FOR:
- settings_mod = __import__(site_settings_module, '', '', [''])
+ settings_mod = __import__(site_settings_module, {}, {}, [''])
if Site._meta.installed:
site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
else:
View
2  django/contrib/admin/views/template.py
@@ -14,7 +14,7 @@ def template_validator(request):
# get a dict of {site_id : settings_module} for the validator
settings_modules = {}
for mod in settings.ADMIN_FOR:
- settings_module = __import__(mod, '', '', [''])
+ settings_module = __import__(mod, {}, {}, [''])
settings_modules[settings_module.SITE_ID] = settings_module
manipulator = TemplateValidator(settings_modules)
new_data, errors = {}, {}
View
2  django/contrib/auth/__init__.py
@@ -9,7 +9,7 @@ def load_backend(path):
i = path.rfind('.')
module, attr = path[:i], path[i+1:]
try:
- mod = __import__(module, '', '', [attr])
+ mod = __import__(module, {}, {}, [attr])
except ImportError, e:
raise ImproperlyConfigured, 'Error importing authentication backend %s: "%s"' % (module, e)
try:
View
2  django/core/cache/__init__.py
@@ -48,7 +48,7 @@ def get_cache(backend_uri):
if host.endswith('/'):
host = host[:-1]
- cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], '', '', ['']), 'CacheClass')
+ cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']), 'CacheClass')
return cache_class(host, params)
cache = get_cache(settings.CACHE_BACKEND)
View
2  django/core/handlers/base.py
@@ -26,7 +26,7 @@ def load_middleware(self):
raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path
mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:]
try:
- mod = __import__(mw_module, '', '', [''])
+ mod = __import__(mw_module, {}, {}, [''])
except ImportError, e:
raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e)
try:
View
6 django/core/management.py
@@ -446,7 +446,7 @@ def syncdb(verbosity=1, interactive=True):
# dispatcher events.
for app_name in settings.INSTALLED_APPS:
try:
- __import__(app_name + '.management', '', '', [''])
+ __import__(app_name + '.management', {}, {}, [''])
except ImportError:
pass
@@ -1230,7 +1230,7 @@ def test(app_labels, verbosity=1):
test_module_name = '.'.join(test_path[:-1])
else:
test_module_name = '.'
- test_module = __import__(test_module_name, [],[],test_path[-1])
+ test_module = __import__(test_module_name, {}, {}, test_path[-1])
test_runner = getattr(test_module, test_path[-1])
test_runner(app_list, verbosity)
@@ -1419,7 +1419,7 @@ def setup_environ(settings_mod):
project_directory = os.path.dirname(settings_mod.__file__)
project_name = os.path.basename(project_directory)
sys.path.append(os.path.join(project_directory, '..'))
- project_module = __import__(project_name, '', '', [''])
+ project_module = __import__(project_name, {}, {}, [''])
sys.path.pop()
# Set DJANGO_SETTINGS_MODULE appropriately.
View
2  django/core/serializers/__init__.py
@@ -29,7 +29,7 @@
def register_serializer(format, serializer_module):
"""Register a new serializer by passing in a module name."""
- module = __import__(serializer_module, '', '', [''])
+ module = __import__(serializer_module, {}, {}, [''])
_serializers[format] = module
def unregister_serializer(format):
View
10 django/core/urlresolvers.py
@@ -119,7 +119,7 @@ def _get_callback(self):
return self._callback
mod_name, func_name = get_mod_func(self._callback_str)
try:
- self._callback = getattr(__import__(mod_name, '', '', ['']), func_name)
+ self._callback = getattr(__import__(mod_name, {}, {}, ['']), func_name)
except ImportError, e:
raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e))
except AttributeError, e:
@@ -130,7 +130,7 @@ def _get_callback(self):
def reverse(self, viewname, *args, **kwargs):
mod_name, func_name = get_mod_func(viewname)
try:
- lookup_view = getattr(__import__(mod_name, '', '', ['']), func_name)
+ lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
except (ImportError, AttributeError):
raise NoReverseMatch
if lookup_view != self.callback:
@@ -171,7 +171,7 @@ def _get_urlconf_module(self):
return self._urlconf_module
except AttributeError:
try:
- self._urlconf_module = __import__(self.urlconf_name, '', '', [''])
+ self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
except ValueError, e:
# Invalid urlconf_name, such as "foo.bar." (note trailing period)
raise ImproperlyConfigured, "Error while importing URLconf %r: %s" % (self.urlconf_name, e)
@@ -186,7 +186,7 @@ def _resolve_special(self, view_type):
callback = getattr(self.urlconf_module, 'handler%s' % view_type)
mod_name, func_name = get_mod_func(callback)
try:
- return getattr(__import__(mod_name, '', '', ['']), func_name), {}
+ return getattr(__import__(mod_name, {}, {}, ['']), func_name), {}
except (ImportError, AttributeError), e:
raise ViewDoesNotExist, "Tried %s. Error was: %s" % (callback, str(e))
@@ -200,7 +200,7 @@ def reverse(self, lookup_view, *args, **kwargs):
if not callable(lookup_view):
mod_name, func_name = get_mod_func(lookup_view)
try:
- lookup_view = getattr(__import__(mod_name, '', '', ['']), func_name)
+ lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
except (ImportError, AttributeError):
raise NoReverseMatch
for pattern in self.urlconf_module.urlpatterns:
View
8 django/db/__init__.py
@@ -8,7 +8,7 @@
settings.DATABASE_ENGINE = 'dummy'
try:
- backend = __import__('django.db.backends.%s.base' % settings.DATABASE_ENGINE, '', '', [''])
+ backend = __import__('django.db.backends.%s.base' % settings.DATABASE_ENGINE, {}, {}, [''])
except ImportError, e:
# The database backend wasn't found. Display a helpful error message
# listing all possible database backends.
@@ -23,9 +23,9 @@
else:
raise # If there's some other error, this must be an error in Django itself.
-get_introspection_module = lambda: __import__('django.db.backends.%s.introspection' % settings.DATABASE_ENGINE, '', '', [''])
-get_creation_module = lambda: __import__('django.db.backends.%s.creation' % settings.DATABASE_ENGINE, '', '', [''])
-runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE_ENGINE, '', '', ['']).runshell()
+get_introspection_module = lambda: __import__('django.db.backends.%s.introspection' % settings.DATABASE_ENGINE, {}, {}, [''])
+get_creation_module = lambda: __import__('django.db.backends.%s.creation' % settings.DATABASE_ENGINE, {}, {}, [''])
+runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE_ENGINE, {}, {}, ['']).runshell()
connection = backend.DatabaseWrapper()
DatabaseError = backend.DatabaseError
View
2  django/db/models/loading.py
@@ -48,7 +48,7 @@ def get_app(app_label, emptyOK=False):
def load_app(app_name):
"Loads the app with the provided fully qualified name, and returns the model module."
global _app_list
- mod = __import__(app_name, '', '', ['models'])
+ mod = __import__(app_name, {}, {}, ['models'])
if not hasattr(mod, 'models'):
return None
if mod.models not in _app_list:
View
2  django/template/__init__.py
@@ -883,7 +883,7 @@ def get_library(module_name):
lib = libraries.get(module_name, None)
if not lib:
try:
- mod = __import__(module_name, '', '', [''])
+ mod = __import__(module_name, {}, {}, [''])
except ImportError, e:
raise InvalidTemplateLibrary, "Could not load template library from %s, %s" % (module_name, e)
try:
View
2  django/template/context.py
@@ -69,7 +69,7 @@ def get_standard_processors():
i = path.rfind('.')
module, attr = path[:i], path[i+1:]
try:
- mod = __import__(module, '', '', [attr])
+ mod = __import__(module, {}, {}, [attr])
except ImportError, e:
raise ImproperlyConfigured, 'Error importing request processor module %s: "%s"' % (module, e)
try:
View
4 django/template/loaders/app_directories.py
@@ -15,9 +15,9 @@
m, a = app[:i], app[i+1:]
try:
if a is None:
- mod = __import__(m, '', '', [])
+ mod = __import__(m, {}, {}, [])
else:
- mod = getattr(__import__(m, '', '', [a]), a)
+ mod = getattr(__import__(m, {}, {}, [a]), a)
except ImportError, e:
raise ImproperlyConfigured, 'ImportError %s: %s' % (app, e.args[0])
template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates')
View
2  django/templatetags/__init__.py
@@ -2,6 +2,6 @@
for a in settings.INSTALLED_APPS:
try:
- __path__.extend(__import__(a + '.templatetags', '', '', ['']).__path__)
+ __path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__)
except ImportError:
pass
View
2  django/test/simple.py
@@ -28,7 +28,7 @@ def build_suite(app_module):
# models module
try:
app_path = app_module.__name__.split('.')[:-1]
- test_module = __import__('.'.join(app_path + [TEST_MODULE]), [], [], TEST_MODULE)
+ test_module = __import__('.'.join(app_path + [TEST_MODULE]), {}, {}, TEST_MODULE)
suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_module))
try:
View
2  django/views/debug.py
@@ -75,7 +75,7 @@ def technical_500_response(request, exc_type, exc_value, tb):
loader_debug_info = []
for loader in template_source_loaders:
try:
- source_list_func = getattr(__import__(loader.__module__, '', '', ['get_template_sources']), 'get_template_sources')
+ source_list_func = getattr(__import__(loader.__module__, {}, {}, ['get_template_sources']), 'get_template_sources')
# NOTE: This assumes exc_value is the name of the template that
# the loader attempted to load.
template_list = [{'name': t, 'exists': os.path.exists(t)} \
Please sign in to comment.
Something went wrong with that request. Please try again.