Index: django/test/client.py
===================================================================
--- django/test/client.py	(revision 8272)
+++ django/test/client.py	(working copy)
@@ -170,7 +170,7 @@
         Obtains the current session variables.
         """
         if 'django.contrib.sessions' in settings.INSTALLED_APPS:
-            engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
+            engine = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]])
             cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
             if cookie:
                 return engine.SessionStore(cookie.value)
@@ -295,7 +295,7 @@
         user = authenticate(**credentials)
         if user and user.is_active \
                 and 'django.contrib.sessions' in settings.INSTALLED_APPS:
-            engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
+            engine = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]])
 
             # Create a fake request to store login details.
             request = HttpRequest()
@@ -327,6 +327,6 @@
 
         Causes the authenticated user to be logged out.
         """
-        session = __import__(settings.SESSION_ENGINE, {}, {}, ['']).SessionStore()
+        session = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]]).SessionStore()
         session.delete(session_key=self.cookies[settings.SESSION_COOKIE_NAME].value)
         self.cookies = SimpleCookie()
Index: django/db/__init__.py
===================================================================
--- django/db/__init__.py	(revision 8272)
+++ django/db/__init__.py	(working copy)
@@ -13,15 +13,15 @@
     # Most of the time, the database backend will be one of the official
     # backends that ships with Django, so look there first.
     _import_path = 'django.db.backends.'
-    backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, [''])
-    creation = __import__('%s%s.creation' % (_import_path, settings.DATABASE_ENGINE), {}, {}, [''])
+    backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, ['base'])
+    creation = __import__('%s%s.creation' % (_import_path, settings.DATABASE_ENGINE), {}, {}, ['creation'])
 except ImportError, e:
     # If the import failed, we might be looking for a database backend
     # distributed external to Django. So we'll try that next.
     try:
         _import_path = ''
-        backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, [''])
-        creation = __import__('%s.creation' % settings.DATABASE_ENGINE, {}, {}, [''])
+        backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, ['base'])
+        creation = __import__('%s.creation' % settings.DATABASE_ENGINE, {}, {}, ['creation'])
     except ImportError, e_user:
         # The database backend wasn't found. Display a helpful error message
         # listing all possible (built-in) database backends.
@@ -36,7 +36,7 @@
 
 def _import_database_module(import_path='', module_name=''):
     """Lazily import a database module when requested."""
-    return __import__('%s%s.%s' % (import_path, settings.DATABASE_ENGINE, module_name), {}, {}, [''])
+    return __import__('%s%s.%s' % (import_path, settings.DATABASE_ENGINE, module_name), {}, {}, [module_name])
 
 # We don't want to import the introspect module unless someone asks for it, so
 # lazily load it on demmand.
Index: django/conf/__init__.py
===================================================================
--- django/conf/__init__.py	(revision 8272)
+++ django/conf/__init__.py	(working copy)
@@ -89,7 +89,7 @@
         self.SETTINGS_MODULE = settings_module
 
         try:
-            mod = __import__(self.SETTINGS_MODULE, {}, {}, [''])
+            mod = __import__(self.SETTINGS_MODULE, {}, {}, [self.SETTINGS_MODULE.split('.')[-1]])
         except ImportError, e:
             raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
 
@@ -109,7 +109,7 @@
         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], {}, {}, [app[:-2].split('.')[-1]]).__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))
Index: django/core/servers/fastcgi.py
===================================================================
--- django/core/servers/fastcgi.py	(revision 8272)
+++ django/core/servers/fastcgi.py	(working copy)
@@ -128,7 +128,7 @@
     wsgi_opts['debug'] = False # Turn off flup tracebacks
 
     try:
-        WSGIServer = getattr(__import__('flup.' + flup_module, '', '', flup_module), 'WSGIServer')
+        WSGIServer = getattr(__import__('flup.' + flup_module, '', '', [flup_module]), 'WSGIServer')
     except:
         print "Can't import flup." + flup_module
         return False
Index: django/core/serializers/__init__.py
===================================================================
--- django/core/serializers/__init__.py	(revision 8272)
+++ django/core/serializers/__init__.py	(working copy)
@@ -36,7 +36,7 @@
 
 def register_serializer(format, serializer_module):
     """Register a new serializer by passing in a module name."""
-    module = __import__(serializer_module, {}, {}, [''])
+    module = __import__(serializer_module, {}, {}, [serializer_module.split('.')[-1]])
     _serializers[format] = module
 
 def unregister_serializer(format):
