Ticket #2968: fix_import_args.diff
File fix_import_args.diff, 14.9 KB (added by , 18 years ago) |
---|
-
django/test/simple.py
28 28 # models module 29 29 try: 30 30 app_path = app_module.__name__.split('.')[:-1] 31 test_module = __import__('.'.join(app_path + [TEST_MODULE]), [], [], TEST_MODULE)31 test_module = __import__('.'.join(app_path + [TEST_MODULE]), {}, {}, TEST_MODULE) 32 32 33 33 suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_module)) 34 34 try: -
django/db/models/loading.py
48 48 def load_app(app_name): 49 49 "Loads the app with the provided fully qualified name, and returns the model module." 50 50 global _app_list 51 mod = __import__(app_name, '', '', ['models'])51 mod = __import__(app_name, {}, {}, ['models']) 52 52 if not hasattr(mod, 'models'): 53 53 return None 54 54 if mod.models not in _app_list: -
django/db/__init__.py
8 8 settings.DATABASE_ENGINE = 'dummy' 9 9 10 10 try: 11 backend = __import__('django.db.backends.%s.base' % settings.DATABASE_ENGINE, '', '', [''])11 backend = __import__('django.db.backends.%s.base' % settings.DATABASE_ENGINE, {}, {}, ['']) 12 12 except ImportError, e: 13 13 # The database backend wasn't found. Display a helpful error message 14 14 # listing all possible database backends. … … 23 23 else: 24 24 raise # If there's some other error, this must be an error in Django itself. 25 25 26 get_introspection_module = lambda: __import__('django.db.backends.%s.introspection' % settings.DATABASE_ENGINE, '', '', [''])27 get_creation_module = lambda: __import__('django.db.backends.%s.creation' % settings.DATABASE_ENGINE, '', '', [''])28 runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE_ENGINE, '', '', ['']).runshell()26 get_introspection_module = lambda: __import__('django.db.backends.%s.introspection' % settings.DATABASE_ENGINE, {}, {}, ['']) 27 get_creation_module = lambda: __import__('django.db.backends.%s.creation' % settings.DATABASE_ENGINE, {}, {}, ['']) 28 runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE_ENGINE, {}, {}, ['']).runshell() 29 29 30 30 connection = backend.DatabaseWrapper() 31 31 DatabaseError = backend.DatabaseError -
django/conf/__init__.py
77 77 self.SETTINGS_MODULE = settings_module 78 78 79 79 try: 80 mod = __import__(self.SETTINGS_MODULE, '', '', [''])80 mod = __import__(self.SETTINGS_MODULE, {}, {}, ['']) 81 81 except ImportError, e: 82 82 raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) 83 83 … … 97 97 new_installed_apps = [] 98 98 for app in self.INSTALLED_APPS: 99 99 if app.endswith('.*'): 100 appdir = os.path.dirname(__import__(app[:-2], '', '', ['']).__file__)100 appdir = os.path.dirname(__import__(app[:-2], {}, {}, ['']).__file__) 101 101 for d in os.listdir(appdir): 102 102 if d.isalpha() and os.path.isdir(os.path.join(appdir, d)): 103 103 new_installed_apps.append('%s.%s' % (app[:-2], d)) -
django/core/serializers/__init__.py
29 29 30 30 def register_serializer(format, serializer_module): 31 31 """Register a new serializer by passing in a module name.""" 32 module = __import__(serializer_module, '', '', [''])32 module = __import__(serializer_module, {}, {}, ['']) 33 33 _serializers[format] = module 34 34 35 35 def unregister_serializer(format): -
django/core/urlresolvers.py
119 119 return self._callback 120 120 mod_name, func_name = get_mod_func(self._callback_str) 121 121 try: 122 self._callback = getattr(__import__(mod_name, '', '', ['']), func_name)122 self._callback = getattr(__import__(mod_name, {}, {}, ['']), func_name) 123 123 except ImportError, e: 124 124 raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e)) 125 125 except AttributeError, e: … … 130 130 def reverse(self, viewname, *args, **kwargs): 131 131 mod_name, func_name = get_mod_func(viewname) 132 132 try: 133 lookup_view = getattr(__import__(mod_name, '', '', ['']), func_name)133 lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 134 134 except (ImportError, AttributeError): 135 135 raise NoReverseMatch 136 136 if lookup_view != self.callback: … … 171 171 return self._urlconf_module 172 172 except AttributeError: 173 173 try: 174 self._urlconf_module = __import__(self.urlconf_name, '', '', [''])174 self._urlconf_module = __import__(self.urlconf_name, {}, {}, ['']) 175 175 except ValueError, e: 176 176 # Invalid urlconf_name, such as "foo.bar." (note trailing period) 177 177 raise ImproperlyConfigured, "Error while importing URLconf %r: %s" % (self.urlconf_name, e) … … 186 186 callback = getattr(self.urlconf_module, 'handler%s' % view_type) 187 187 mod_name, func_name = get_mod_func(callback) 188 188 try: 189 return getattr(__import__(mod_name, '', '', ['']), func_name), {}189 return getattr(__import__(mod_name, {}, {}, ['']), func_name), {} 190 190 except (ImportError, AttributeError), e: 191 191 raise ViewDoesNotExist, "Tried %s. Error was: %s" % (callback, str(e)) 192 192 … … 200 200 if not callable(lookup_view): 201 201 mod_name, func_name = get_mod_func(lookup_view) 202 202 try: 203 lookup_view = getattr(__import__(mod_name, '', '', ['']), func_name)203 lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 204 204 except (ImportError, AttributeError): 205 205 raise NoReverseMatch 206 206 for pattern in self.urlconf_module.urlpatterns: -
django/core/handlers/base.py
26 26 raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path 27 27 mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:] 28 28 try: 29 mod = __import__(mw_module, '', '', [''])29 mod = __import__(mw_module, {}, {}, ['']) 30 30 except ImportError, e: 31 31 raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e) 32 32 try: -
django/core/cache/__init__.py
48 48 if host.endswith('/'): 49 49 host = host[:-1] 50 50 51 cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], '', '', ['']), 'CacheClass')51 cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']), 'CacheClass') 52 52 return cache_class(host, params) 53 53 54 54 cache = get_cache(settings.CACHE_BACKEND) -
django/core/management.py
446 446 # dispatcher events. 447 447 for app_name in settings.INSTALLED_APPS: 448 448 try: 449 __import__(app_name + '.management', '', '', [''])449 __import__(app_name + '.management', {}, {}, ['']) 450 450 except ImportError: 451 451 pass 452 452 … … 1230 1230 test_module_name = '.'.join(test_path[:-1]) 1231 1231 else: 1232 1232 test_module_name = '.' 1233 test_module = __import__(test_module_name, [],[],test_path[-1])1233 test_module = __import__(test_module_name, {}, {}, test_path[-1]) 1234 1234 test_runner = getattr(test_module, test_path[-1]) 1235 1235 1236 1236 test_runner(app_list, verbosity) … … 1419 1419 project_directory = os.path.dirname(settings_mod.__file__) 1420 1420 project_name = os.path.basename(project_directory) 1421 1421 sys.path.append(os.path.join(project_directory, '..')) 1422 project_module = __import__(project_name, '', '', [''])1422 project_module = __import__(project_name, {}, {}, ['']) 1423 1423 sys.path.pop() 1424 1424 1425 1425 # Set DJANGO_SETTINGS_MODULE appropriately. -
django/templatetags/__init__.py
2 2 3 3 for a in settings.INSTALLED_APPS: 4 4 try: 5 __path__.extend(__import__(a + '.templatetags', '', '', ['']).__path__)5 __path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__) 6 6 except ImportError: 7 7 pass -
django/views/debug.py
75 75 loader_debug_info = [] 76 76 for loader in template_source_loaders: 77 77 try: 78 source_list_func = getattr(__import__(loader.__module__, '', '', ['get_template_sources']), 'get_template_sources')78 source_list_func = getattr(__import__(loader.__module__, {}, {}, ['get_template_sources']), 'get_template_sources') 79 79 # NOTE: This assumes exc_value is the name of the template that 80 80 # the loader attempted to load. 81 81 template_list = [{'name': t, 'exists': os.path.exists(t)} \ -
django/contrib/auth/__init__.py
9 9 i = path.rfind('.') 10 10 module, attr = path[:i], path[i+1:] 11 11 try: 12 mod = __import__(module, '', '', [attr])12 mod = __import__(module, {}, {}, [attr]) 13 13 except ImportError, e: 14 14 raise ImproperlyConfigured, 'Error importing authentication backend %s: "%s"' % (module, e) 15 15 try: -
django/contrib/admin/views/template.py
14 14 # get a dict of {site_id : settings_module} for the validator 15 15 settings_modules = {} 16 16 for mod in settings.ADMIN_FOR: 17 settings_module = __import__(mod, '', '', [''])17 settings_module = __import__(mod, {}, {}, ['']) 18 18 settings_modules[settings_module.SITE_ID] = settings_module 19 19 manipulator = TemplateValidator(settings_modules) 20 20 new_data, errors = {}, {} -
django/contrib/admin/views/doc.py
98 98 return missing_docutils_page(request) 99 99 100 100 if settings.ADMIN_FOR: 101 settings_modules = [__import__(m, '', '', ['']) for m in settings.ADMIN_FOR]101 settings_modules = [__import__(m, {}, {}, ['']) for m in settings.ADMIN_FOR] 102 102 else: 103 103 settings_modules = [settings] 104 104 105 105 views = [] 106 106 for settings_mod in settings_modules: 107 urlconf = __import__(settings_mod.ROOT_URLCONF, '', '', [''])107 urlconf = __import__(settings_mod.ROOT_URLCONF, {}, {}, ['']) 108 108 view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns) 109 109 if Site._meta.installed: 110 110 site_obj = Site.objects.get(pk=settings_mod.SITE_ID) … … 127 127 128 128 mod, func = urlresolvers.get_mod_func(view) 129 129 try: 130 view_func = getattr(__import__(mod, '', '', ['']), func)130 view_func = getattr(__import__(mod, {}, {}, ['']), func) 131 131 except (ImportError, AttributeError): 132 132 raise Http404 133 133 title, body, metadata = utils.parse_docstring(view_func.__doc__) … … 235 235 def template_detail(request, template): 236 236 templates = [] 237 237 for site_settings_module in settings.ADMIN_FOR: 238 settings_mod = __import__(site_settings_module, '', '', [''])238 settings_mod = __import__(site_settings_module, {}, {}, ['']) 239 239 if Site._meta.installed: 240 240 site_obj = Site.objects.get(pk=settings_mod.SITE_ID) 241 241 else: -
django/template/__init__.py
883 883 lib = libraries.get(module_name, None) 884 884 if not lib: 885 885 try: 886 mod = __import__(module_name, '', '', [''])886 mod = __import__(module_name, {}, {}, ['']) 887 887 except ImportError, e: 888 888 raise InvalidTemplateLibrary, "Could not load template library from %s, %s" % (module_name, e) 889 889 try: -
django/template/loaders/app_directories.py
15 15 m, a = app[:i], app[i+1:] 16 16 try: 17 17 if a is None: 18 mod = __import__(m, '', '', [])18 mod = __import__(m, {}, {}, []) 19 19 else: 20 mod = getattr(__import__(m, '', '', [a]), a)20 mod = getattr(__import__(m, {}, {}, [a]), a) 21 21 except ImportError, e: 22 22 raise ImproperlyConfigured, 'ImportError %s: %s' % (app, e.args[0]) 23 23 template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates') -
django/template/context.py
69 69 i = path.rfind('.') 70 70 module, attr = path[:i], path[i+1:] 71 71 try: 72 mod = __import__(module, '', '', [attr])72 mod = __import__(module, {}, {}, [attr]) 73 73 except ImportError, e: 74 74 raise ImproperlyConfigured, 'Error importing request processor module %s: "%s"' % (module, e) 75 75 try: