Skip to content

Commit

Permalink
Fixed #2968 -- Changed arguments to __import__ to use empty dictionar…
Browse files Browse the repository at this point in the history
…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
adrianholovaty committed Oct 30, 2006
1 parent 6d1335c commit 41d11a6
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions django/conf/__init__.py
Expand Up @@ -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)

Expand All @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions django/contrib/admin/views/doc.py
Expand Up @@ -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)
Expand All @@ -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__)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/admin/views/template.py
Expand Up @@ -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 = {}, {}
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/auth/__init__.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion django/core/cache/__init__.py
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion django/core/handlers/base.py
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions django/core/management.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion django/core/serializers/__init__.py
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions django/core/urlresolvers.py
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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))

Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions django/db/__init__.py
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion django/db/models/loading.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion django/template/__init__.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion django/template/context.py
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions django/template/loaders/app_directories.py
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion django/templatetags/__init__.py
Expand Up @@ -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
2 changes: 1 addition & 1 deletion django/test/simple.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion django/views/debug.py
Expand Up @@ -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)} \
Expand Down

0 comments on commit 41d11a6

Please sign in to comment.