Ticket #8193: import_fixes_8272.2.diff

File import_fixes_8272.2.diff, 15.7 KB (added by Ivan Illarionov, 11 years ago)

Added another import fix to the previous patch

  • django/test/client.py

     
    170170        Obtains the current session variables.
    171171        """
    172172        if 'django.contrib.sessions' in settings.INSTALLED_APPS:
    173             engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
     173            engine = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]])
    174174            cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
    175175            if cookie:
    176176                return engine.SessionStore(cookie.value)
     
    295295        user = authenticate(**credentials)
    296296        if user and user.is_active \
    297297                and 'django.contrib.sessions' in settings.INSTALLED_APPS:
    298             engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
     298            engine = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]])
    299299
    300300            # Create a fake request to store login details.
    301301            request = HttpRequest()
     
    327327
    328328        Causes the authenticated user to be logged out.
    329329        """
    330         session = __import__(settings.SESSION_ENGINE, {}, {}, ['']).SessionStore()
     330        session = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]]).SessionStore()
    331331        session.delete(session_key=self.cookies[settings.SESSION_COOKIE_NAME].value)
    332332        self.cookies = SimpleCookie()
  • django/db/__init__.py

     
    1313    # Most of the time, the database backend will be one of the official
    1414    # backends that ships with Django, so look there first.
    1515    _import_path = 'django.db.backends.'
    16     backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, [''])
    17     creation = __import__('%s%s.creation' % (_import_path, settings.DATABASE_ENGINE), {}, {}, [''])
     16    backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, ['base'])
     17    creation = __import__('%s%s.creation' % (_import_path, settings.DATABASE_ENGINE), {}, {}, ['creation'])
    1818except ImportError, e:
    1919    # If the import failed, we might be looking for a database backend
    2020    # distributed external to Django. So we'll try that next.
    2121    try:
    2222        _import_path = ''
    23         backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, [''])
    24         creation = __import__('%s.creation' % settings.DATABASE_ENGINE, {}, {}, [''])
     23        backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, ['base'])
     24        creation = __import__('%s.creation' % settings.DATABASE_ENGINE, {}, {}, ['creation'])
    2525    except ImportError, e_user:
    2626        # The database backend wasn't found. Display a helpful error message
    2727        # listing all possible (built-in) database backends.
  • django/conf/__init__.py

     
    8989        self.SETTINGS_MODULE = settings_module
    9090
    9191        try:
    92             mod = __import__(self.SETTINGS_MODULE, {}, {}, [''])
     92            mod = __import__(self.SETTINGS_MODULE, {}, {}, [self.SETTINGS_MODULE.split('.')[-1]])
    9393        except ImportError, e:
    9494            raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
    9595
     
    109109        new_installed_apps = []
    110110        for app in self.INSTALLED_APPS:
    111111            if app.endswith('.*'):
    112                 appdir = os.path.dirname(__import__(app[:-2], {}, {}, ['']).__file__)
     112                appdir = os.path.dirname(__import__(app[:-2], {}, {}, [app[:-2].split('.')[-1]]).__file__)
    113113                for d in os.listdir(appdir):
    114114                    if d.isalpha() and os.path.isdir(os.path.join(appdir, d)):
    115115                        new_installed_apps.append('%s.%s' % (app[:-2], d))
  • django/core/servers/fastcgi.py

     
    128128    wsgi_opts['debug'] = False # Turn off flup tracebacks
    129129
    130130    try:
    131         WSGIServer = getattr(__import__('flup.' + flup_module, '', '', flup_module), 'WSGIServer')
     131        WSGIServer = getattr(__import__('flup.' + flup_module, '', '', [flup_module]), 'WSGIServer')
    132132    except:
    133133        print "Can't import flup." + flup_module
    134134        return False
  • django/core/serializers/__init__.py

     
    3636
    3737def register_serializer(format, serializer_module):
    3838    """Register a new serializer by passing in a module name."""
    39     module = __import__(serializer_module, {}, {}, [''])
     39    module = __import__(serializer_module, {}, {}, [serializer_module.split('.')[-1]])
    4040    _serializers[format] = module
    4141
    4242def unregister_serializer(format):
  • django/core/urlresolvers.py

     
    5151            lookup_view = lookup_view.encode('ascii')
    5252            mod_name, func_name = get_mod_func(lookup_view)
    5353            if func_name != '':
    54                 lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
     54                lookup_view = getattr(__import__(mod_name, {}, {}, [mod_name.split('.')[-1]]), func_name)
    5555        except (ImportError, AttributeError):
    5656            if not can_fail:
    5757                raise
     
    195195    def reverse(self, viewname, *args, **kwargs):
    196196        mod_name, func_name = get_mod_func(viewname)
    197197        try:
    198             lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
     198            lookup_view = getattr(__import__(mod_name, {}, {}, [mod_name.split('.')[-1]]), func_name)
    199199        except (ImportError, AttributeError):
    200200            raise NoReverseMatch
    201201        if lookup_view != self.callback:
     
    255255            return self._urlconf_module
    256256        except AttributeError:
    257257            try:
    258                 self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
     258                self._urlconf_module = __import__(self.urlconf_name, {}, {}, [self.urlconf_name.split('.')[-1]])
    259259            except Exception, e:
    260260                # Either an invalid urlconf_name, such as "foo.bar.", or some
    261261                # kind of problem during the actual import.
     
    271271        callback = getattr(self.urlconf_module, 'handler%s' % view_type)
    272272        mod_name, func_name = get_mod_func(callback)
    273273        try:
    274             return getattr(__import__(mod_name, {}, {}, ['']), func_name), {}
     274            return getattr(__import__(mod_name, {}, {}, [mod_name.split('.')[-1]]), func_name), {}
    275275        except (ImportError, AttributeError), e:
    276276            raise ViewDoesNotExist, "Tried %s. Error was: %s" % (callback, str(e))
    277277
  • django/core/handlers/base.py

     
    3535                raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path
    3636            mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:]
    3737            try:
    38                 mod = __import__(mw_module, {}, {}, [''])
     38                mod = __import__(mw_module, {}, {}, [mw_module.split('.')[-1]])
    3939            except ImportError, e:
    4040                raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e)
    4141            try:
  • django/core/files/storage.py

     
    203203        raise ImproperlyConfigured("%s isn't a storage module." % import_path)
    204204    module, classname = import_path[:dot], import_path[dot+1:]
    205205    try:
    206         mod = __import__(module, {}, {}, [''])
     206        mod = __import__(module, {}, {}, [module.split('.')[-1]])
    207207    except ImportError, e:
    208208        raise ImproperlyConfigured('Error importing storage module %s: "%s"' % (module, e))
    209209    try:
  • django/core/cache/__init__.py

     
    4848        host = host[:-1]
    4949
    5050    if scheme in BACKENDS:
    51         module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, [''])
     51        module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, [BACKENDS[scheme]])
    5252    else:
    53         module = __import__(scheme, {}, {}, [''])
     53        module = __import__(scheme, {}, {}, [scheme.split('.')[-1]])
    5454    return getattr(module, 'CacheClass')(host, params)
    5555
    5656cache = get_cache(settings.CACHE_BACKEND)
  • django/core/management/commands/flush.py

     
    2626        # dispatcher events.
    2727        for app_name in settings.INSTALLED_APPS:
    2828            try:
    29                 __import__(app_name + '.management', {}, {}, [''])
     29                __import__(app_name + '.management', {}, {}, ['management'])
    3030            except ImportError:
    3131                pass
    3232
  • django/core/management/commands/syncdb.py

     
    3333        # dispatcher events.
    3434        for app_name in settings.INSTALLED_APPS:
    3535            try:
    36                 __import__(app_name + '.management', {}, {}, [''])
     36                __import__(app_name + '.management', {}, {}, ['management'])
    3737            except ImportError, exc:
    3838                # This is slightly hackish. We want to ignore ImportErrors
    3939                # if the "management" module itself is missing -- but we don't
  • django/core/management/__init__.py

     
    308308    project_name = os.path.basename(project_directory)
    309309    settings_name = os.path.splitext(settings_filename)[0]
    310310    sys.path.append(os.path.join(project_directory, os.pardir))
    311     project_module = __import__(project_name, {}, {}, [''])
     311    project_module = __import__(project_name, {}, {}, [project_name.split('.')[-1]])
    312312    sys.path.pop()
    313313
    314314    # 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', {}, {}, ['templatetags']).__path__)
    66    except ImportError:
    77        pass
  • django/views/i18n.py

     
    128128    paths = []
    129129    # first load all english languages files for defaults
    130130    for package in packages:
    131         p = __import__(package, {}, {}, [''])
     131        p = __import__(package, {}, {}, [package.split('.')[-1]])
    132132        path = os.path.join(os.path.dirname(p.__file__), 'locale')
    133133        paths.append(path)
    134134        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, {}, {}, [mod.split('.')[-1]])
    1818        settings_modules[settings_module.SITE_ID] = settings_module
    1919    manipulator = TemplateValidator(settings_modules)
    2020    new_data, errors = {}, {}
  • django/contrib/admindocs/views.py

     
    112112        return missing_docutils_page(request)
    113113
    114114    if settings.ADMIN_FOR:
    115         settings_modules = [__import__(m, {}, {}, ['']) for m in settings.ADMIN_FOR]
     115        settings_modules = [__import__(m, {}, {}, [m.split('.')[-1]]) for m in settings.ADMIN_FOR]
    116116    else:
    117117        settings_modules = [settings]
    118118
    119119    views = []
    120120    for settings_mod in settings_modules:
    121         urlconf = __import__(settings_mod.ROOT_URLCONF, {}, {}, [''])
     121        urlconf = __import__(settings_mod.ROOT_URLCONF, {}, {}, [settings_mod.ROOT_URLCONF.split('.')[-1]])
    122122        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
    123123        if Site._meta.installed:
    124124            site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
     
    145145
    146146    mod, func = urlresolvers.get_mod_func(view)
    147147    try:
    148         view_func = getattr(__import__(mod, {}, {}, ['']), func)
     148        view_func = getattr(__import__(mod, {}, {}, [mod.split('.')[-1]]), func)
    149149    except (ImportError, AttributeError):
    150150        raise Http404
    151151    title, body, metadata = utils.parse_docstring(view_func.__doc__)
     
    259259def template_detail(request, template):
    260260    templates = []
    261261    for site_settings_module in settings.ADMIN_FOR:
    262         settings_mod = __import__(site_settings_module, {}, {}, [''])
     262        settings_mod = __import__(site_settings_module, {}, {}, [site_settings_module.split('.')[-1]])
    263263        if Site._meta.installed:
    264264            site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
    265265        else:
  • django/contrib/sessions/middleware.py

     
    66
    77class SessionMiddleware(object):
    88    def process_request(self, request):
    9         engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
     9        engine = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]])
    1010        session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME, None)
    1111        request.session = engine.SessionStore(session_key)
    1212
  • django/template/__init__.py

     
    917917    lib = libraries.get(module_name, None)
    918918    if not lib:
    919919        try:
    920             mod = __import__(module_name, {}, {}, [''])
     920            mod = __import__(module_name, {}, {}, [module_name.split('.')[-1]])
    921921        except ImportError, e:
    922922            raise InvalidTemplateLibrary("Could not load template library from %s, %s" % (module_name, e))
    923923        try:
Back to Top