Ticket #2968: fix_import_args.diff

File fix_import_args.diff, 14.9 KB (added by Yasushi Masuda <ymasuda@…>, 9 years ago)

Patch to fix import args

  • django/test/simple.py

     
    2828    # models module
    2929    try:
    3030        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)
    3232       
    3333        suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_module))
    3434        try:           
  • django/db/models/loading.py

     
    4848def load_app(app_name):
    4949    "Loads the app with the provided fully qualified name, and returns the model module."
    5050    global _app_list
    51     mod = __import__(app_name, '', '', ['models'])
     51    mod = __import__(app_name, {}, {}, ['models'])
    5252    if not hasattr(mod, 'models'):
    5353        return None
    5454    if mod.models not in _app_list:
  • django/db/__init__.py

     
    88    settings.DATABASE_ENGINE = 'dummy'
    99
    1010try:
    11     backend = __import__('django.db.backends.%s.base' % settings.DATABASE_ENGINE, '', '', [''])
     11    backend = __import__('django.db.backends.%s.base' % settings.DATABASE_ENGINE, {}, {}, [''])
    1212except ImportError, e:
    1313    # The database backend wasn't found. Display a helpful error message
    1414    # listing all possible database backends.
     
    2323    else:
    2424        raise # If there's some other error, this must be an error in Django itself.
    2525
    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()
     26get_introspection_module = lambda: __import__('django.db.backends.%s.introspection' % settings.DATABASE_ENGINE, {}, {}, [''])
     27get_creation_module = lambda: __import__('django.db.backends.%s.creation' % settings.DATABASE_ENGINE, {}, {}, [''])
     28runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE_ENGINE, {}, {}, ['']).runshell()
    2929
    3030connection = backend.DatabaseWrapper()
    3131DatabaseError = backend.DatabaseError
  • django/conf/__init__.py

     
    7777        self.SETTINGS_MODULE = settings_module
    7878
    7979        try:
    80             mod = __import__(self.SETTINGS_MODULE, '', '', [''])
     80            mod = __import__(self.SETTINGS_MODULE, {}, {}, [''])
    8181        except ImportError, e:
    8282            raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
    8383
     
    9797        new_installed_apps = []
    9898        for app in self.INSTALLED_APPS:
    9999            if app.endswith('.*'):
    100                 appdir = os.path.dirname(__import__(app[:-2], '', '', ['']).__file__)
     100                appdir = os.path.dirname(__import__(app[:-2], {}, {}, ['']).__file__)
    101101                for d in os.listdir(appdir):
    102102                    if d.isalpha() and os.path.isdir(os.path.join(appdir, d)):
    103103                        new_installed_apps.append('%s.%s' % (app[:-2], d))
  • django/core/serializers/__init__.py

     
    2929       
    3030def register_serializer(format, serializer_module):
    3131    """Register a new serializer by passing in a module name."""
    32     module = __import__(serializer_module, '', '', [''])
     32    module = __import__(serializer_module, {}, {}, [''])
    3333    _serializers[format] = module
    3434   
    3535def unregister_serializer(format):
  • django/core/urlresolvers.py

     
    119119            return self._callback
    120120        mod_name, func_name = get_mod_func(self._callback_str)
    121121        try:
    122             self._callback = getattr(__import__(mod_name, '', '', ['']), func_name)
     122            self._callback = getattr(__import__(mod_name, {}, {}, ['']), func_name)
    123123        except ImportError, e:
    124124            raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e))
    125125        except AttributeError, e:
     
    130130    def reverse(self, viewname, *args, **kwargs):
    131131        mod_name, func_name = get_mod_func(viewname)
    132132        try:
    133             lookup_view = getattr(__import__(mod_name, '', '', ['']), func_name)
     133            lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
    134134        except (ImportError, AttributeError):
    135135            raise NoReverseMatch
    136136        if lookup_view != self.callback:
     
    171171            return self._urlconf_module
    172172        except AttributeError:
    173173            try:
    174                 self._urlconf_module = __import__(self.urlconf_name, '', '', [''])
     174                self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
    175175            except ValueError, e:
    176176                # Invalid urlconf_name, such as "foo.bar." (note trailing period)
    177177                raise ImproperlyConfigured, "Error while importing URLconf %r: %s" % (self.urlconf_name, e)
     
    186186        callback = getattr(self.urlconf_module, 'handler%s' % view_type)
    187187        mod_name, func_name = get_mod_func(callback)
    188188        try:
    189             return getattr(__import__(mod_name, '', '', ['']), func_name), {}
     189            return getattr(__import__(mod_name, {}, {}, ['']), func_name), {}
    190190        except (ImportError, AttributeError), e:
    191191            raise ViewDoesNotExist, "Tried %s. Error was: %s" % (callback, str(e))
    192192
     
    200200        if not callable(lookup_view):
    201201            mod_name, func_name = get_mod_func(lookup_view)
    202202            try:
    203                 lookup_view = getattr(__import__(mod_name, '', '', ['']), func_name)
     203                lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
    204204            except (ImportError, AttributeError):
    205205                raise NoReverseMatch
    206206        for pattern in self.urlconf_module.urlpatterns:
  • django/core/handlers/base.py

     
    2626                raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path
    2727            mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:]
    2828            try:
    29                 mod = __import__(mw_module, '', '', [''])
     29                mod = __import__(mw_module, {}, {}, [''])
    3030            except ImportError, e:
    3131                raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e)
    3232            try:
  • django/core/cache/__init__.py

     
    4848    if host.endswith('/'):
    4949        host = host[:-1]
    5050
    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')
    5252    return cache_class(host, params)
    5353
    5454cache = get_cache(settings.CACHE_BACKEND)
  • django/core/management.py

     
    446446    # dispatcher events.
    447447    for app_name in settings.INSTALLED_APPS:
    448448        try:
    449             __import__(app_name + '.management', '', '', [''])
     449            __import__(app_name + '.management', {}, {}, [''])
    450450        except ImportError:
    451451            pass
    452452
     
    12301230        test_module_name = '.'.join(test_path[:-1])
    12311231    else:
    12321232        test_module_name = '.'
    1233     test_module = __import__(test_module_name, [],[],test_path[-1])
     1233    test_module = __import__(test_module_name, {}, {}, test_path[-1])
    12341234    test_runner = getattr(test_module, test_path[-1])
    12351235
    12361236    test_runner(app_list, verbosity)
     
    14191419    project_directory = os.path.dirname(settings_mod.__file__)
    14201420    project_name = os.path.basename(project_directory)
    14211421    sys.path.append(os.path.join(project_directory, '..'))
    1422     project_module = __import__(project_name, '', '', [''])
     1422    project_module = __import__(project_name, {}, {}, [''])
    14231423    sys.path.pop()
    14241424
    14251425    # Set DJANGO_SETTINGS_MODULE appropriately.
  • django/templatetags/__init__.py

     
    22
    33for a in settings.INSTALLED_APPS:
    44    try:
    5         __path__.extend(__import__(a + '.templatetags', '', '', ['']).__path__)
     5        __path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__)
    66    except ImportError:
    77        pass
  • django/views/debug.py

     
    7575        loader_debug_info = []
    7676        for loader in template_source_loaders:
    7777            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')
    7979                # NOTE: This assumes exc_value is the name of the template that
    8080                # the loader attempted to load.
    8181                template_list = [{'name': t, 'exists': os.path.exists(t)} \
  • django/contrib/auth/__init__.py

     
    99    i = path.rfind('.')
    1010    module, attr = path[:i], path[i+1:]
    1111    try:
    12         mod = __import__(module, '', '', [attr])
     12        mod = __import__(module, {}, {}, [attr])
    1313    except ImportError, e:
    1414        raise ImproperlyConfigured, 'Error importing authentication backend %s: "%s"' % (module, e)
    1515    try:
  • django/contrib/admin/views/template.py

     
    1414    # get a dict of {site_id : settings_module} for the validator
    1515    settings_modules = {}
    1616    for mod in settings.ADMIN_FOR:
    17         settings_module = __import__(mod, '', '', [''])
     17        settings_module = __import__(mod, {}, {}, [''])
    1818        settings_modules[settings_module.SITE_ID] = settings_module
    1919    manipulator = TemplateValidator(settings_modules)
    2020    new_data, errors = {}, {}
  • django/contrib/admin/views/doc.py

     
    9898        return missing_docutils_page(request)
    9999
    100100    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]
    102102    else:
    103103        settings_modules = [settings]
    104104
    105105    views = []
    106106    for settings_mod in settings_modules:
    107         urlconf = __import__(settings_mod.ROOT_URLCONF, '', '', [''])
     107        urlconf = __import__(settings_mod.ROOT_URLCONF, {}, {}, [''])
    108108        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
    109109        if Site._meta.installed:
    110110            site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
     
    127127
    128128    mod, func = urlresolvers.get_mod_func(view)
    129129    try:
    130         view_func = getattr(__import__(mod, '', '', ['']), func)
     130        view_func = getattr(__import__(mod, {}, {}, ['']), func)
    131131    except (ImportError, AttributeError):
    132132        raise Http404
    133133    title, body, metadata = utils.parse_docstring(view_func.__doc__)
     
    235235def template_detail(request, template):
    236236    templates = []
    237237    for site_settings_module in settings.ADMIN_FOR:
    238         settings_mod = __import__(site_settings_module, '', '', [''])
     238        settings_mod = __import__(site_settings_module, {}, {}, [''])
    239239        if Site._meta.installed:
    240240            site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
    241241        else:
  • django/template/__init__.py

     
    883883    lib = libraries.get(module_name, None)
    884884    if not lib:
    885885        try:
    886             mod = __import__(module_name, '', '', [''])
     886            mod = __import__(module_name, {}, {}, [''])
    887887        except ImportError, e:
    888888            raise InvalidTemplateLibrary, "Could not load template library from %s, %s" % (module_name, e)
    889889        try:
  • django/template/loaders/app_directories.py

     
    1515        m, a = app[:i], app[i+1:]
    1616    try:
    1717        if a is None:
    18             mod = __import__(m, '', '', [])
     18            mod = __import__(m, {}, {}, [])
    1919        else:
    20             mod = getattr(__import__(m, '', '', [a]), a)
     20            mod = getattr(__import__(m, {}, {}, [a]), a)
    2121    except ImportError, e:
    2222        raise ImproperlyConfigured, 'ImportError %s: %s' % (app, e.args[0])
    2323    template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates')
  • django/template/context.py

     
    6969            i = path.rfind('.')
    7070            module, attr = path[:i], path[i+1:]
    7171            try:
    72                 mod = __import__(module, '', '', [attr])
     72                mod = __import__(module, {}, {}, [attr])
    7373            except ImportError, e:
    7474                raise ImproperlyConfigured, 'Error importing request processor module %s: "%s"' % (module, e)
    7575            try:
Back to Top