From 41d11a685f6563c175902fad6e39a55c01c49a0b Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 30 Oct 2006 20:50:27 +0000 Subject: [PATCH] Fixed #2968 -- Changed arguments to __import__ to use empty dictionary 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 --- django/conf/__init__.py | 4 ++-- django/contrib/admin/views/doc.py | 8 ++++---- django/contrib/admin/views/template.py | 2 +- django/contrib/auth/__init__.py | 2 +- django/core/cache/__init__.py | 2 +- django/core/handlers/base.py | 2 +- django/core/management.py | 6 +++--- django/core/serializers/__init__.py | 2 +- django/core/urlresolvers.py | 10 +++++----- django/db/__init__.py | 8 ++++---- django/db/models/loading.py | 2 +- django/template/__init__.py | 2 +- django/template/context.py | 2 +- django/template/loaders/app_directories.py | 4 ++-- django/templatetags/__init__.py | 2 +- django/test/simple.py | 2 +- django/views/debug.py | 2 +- 17 files changed, 31 insertions(+), 31 deletions(-) diff --git a/django/conf/__init__.py b/django/conf/__init__.py index 1a04bbfb02..daf5ad766a 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -77,7 +77,7 @@ class Settings(object): 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 @@ class Settings(object): 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)) diff --git a/django/contrib/admin/views/doc.py b/django/contrib/admin/views/doc.py index 435d76f276..4b592acebd 100644 --- a/django/contrib/admin/views/doc.py +++ b/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 @@ model_detail = staff_member_required(model_detail) 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: diff --git a/django/contrib/admin/views/template.py b/django/contrib/admin/views/template.py index 1684870842..93d110b045 100644 --- a/django/contrib/admin/views/template.py +++ b/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 = {}, {} diff --git a/django/contrib/auth/__init__.py b/django/contrib/auth/__init__.py index a0097a01ed..dd3b8152e6 100644 --- a/django/contrib/auth/__init__.py +++ b/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: diff --git a/django/core/cache/__init__.py b/django/core/cache/__init__.py index 17008c4637..6da8e883b9 100644 --- a/django/core/cache/__init__.py +++ b/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) diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index 213c528952..c1403ea4fa 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -26,7 +26,7 @@ class BaseHandler(object): 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: diff --git a/django/core/management.py b/django/core/management.py index 5b34403dd4..0af842dadd 100644 --- a/django/core/management.py +++ b/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. diff --git a/django/core/serializers/__init__.py b/django/core/serializers/__init__.py index 75e087ee1b..a1268321f2 100644 --- a/django/core/serializers/__init__.py +++ b/django/core/serializers/__init__.py @@ -29,7 +29,7 @@ _serializers = {} 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): diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index 45705cb223..6abd71dc41 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -119,7 +119,7 @@ class RegexURLPattern(object): 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 @@ class RegexURLPattern(object): 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 @@ class RegexURLResolver(object): 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 @@ class RegexURLResolver(object): 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 @@ class RegexURLResolver(object): 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: diff --git a/django/db/__init__.py b/django/db/__init__.py index f21ae6a727..4a7f5749d2 100644 --- a/django/db/__init__.py +++ b/django/db/__init__.py @@ -8,7 +8,7 @@ if not settings.DATABASE_ENGINE: 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 @@ except ImportError, e: 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 diff --git a/django/db/models/loading.py b/django/db/models/loading.py index 22f83bfd78..f4aff2438b 100644 --- a/django/db/models/loading.py +++ b/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: diff --git a/django/template/__init__.py b/django/template/__init__.py index 60526b663d..4e0bcf384e 100644 --- a/django/template/__init__.py +++ b/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: diff --git a/django/template/context.py b/django/template/context.py index 6d9efdc7ec..ba23e95ab7 100644 --- a/django/template/context.py +++ b/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: diff --git a/django/template/loaders/app_directories.py b/django/template/loaders/app_directories.py index 8a9bfef4b6..c4e91df929 100644 --- a/django/template/loaders/app_directories.py +++ b/django/template/loaders/app_directories.py @@ -15,9 +15,9 @@ for app in settings.INSTALLED_APPS: 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') diff --git a/django/templatetags/__init__.py b/django/templatetags/__init__.py index 62374577ea..9204535abb 100644 --- a/django/templatetags/__init__.py +++ b/django/templatetags/__init__.py @@ -2,6 +2,6 @@ from django.conf import settings for a in settings.INSTALLED_APPS: try: - __path__.extend(__import__(a + '.templatetags', '', '', ['']).__path__) + __path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__) except ImportError: pass diff --git a/django/test/simple.py b/django/test/simple.py index 628fa464d2..88e6b49925 100644 --- a/django/test/simple.py +++ b/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: diff --git a/django/views/debug.py b/django/views/debug.py index a7f44d17b3..77b6c2fac2 100644 --- a/django/views/debug.py +++ b/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)} \