Index: django/core/urlresolvers.py
===================================================================
--- django/core/urlresolvers.py	(revision 8272)
+++ django/core/urlresolvers.py	(working copy)
@@ -51,7 +51,7 @@
             lookup_view = lookup_view.encode('ascii')
             mod_name, func_name = get_mod_func(lookup_view)
             if func_name != '':
-                lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
+                lookup_view = getattr(__import__(mod_name, {}, {}, [mod_name.split('.')[-1]]), func_name)
         except (ImportError, AttributeError):
             if not can_fail:
                 raise
@@ -195,7 +195,7 @@
     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, {}, {}, [mod_name.split('.')[-1]]), func_name)
         except (ImportError, AttributeError):
             raise NoReverseMatch
         if lookup_view != self.callback:
@@ -255,7 +255,7 @@
             return self._urlconf_module
         except AttributeError:
             try:
-                self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
+                self._urlconf_module = __import__(self.urlconf_name, {}, {}, [self.urlconf_name.split('.')[-1]])
             except Exception, e:
                 # Either an invalid urlconf_name, such as "foo.bar.", or some
                 # kind of problem during the actual import.
@@ -271,7 +271,7 @@
         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, {}, {}, [mod_name.split('.')[-1]]), func_name), {}
         except (ImportError, AttributeError), e:
             raise ViewDoesNotExist, "Tried %s. Error was: %s" % (callback, str(e))
 
Index: django/core/handlers/base.py
===================================================================
--- django/core/handlers/base.py	(revision 8272)
+++ django/core/handlers/base.py	(working copy)
@@ -35,7 +35,7 @@
                 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, {}, {}, [mw_module.split('.')[-1]])
             except ImportError, e:
                 raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e)
             try:
Index: django/core/files/storage.py
===================================================================
--- django/core/files/storage.py	(revision 8272)
+++ django/core/files/storage.py	(working copy)
@@ -203,7 +203,7 @@
         raise ImproperlyConfigured("%s isn't a storage module." % import_path)
     module, classname = import_path[:dot], import_path[dot+1:]
     try:
-        mod = __import__(module, {}, {}, [''])
+        mod = __import__(module, {}, {}, [module.split('.')[-1]])
     except ImportError, e:
         raise ImproperlyConfigured('Error importing storage module %s: "%s"' % (module, e))
     try:
Index: django/core/cache/__init__.py
===================================================================
--- django/core/cache/__init__.py	(revision 8272)
+++ django/core/cache/__init__.py	(working copy)
@@ -48,9 +48,9 @@
         host = host[:-1]
 
     if scheme in BACKENDS:
-        module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, [''])
+        module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, [BACKENDS[scheme]])
     else:
-        module = __import__(scheme, {}, {}, [''])
+        module = __import__(scheme, {}, {}, [scheme.split('.')[-1]])
     return getattr(module, 'CacheClass')(host, params)
 
 cache = get_cache(settings.CACHE_BACKEND)
Index: django/core/management/commands/flush.py
===================================================================
--- django/core/management/commands/flush.py	(revision 8272)
+++ django/core/management/commands/flush.py	(working copy)
@@ -26,7 +26,7 @@
         # dispatcher events.
         for app_name in settings.INSTALLED_APPS:
             try:
-                __import__(app_name + '.management', {}, {}, [''])
+                __import__(app_name + '.management', {}, {}, ['management'])
             except ImportError:
                 pass
 
Index: django/core/management/commands/syncdb.py
===================================================================
--- django/core/management/commands/syncdb.py	(revision 8272)
+++ django/core/management/commands/syncdb.py	(working copy)
@@ -33,7 +33,7 @@
         # dispatcher events.
         for app_name in settings.INSTALLED_APPS:
             try:
-                __import__(app_name + '.management', {}, {}, [''])
+                __import__(app_name + '.management', {}, {}, ['management'])
             except ImportError, exc:
                 # This is slightly hackish. We want to ignore ImportErrors
                 # if the "management" module itself is missing -- but we don't
Index: django/core/management/__init__.py
===================================================================
--- django/core/management/__init__.py	(revision 8272)
+++ django/core/management/__init__.py	(working copy)
@@ -308,7 +308,7 @@
     project_name = os.path.basename(project_directory)
     settings_name = os.path.splitext(settings_filename)[0]
     sys.path.append(os.path.join(project_directory, os.pardir))
-    project_module = __import__(project_name, {}, {}, [''])
+    project_module = __import__(project_name, {}, {}, [project_name.split('.')[-1]])
     sys.path.pop()
 
     # Set DJANGO_SETTINGS_MODULE appropriately.
