Ticket #8193: import_fixes.5.diff

File import_fixes.5.diff, 16.2 KB (added by mrts, 16 years ago)

missing init.py in tests/regressiontests/dynamic_imports/

  • django/test/client.py

     
    171171        Obtains the current session variables.
    172172        """
    173173        if 'django.contrib.sessions' in settings.INSTALLED_APPS:
    174             engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
     174            engine = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]])
    175175            cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
    176176            if cookie:
    177177                return engine.SessionStore(cookie.value)
     
    302302        user = authenticate(**credentials)
    303303        if user and user.is_active \
    304304                and 'django.contrib.sessions' in settings.INSTALLED_APPS:
    305             engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
     305            engine = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]])
    306306
    307307            # Create a fake request to store login details.
    308308            request = HttpRequest()
     
    337337
    338338        Causes the authenticated user to be logged out.
    339339        """
    340         session = __import__(settings.SESSION_ENGINE, {}, {}, ['']).SessionStore()
     340        session = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]]).SessionStore()
    341341        session.delete(session_key=self.cookies[settings.SESSION_COOKIE_NAME].value)
    342342        self.cookies = SimpleCookie()
  • 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                app_subdirs = os.listdir(appdir)
    114114                app_subdirs.sort()
    115115                for d in app_subdirs:
  • 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), {}, {}, [''])
     16    backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, ['base'])
    1717except ImportError, e:
    1818    # If the import failed, we might be looking for a database backend
    1919    # distributed external to Django. So we'll try that next.
    2020    try:
    2121        _import_path = ''
    22         backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, [''])
     22        backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, ['base'])
    2323    except ImportError, e_user:
    2424        # The database backend wasn't found. Display a helpful error message
    2525        # listing all possible (built-in) database backends.
  • 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

     
    4747    directly into the global register of serializers. Adding serializers
    4848    directly is not a thread-safe operation.
    4949    """
    50     module = __import__(serializer_module, {}, {}, [''])
     50    module = __import__(serializer_module, {}, {}, [serializer_module.split('.')[-1]])
    5151    if serializers is None:
    5252        _serializers[format] = module
    5353    else:
  • django/core/urlresolvers.py

     
    5454            lookup_view = lookup_view.encode('ascii')
    5555            mod_name, func_name = get_mod_func(lookup_view)
    5656            if func_name != '':
    57                 lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
     57                lookup_view = getattr(__import__(mod_name, {}, {}, [mod_name.split('.')[-1]]), func_name)
    5858                if not callable(lookup_view):
    5959                    raise AttributeError("'%s.%s' is not a callable." % (mod_name, func_name))
    6060        except (ImportError, AttributeError):
     
    195195        try:
    196196            return self._urlconf_module
    197197        except AttributeError:
    198             self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
     198            self._urlconf_module = __import__(self.urlconf_name, {}, {}, [self.urlconf_name.split('.')[-1]])
    199199            return self._urlconf_module
    200200    urlconf_module = property(_get_urlconf_module)
    201201
     
    207207        callback = getattr(self.urlconf_module, 'handler%s' % view_type)
    208208        mod_name, func_name = get_mod_func(callback)
    209209        try:
    210             return getattr(__import__(mod_name, {}, {}, ['']), func_name), {}
     210            return getattr(__import__(mod_name, {}, {}, [mod_name.split('.')[-1]]), func_name), {}
    211211        except (ImportError, AttributeError), e:
    212212            raise ViewDoesNotExist, "Tried %s. Error was: %s" % (callback, str(e))
    213213
  • 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

     
    219219        raise ImproperlyConfigured("%s isn't a storage module." % import_path)
    220220    module, classname = import_path[:dot], import_path[dot+1:]
    221221    try:
    222         mod = __import__(module, {}, {}, [''])
     222        mod = __import__(module, {}, {}, [module.split('.')[-1]])
    223223    except ImportError, e:
    224224        raise ImproperlyConfigured('Error importing storage module %s: "%s"' % (module, e))
    225225    try:
  • django/core/cache/__init__.py

     
    4949        host = host[:-1]
    5050
    5151    if scheme in BACKENDS:
    52         module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, [''])
     52        module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, [BACKENDS[scheme]])
    5353    else:
    54         module = __import__(scheme, {}, {}, [''])
     54        module = __import__(scheme, {}, {}, [scheme.split('.')[-1]])
    5555    return getattr(module, 'CacheClass')(host, params)
    5656
    5757cache = 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

     
    313313    project_name = os.path.basename(project_directory)
    314314    settings_name = os.path.splitext(settings_filename)[0]
    315315    sys.path.append(os.path.join(project_directory, os.pardir))
    316     project_module = __import__(project_name, {}, {}, [''])
     316    project_module = __import__(project_name, {}, {}, [project_name.split('.')[-1]])
    317317    sys.path.pop()
    318318
    319319    # 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/comments/__init__.py

     
    1717
    1818    # Try to import the package
    1919    try:
    20         package = __import__(comments_app, '', '', [''])
     20        package = __import__(comments_app, {}, {}, [comments_app.split('.')[-1]])
    2121    except ImportError:
    2222        raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\
    2323                                   "a non-existing package.")
  • django/contrib/admin/views/template.py

     
    1515    # get a dict of {site_id : settings_module} for the validator
    1616    settings_modules = {}
    1717    for mod in settings.ADMIN_FOR:
    18         settings_module = __import__(mod, {}, {}, [''])
     18        settings_module = __import__(mod, {}, {}, [mod.split('.')[-1]])
    1919        settings_modules[settings_module.SITE_ID] = settings_module
    2020    site_list = Site.objects.in_bulk(settings_modules.keys()).values()
    2121    if request.POST:
  • django/contrib/admindocs/views.py

     
    114114        return missing_docutils_page(request)
    115115
    116116    if settings.ADMIN_FOR:
    117         settings_modules = [__import__(m, {}, {}, ['']) for m in settings.ADMIN_FOR]
     117        settings_modules = [__import__(m, {}, {}, [m.split('.')[-1]]) for m in settings.ADMIN_FOR]
    118118    else:
    119119        settings_modules = [settings]
    120120
    121121    views = []
    122122    for settings_mod in settings_modules:
    123         urlconf = __import__(settings_mod.ROOT_URLCONF, {}, {}, [''])
     123        urlconf = __import__(settings_mod.ROOT_URLCONF, {}, {}, [settings_mod.ROOT_URLCONF.split('.')[-1]])
    124124        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
    125125        if Site._meta.installed:
    126126            site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
     
    146146
    147147    mod, func = urlresolvers.get_mod_func(view)
    148148    try:
    149         view_func = getattr(__import__(mod, {}, {}, ['']), func)
     149        view_func = getattr(__import__(mod, {}, {}, [mod.split('.')[-1]]), func)
    150150    except (ImportError, AttributeError):
    151151        raise Http404
    152152    title, body, metadata = utils.parse_docstring(view_func.__doc__)
     
    257257def template_detail(request, template):
    258258    templates = []
    259259    for site_settings_module in settings.ADMIN_FOR:
    260         settings_mod = __import__(site_settings_module, {}, {}, [''])
     260        settings_mod = __import__(site_settings_module, {}, {}, [site_settings_module.split('.')[-1]])
    261261        if Site._meta.installed:
    262262            site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
    263263        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

     
    934934    lib = libraries.get(module_name, None)
    935935    if not lib:
    936936        try:
    937             mod = __import__(module_name, {}, {}, [''])
     937            mod = __import__(module_name, {}, {}, [module_name.split('.')[-1]])
    938938        except ImportError, e:
    939939            raise InvalidTemplateLibrary("Could not load template library from %s, %s" % (module_name, e))
    940940        try:
  • tests/regressiontests/dynamic_imports/tests.py

    Property changes on: tests/regressiontests/dynamic_imports
    ___________________________________________________________________
    Added: svn:ignore
       + *.pyc
    
    
     
     1__test__ = {'API_TESTS': """
     2>>> import sys
     3>>> import os
     4>>> mod_name = os.environ['DJANGO_SETTINGS_MODULE']
     5>>> mod = __import__(mod_name, {}, {}, [mod_name.split('.')[-1]])
     6>>> from django.core.management import setup_environ
     7>>> d = setup_environ(mod)
     8>>> [k for k in sys.modules if k.endswith('.') or '..' in k]
     9[]
     10"""}
Back to Top