Index: django/templatetags/__init__.py
===================================================================
--- django/templatetags/__init__.py	(revision 8272)
+++ django/templatetags/__init__.py	(working copy)
@@ -2,6 +2,6 @@
 
 for a in settings.INSTALLED_APPS:
     try:
-        __path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__)
+        __path__.extend(__import__(a + '.templatetags', {}, {}, ['templatetags']).__path__)
     except ImportError:
         pass
Index: django/views/i18n.py
===================================================================
--- django/views/i18n.py	(revision 8272)
+++ django/views/i18n.py	(working copy)
@@ -128,7 +128,7 @@
     paths = []
     # first load all english languages files for defaults
     for package in packages:
-        p = __import__(package, {}, {}, [''])
+        p = __import__(package, {}, {}, [package.split('.')[-1]])
         path = os.path.join(os.path.dirname(p.__file__), 'locale')
         paths.append(path)
         try:
Index: django/contrib/admin/views/template.py
===================================================================
--- django/contrib/admin/views/template.py	(revision 8272)
+++ django/contrib/admin/views/template.py	(working copy)
@@ -14,7 +14,7 @@
     # 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, {}, {}, [mod.split('.')[-1]])
         settings_modules[settings_module.SITE_ID] = settings_module
     manipulator = TemplateValidator(settings_modules)
     new_data, errors = {}, {}
Index: django/contrib/admindocs/views.py
===================================================================
--- django/contrib/admindocs/views.py	(revision 8272)
+++ django/contrib/admindocs/views.py	(working copy)
@@ -112,13 +112,13 @@
         return missing_docutils_page(request)
 
     if settings.ADMIN_FOR:
-        settings_modules = [__import__(m, {}, {}, ['']) for m in settings.ADMIN_FOR]
+        settings_modules = [__import__(m, {}, {}, [m.split('.')[-1]]) 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, {}, {}, [settings_mod.ROOT_URLCONF.split('.')[-1]])
         view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
         if Site._meta.installed:
             site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
@@ -145,7 +145,7 @@
 
     mod, func = urlresolvers.get_mod_func(view)
     try:
-        view_func = getattr(__import__(mod, {}, {}, ['']), func)
+        view_func = getattr(__import__(mod, {}, {}, [mod.split('.')[-1]]), func)
     except (ImportError, AttributeError):
         raise Http404
     title, body, metadata = utils.parse_docstring(view_func.__doc__)
@@ -259,7 +259,7 @@
 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, {}, {}, [site_settings_module.split('.')[-1]])
         if Site._meta.installed:
             site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
         else:
Index: django/contrib/sessions/middleware.py
===================================================================
--- django/contrib/sessions/middleware.py	(revision 8272)
+++ django/contrib/sessions/middleware.py	(working copy)
@@ -6,7 +6,7 @@
 
 class SessionMiddleware(object):
     def process_request(self, request):
-        engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
+        engine = __import__(settings.SESSION_ENGINE, {}, {}, [settings.SESSION_ENGINE.split('.')[-1]])
         session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME, None)
         request.session = engine.SessionStore(session_key)
 
Index: django/template/__init__.py
===================================================================
--- django/template/__init__.py	(revision 8272)
+++ django/template/__init__.py	(working copy)
@@ -917,7 +917,7 @@
     lib = libraries.get(module_name, None)
     if not lib:
         try:
-            mod = __import__(module_name, {}, {}, [''])
+            mod = __import__(module_name, {}, {}, [module_name.split('.')[-1]])
         except ImportError, e:
             raise InvalidTemplateLibrary("Could not load template library from %s, %s" % (module_name, e))
         try:

Property changes on: tests/regressiontests/dynamic_imports
___________________________________________________________________
Name: svn:ignore
   + *.pyc


Index: tests/regressiontests/dynamic_imports/__init__.py
===================================================================
Index: tests/regressiontests/dynamic_imports/tests.py
===================================================================
--- tests/regressiontests/dynamic_imports/tests.py	(revision 0)
+++ tests/regressiontests/dynamic_imports/tests.py	(revision 0)
@@ -0,0 +1,10 @@
+__test__ = {'API_TESTS': """
+>>> import sys
+>>> import os
+>>> mod_name = os.environ['DJANGO_SETTINGS_MODULE']
+>>> mod = __import__(mod_name, {}, {}, [mod_name.split('.')[-1]])
+>>> from django.core.management import setup_environ
+>>> d = setup_environ(mod)
+>>> [k for k in sys.modules if k.endswith('.') or '..' in k]
+[]
+"""}
Index: tests/regressiontests/dynamic_imports/models.py
===================================================================
