Ticket #8193: importlib.diff
File importlib.diff, 34.0 KB (added by , 16 years ago) |
---|
-
django/test/client.py
19 19 from django.utils.encoding import smart_str 20 20 from django.utils.http import urlencode 21 21 from django.utils.itercompat import is_iterable 22 from django.utils.importlib import import_module 22 23 from django.db import transaction, close_connection 23 24 24 25 BOUNDARY = 'BoUnDaRyStRiNg' … … 175 176 Obtains the current session variables. 176 177 """ 177 178 if 'django.contrib.sessions' in settings.INSTALLED_APPS: 178 engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])179 engine = import_module(settings.SESSION_ENGINE) 179 180 cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None) 180 181 if cookie: 181 182 return engine.SessionStore(cookie.value) … … 398 399 user = authenticate(**credentials) 399 400 if user and user.is_active \ 400 401 and 'django.contrib.sessions' in settings.INSTALLED_APPS: 401 engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])402 engine = import_module(settings.SESSION_ENGINE) 402 403 403 404 # Create a fake request to store login details. 404 405 request = HttpRequest() … … 433 434 434 435 Causes the authenticated user to be logged out. 435 436 """ 436 session = __import__(settings.SESSION_ENGINE, {}, {}, ['']).SessionStore()437 session = import_module(settings.SESSION_ENGINE).SessionStore() 437 438 session.delete(session_key=self.cookies[settings.SESSION_COOKIE_NAME].value) 438 439 self.cookies = SimpleCookie() 439 440 -
django/db/models/loading.py
3 3 from django.conf import settings 4 4 from django.core.exceptions import ImproperlyConfigured 5 5 from django.utils.datastructures import SortedDict 6 from django.utils.importlib import import_module 6 7 7 8 import sys 8 9 import os … … 69 70 """ 70 71 self.handled[app_name] = None 71 72 self.nesting_level += 1 72 mod = __import__(app_name, {}, {}, ['models']) 73 self.nesting_level -= 1 74 if not hasattr(mod, 'models'): 73 try: 74 models = import_module('.models', app_name) 75 except ImportError: 76 self.nesting_level -= 1 75 77 if can_postpone: 76 78 # Either the app has no models, or the package is still being 77 79 # imported by Python and the model module isn't available yet. … … 79 81 # populate). 80 82 self.postponed.append(app_name) 81 83 return None 82 if mod.models not in self.app_store: 83 self.app_store[mod.models] = len(self.app_store) 84 return mod.models 84 self.nesting_level -= 1 85 if models not in self.app_store: 86 self.app_store[models] = len(self.app_store) 87 return models 85 88 86 89 def app_cache_ready(self): 87 90 """ -
django/db/__init__.py
3 3 from django.core import signals 4 4 from django.core.exceptions import ImproperlyConfigured 5 5 from django.utils.functional import curry 6 from django.utils.importlib import import_module 6 7 7 8 __all__ = ('backend', 'connection', 'DatabaseError', 'IntegrityError') 8 9 … … 13 14 # Most of the time, the database backend will be one of the official 14 15 # backends that ships with Django, so look there first. 15 16 _import_path = 'django.db.backends.' 16 backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, ['']) 17 backend = import_module('.base', 18 '%s%s' % (_import_path, settings.DATABASE_ENGINE)) 17 19 except ImportError, e: 18 20 # If the import failed, we might be looking for a database backend 19 21 # distributed external to Django. So we'll try that next. 20 22 try: 21 23 _import_path = '' 22 backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, [''])24 backend = import_module('.base', settings.DATABASE_ENGINE) 23 25 except ImportError, e_user: 24 26 # The database backend wasn't found. Display a helpful error message 25 27 # listing all possible (built-in) database backends. -
django/conf/__init__.py
11 11 12 12 from django.conf import global_settings 13 13 from django.utils.functional import LazyObject 14 from django.utils import importlib 14 15 15 16 ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE" 16 17 … … 68 69 self.SETTINGS_MODULE = settings_module 69 70 70 71 try: 71 mod = __import__(self.SETTINGS_MODULE, {}, {}, [''])72 mod = importlib.import_module(self.SETTINGS_MODULE) 72 73 except ImportError, e: 73 74 raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) 74 75 … … 88 89 new_installed_apps = [] 89 90 for app in self.INSTALLED_APPS: 90 91 if app.endswith('.*'): 91 appdir = os.path.dirname(__import__(app[:-2], {}, {}, ['']).__file__) 92 app_mod = importlib.import_module(app[:-2]) 93 appdir = os.path.dirname(app_mod.__file__) 92 94 app_subdirs = os.listdir(appdir) 93 95 app_subdirs.sort() 94 96 for d in app_subdirs: -
django/core/servers/fastcgi.py
12 12 pass to this server. 13 13 """ 14 14 15 from django.utils import importlib 15 16 import sys, os 16 17 17 18 __version__ = "0.1" … … 113 114 'maxSpare': int(options["maxspare"]), 114 115 'minSpare': int(options["minspare"]), 115 116 'maxChildren': int(options["maxchildren"]), 116 'maxRequests': int(options["maxrequests"]), 117 'maxRequests': int(options["maxrequests"]), 117 118 } 118 119 flup_module += '_fork' 119 120 elif options['method'] in ('thread', 'threaded'): … … 128 129 wsgi_opts['debug'] = False # Turn off flup tracebacks 129 130 130 131 try: 131 WSGIServer = getattr(__import__('flup.' + flup_module, '', '', flup_module), 'WSGIServer') 132 module = importlib_import_module('.%s' % flup_module, 'flup') 133 WSGIServer = module.WSGIServer 132 134 except: 133 135 print "Can't import flup." + flup_module 134 136 return False -
django/core/serializers/__init__.py
17 17 """ 18 18 19 19 from django.conf import settings 20 from django.utils import importlib 20 21 21 22 # Built-in serializers 22 23 BUILTIN_SERIALIZERS = { … … 47 48 directly into the global register of serializers. Adding serializers 48 49 directly is not a thread-safe operation. 49 50 """ 50 module = __import__(serializer_module, {}, {}, [''])51 module = importlib.import_module(serializer_module) 51 52 if serializers is None: 52 53 _serializers[format] = module 53 54 else: -
django/core/urlresolvers.py
14 14 from django.utils.datastructures import MultiValueDict 15 15 from django.utils.encoding import iri_to_uri, force_unicode, smart_str 16 16 from django.utils.functional import memoize 17 from django.utils.importlib import import_module 17 18 from django.utils.regex_helper import normalize 18 19 from django.utils.thread_support import currentThread 19 20 … … 54 55 lookup_view = lookup_view.encode('ascii') 55 56 mod_name, func_name = get_mod_func(lookup_view) 56 57 if func_name != '': 57 lookup_view = getattr( __import__(mod_name, {}, {}, ['']), func_name)58 lookup_view = getattr(import_module(mod_name), func_name) 58 59 if not callable(lookup_view): 59 60 raise AttributeError("'%s.%s' is not a callable." % (mod_name, func_name)) 60 61 except (ImportError, AttributeError): … … 197 198 try: 198 199 return self._urlconf_module 199 200 except AttributeError: 200 self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])201 self._urlconf_module = import_module(self.urlconf_name) 201 202 return self._urlconf_module 202 203 urlconf_module = property(_get_urlconf_module) 203 204 … … 215 216 callback = getattr(self.urlconf_module, 'handler%s' % view_type) 216 217 mod_name, func_name = get_mod_func(callback) 217 218 try: 218 return getattr( __import__(mod_name, {}, {}, ['']), func_name), {}219 return getattr(import_module(mod_name), func_name), {} 219 220 except (ImportError, AttributeError), e: 220 221 raise ViewDoesNotExist, "Tried %s. Error was: %s" % (callback, str(e)) 221 222 -
django/core/handlers/base.py
3 3 from django import http 4 4 from django.core import signals 5 5 from django.utils.encoding import force_unicode 6 from django.utils.importlib import import_module 6 7 7 8 class BaseHandler(object): 8 9 # Changes that are always applied to a response (in this order). … … 35 36 raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path 36 37 mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:] 37 38 try: 38 mod = __import__(mw_module, {}, {}, [''])39 mod = import_module(mw_module) 39 40 except ImportError, e: 40 41 raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e) 41 42 try: -
django/core/files/uploadhandler.py
10 10 from django.conf import settings 11 11 from django.core.exceptions import ImproperlyConfigured 12 12 from django.core.files.uploadedfile import TemporaryUploadedFile, InMemoryUploadedFile 13 from django.utils import importlib 13 14 14 15 __all__ = ['UploadFileException','StopUpload', 'SkipFile', 'FileUploadHandler', 15 16 'TemporaryFileUploadHandler', 'MemoryFileUploadHandler', … … 201 202 i = path.rfind('.') 202 203 module, attr = path[:i], path[i+1:] 203 204 try: 204 mod = __import__(module, {}, {}, [attr])205 mod = importlib.import_module(module) 205 206 except ImportError, e: 206 207 raise ImproperlyConfigured('Error importing upload handler module %s: "%s"' % (module, e)) 207 208 except ValueError, e: -
django/core/files/storage.py
8 8 from django.core.files.move import file_move_safe 9 9 from django.utils.encoding import force_unicode 10 10 from django.utils.functional import LazyObject 11 from django.utils.importlib import import_module 11 12 from django.utils.text import get_valid_filename 12 13 from django.utils._os import safe_join 13 14 … … 230 231 raise ImproperlyConfigured("%s isn't a storage module." % import_path) 231 232 module, classname = import_path[:dot], import_path[dot+1:] 232 233 try: 233 mod = __import__(module, {}, {}, [''])234 mod = import_module(module) 234 235 except ImportError, e: 235 236 raise ImproperlyConfigured('Error importing storage module %s: "%s"' % (module, e)) 236 237 try: -
django/core/cache/__init__.py
19 19 from django.conf import settings 20 20 from django.core import signals 21 21 from django.core.cache.backends.base import InvalidCacheBackendError 22 from django.utils import importlib 22 23 23 24 # Name for use in settings file --> name of module in "backends" directory. 24 25 # Any backend scheme that is not in this dictionary is treated as a Python … … 58 59 def get_cache(backend_uri): 59 60 scheme, host, params = parse_backend_uri(backend_uri) 60 61 if scheme in BACKENDS: 61 module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, [''])62 name = 'django.core.cache.backends.%s' % BACKENDS[scheme] 62 63 else: 63 module = __import__(scheme, {}, {}, ['']) 64 name = scheme 65 module = importlib.import_module(name) 64 66 return getattr(module, 'CacheClass')(host, params) 65 67 66 68 cache = get_cache(settings.CACHE_BACKEND) -
django/core/management/commands/startapp.py
1 1 import os 2 2 3 3 from django.core.management.base import copy_helper, CommandError, LabelCommand 4 from django.utils.importlib import import_module 4 5 5 6 class Command(LabelCommand): 6 7 help = "Creates a Django app directory structure for the given app name in the current directory." … … 26 27 27 28 # Check that the app_name cannot be imported. 28 29 try: 29 __import__(app_name)30 import_module(app_name) 30 31 except ImportError: 31 32 pass 32 33 else: -
django/core/management/commands/flush.py
1 1 from django.core.management.base import NoArgsCommand, CommandError 2 2 from django.core.management.color import no_style 3 from django.utils.importlib import import_module 3 4 from optparse import make_option 4 5 5 6 class Command(NoArgsCommand): … … 23 24 # dispatcher events. 24 25 for app_name in settings.INSTALLED_APPS: 25 26 try: 26 __import__(app_name + '.management', {}, {}, [''])27 import_module('.management', app_name) 27 28 except ImportError: 28 29 pass 29 30 -
django/core/management/commands/syncdb.py
1 1 from django.core.management.base import NoArgsCommand 2 2 from django.core.management.color import no_style 3 from django.utils.importlib import import_module 3 4 from optparse import make_option 4 5 import sys 5 6 … … 30 31 # dispatcher events. 31 32 for app_name in settings.INSTALLED_APPS: 32 33 try: 33 __import__(app_name + '.management', {}, {}, [''])34 import_module('.management', app_name) 34 35 except ImportError, exc: 35 36 # This is slightly hackish. We want to ignore ImportErrors 36 37 # if the "management" module itself is missing -- but we don't -
django/core/management/commands/startproject.py
1 1 from django.core.management.base import copy_helper, CommandError, LabelCommand 2 from django.utils.importlib import import_module 2 3 import os 3 4 import re 4 5 from random import choice … … 20 21 21 22 # Check that the project_name cannot be imported. 22 23 try: 23 __import__(project_name)24 import_module(project_name) 24 25 except ImportError: 25 26 pass 26 27 else: -
django/core/management/__init__.py
5 5 6 6 import django 7 7 from django.core.management.base import BaseCommand, CommandError, handle_default_options 8 from django.utils.importlib import import_module 8 9 9 10 # For backwards compatibility: get_version() used to be in this module. 10 11 get_version = django.get_version … … 63 64 class instance. All errors raised by the import process 64 65 (ImportError, AttributeError) are allowed to propagate. 65 66 """ 66 return getattr(__import__('%s.management.commands.%s' % (app_name, name),67 {}, {}, ['Command']), 'Command')()67 module = import_module('%s.management.commands.%s' % (app_name, name)) 68 return module.Command() 68 69 69 70 def get_commands(): 70 71 """ … … 104 105 # Find the project directory 105 106 try: 106 107 from django.conf import settings 107 project_directory = setup_environ( 108 __import__( 109 settings.SETTINGS_MODULE, {}, {}, 110 (settings.SETTINGS_MODULE.split(".")[-1],) 111 ), settings.SETTINGS_MODULE 112 ) 108 module = import_module(settings.SETTINGS_MODULE.split('.', 1)[0]) 109 project_directory = setup_environ(module, 110 settings.SETTINGS_MODULE) 113 111 except (AttributeError, EnvironmentError, ImportError): 114 112 project_directory = None 115 113 … … 328 326 # Import the project module. We add the parent directory to PYTHONPATH to 329 327 # avoid some of the path errors new users can have. 330 328 sys.path.append(os.path.join(project_directory, os.pardir)) 331 project_module = __import__(project_name, {}, {}, [''])329 project_module = import_module(project_name) 332 330 sys.path.pop() 333 331 334 332 return project_directory -
django/templatetags/__init__.py
1 1 from django.conf import settings 2 from django.utils import importlib 2 3 3 4 for a in settings.INSTALLED_APPS: 4 5 try: 5 __path__.extend( __import__(a + '.templatetags', {}, {}, ['']).__path__)6 __path__.extend(importlib.import_module('.templatetags', a).__path__) 6 7 except ImportError: 7 8 pass -
django/views/i18n.py
1 1 from django import http 2 from django.conf import settings 3 from django.utils import importlib 2 4 from django.utils.translation import check_for_language, activate, to_locale, get_language 3 5 from django.utils.text import javascript_quote 4 from django.conf import settings5 6 import os 6 7 import gettext as gettext_module 7 8 … … 128 129 paths = [] 129 130 # first load all english languages files for defaults 130 131 for package in packages: 131 p = __import__(package, {}, {}, [''])132 p = importlib.import_module(package) 132 133 path = os.path.join(os.path.dirname(p.__file__), 'locale') 133 134 paths.append(path) 134 135 try: -
django/views/debug.py
6 6 from django.conf import settings 7 7 from django.template import Template, Context, TemplateDoesNotExist 8 8 from django.utils.html import escape 9 from django.utils.importlib import import_module 9 10 from django.http import HttpResponse, HttpResponseServerError, HttpResponseNotFound 10 11 from django.utils.encoding import smart_unicode, smart_str 11 12 … … 67 68 self.loader_debug_info = [] 68 69 for loader in template_source_loaders: 69 70 try: 70 source_list_func = getattr(__import__(loader.__module__, {}, {}, ['get_template_sources']), 'get_template_sources') 71 module = import_module(loader.__module__) 72 source_list_func = module.get_template_sources 71 73 # NOTE: This assumes exc_value is the name of the template that 72 74 # the loader attempted to load. 73 75 template_list = [{'name': t, 'exists': os.path.exists(t)} \ -
django/utils/importlib.py
1 # Taken from Python 2.7 with permission from/by the original author. 2 import sys 3 4 def _resolve_name(name, package, level): 5 """Return the absolute name of the module to be imported.""" 6 if not hasattr(package, 'rindex'): 7 raise ValueError("'package' not set to a string") 8 dot = len(package) 9 for x in xrange(level, 1, -1): 10 try: 11 dot = package.rindex('.', 0, dot) 12 except ValueError: 13 raise ValueError("attempted relative import beyond top-level " 14 "package") 15 return "%s.%s" % (package[:dot], name) 16 17 18 def import_module(name, package=None): 19 """Import a module. 20 21 The 'package' argument is required when performing a relative import. It 22 specifies the package to use as the anchor point from which to resolve the 23 relative import to an absolute import. 24 25 """ 26 if name.startswith('.'): 27 if not package: 28 raise TypeError("relative imports require the 'package' argument") 29 level = 0 30 for character in name: 31 if character != '.': 32 break 33 level += 1 34 name = _resolve_name(name[level:], package, level) 35 __import__(name) 36 return sys.modules[name] -
django/utils/translation/trans_real.py
7 7 import gettext as gettext_module 8 8 from cStringIO import StringIO 9 9 10 from django.utils.importlib import import_module 10 11 from django.utils.safestring import mark_safe, SafeData 11 12 from django.utils.thread_support import currentThread 12 13 … … 125 126 126 127 if settings.SETTINGS_MODULE is not None: 127 128 parts = settings.SETTINGS_MODULE.split('.') 128 project = __import__(parts[0], {}, {}, [])129 project = import_module(parts[0]) 129 130 projectpath = os.path.join(os.path.dirname(project.__file__), 'locale') 130 131 else: 131 132 projectpath = None … … 176 177 res = _merge(projectpath) 177 178 178 179 for appname in settings.INSTALLED_APPS: 179 p = appname.rfind('.') 180 if p >= 0: 181 app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:]) 182 else: 183 app = __import__(appname, {}, {}, []) 184 180 app = import_module(appname) 185 181 apppath = os.path.join(os.path.dirname(app.__file__), 'locale') 186 182 187 183 if os.path.isdir(apppath): -
django/contrib/comments/__init__.py
3 3 from django.core.exceptions import ImproperlyConfigured 4 4 from django.contrib.comments.models import Comment 5 5 from django.contrib.comments.forms import CommentForm 6 from django.utils.importlib import import_module 6 7 7 8 DEFAULT_COMMENTS_APP = 'django.contrib.comments' 8 9 … … 18 19 19 20 # Try to import the package 20 21 try: 21 package = __import__(comments_app, '', '', [''])22 package = import_module(comments_app) 22 23 except ImportError: 23 24 raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\ 24 25 "a non-existing package.") -
django/contrib/admin/__init__.py
1 1 from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL 2 2 from django.contrib.admin.options import StackedInline, TabularInline 3 3 from django.contrib.admin.sites import AdminSite, site 4 from django.utils.importlib import import_module 4 5 5 6 # A flag to tell us if autodiscover is running. autodiscover will set this to 6 7 # True while running, and False when it finishes. … … 36 37 # fails silently -- apps that do weird things with __path__ might 37 38 # need to roll their own admin registration. 38 39 try: 39 app_path = __import__(app, {}, {}, [app.split('.')[-1]]).__path__40 app_path = import_module(app).__path__ 40 41 except AttributeError: 41 42 continue 42 43 … … 51 52 52 53 # Step 3: import the app's admin file. If this has errors we want them 53 54 # to bubble up. 54 __import__("%s.admin" % app)55 import_module("%s.admin" % app) 55 56 # autodiscover was successful, reset loading flag. 56 57 LOADING = False -
django/contrib/admin/views/template.py
4 4 from django.shortcuts import render_to_response 5 5 from django.contrib.sites.models import Site 6 6 from django.conf import settings 7 from django.utils.importlib import import_module 7 8 from django.utils.translation import ugettext_lazy as _ 8 9 9 10 … … 15 16 # get a dict of {site_id : settings_module} for the validator 16 17 settings_modules = {} 17 18 for mod in settings.ADMIN_FOR: 18 settings_module = __import__(mod, {}, {}, [''])19 settings_module = import_module(mod) 19 20 settings_modules[settings_module.SITE_ID] = settings_module 20 21 site_list = Site.objects.in_bulk(settings_modules.keys()).values() 21 22 if request.POST: -
django/contrib/admindocs/views.py
9 9 from django.core import urlresolvers 10 10 from django.contrib.admindocs import utils 11 11 from django.contrib.sites.models import Site 12 from django.utils.importlib import import_module 12 13 from django.utils.translation import ugettext as _ 13 14 from django.utils.safestring import mark_safe 14 15 import inspect, os, re … … 114 115 return missing_docutils_page(request) 115 116 116 117 if settings.ADMIN_FOR: 117 settings_modules = [ __import__(m, {}, {}, ['']) for m in settings.ADMIN_FOR]118 settings_modules = [import_module(m) for m in settings.ADMIN_FOR] 118 119 else: 119 120 settings_modules = [settings] 120 121 121 122 views = [] 122 123 for settings_mod in settings_modules: 123 urlconf = __import__(settings_mod.ROOT_URLCONF, {}, {}, [''])124 urlconf = import_module(settings_mod.ROOT_URLCONF) 124 125 view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns) 125 126 if Site._meta.installed: 126 127 site_obj = Site.objects.get(pk=settings_mod.SITE_ID) … … 146 147 147 148 mod, func = urlresolvers.get_mod_func(view) 148 149 try: 149 view_func = getattr( __import__(mod, {}, {}, ['']), func)150 view_func = getattr(import_module(mod), func) 150 151 except (ImportError, AttributeError): 151 152 raise Http404 152 153 title, body, metadata = utils.parse_docstring(view_func.__doc__) … … 257 258 def template_detail(request, template): 258 259 templates = [] 259 260 for site_settings_module in settings.ADMIN_FOR: 260 settings_mod = __import__(site_settings_module, {}, {}, [''])261 settings_mod = import_module(site_settings_module) 261 262 if Site._meta.installed: 262 263 site_obj = Site.objects.get(pk=settings_mod.SITE_ID) 263 264 else: -
django/contrib/auth/__init__.py
1 1 import datetime 2 2 from django.core.exceptions import ImproperlyConfigured 3 from django.utils.importlib import import_module 3 4 4 5 SESSION_KEY = '_auth_user_id' 5 6 BACKEND_SESSION_KEY = '_auth_user_backend' … … 9 10 i = path.rfind('.') 10 11 module, attr = path[:i], path[i+1:] 11 12 try: 12 mod = __import__(module, {}, {}, [attr])13 mod = import_module(module) 13 14 except ImportError, e: 14 15 raise ImproperlyConfigured, 'Error importing authentication backend %s: "%s"' % (module, e) 15 16 except ValueError, e: -
django/contrib/sessions/middleware.py
3 3 from django.conf import settings 4 4 from django.utils.cache import patch_vary_headers 5 5 from django.utils.http import cookie_date 6 from django.utils.importlib import import_module 6 7 7 8 class SessionMiddleware(object): 8 9 def process_request(self, request): 9 engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])10 engine = import_module(settings.SESSION_ENGINE) 10 11 session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME, None) 11 12 request.session = engine.SessionStore(session_key) 12 13 -
django/template/__init__.py
52 52 from inspect import getargspec 53 53 from django.conf import settings 54 54 from django.template.context import Context, RequestContext, ContextPopException 55 from django.utils.importlib import import_module 55 56 from django.utils.itercompat import is_iterable 56 57 from django.utils.functional import curry, Promise 57 58 from django.utils.text import smart_split … … 935 936 lib = libraries.get(module_name, None) 936 937 if not lib: 937 938 try: 938 mod = __import__(module_name, {}, {}, [''])939 mod = import_module(module_name) 939 940 except ImportError, e: 940 941 raise InvalidTemplateLibrary("Could not load template library from %s, %s" % (module_name, e)) 941 942 try: -
django/template/loaders/app_directories.py
10 10 from django.core.exceptions import ImproperlyConfigured 11 11 from django.template import TemplateDoesNotExist 12 12 from django.utils._os import safe_join 13 from django.utils.importlib import import_module 13 14 14 15 # At compile time, cache the directories to search. 15 16 fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() 16 17 app_template_dirs = [] 17 18 for app in settings.INSTALLED_APPS: 18 i = app.rfind('.')19 if i == -1:20 m, a = app, None21 else:22 m, a = app[:i], app[i+1:]23 19 try: 24 if a is None: 25 mod = __import__(m, {}, {}, []) 26 else: 27 mod = getattr(__import__(m, {}, {}, [a]), a) 20 mod = import_module(app) 28 21 except ImportError, e: 29 22 raise ImproperlyConfigured, 'ImportError %s: %s' % (app, e.args[0]) 30 23 template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates') -
django/template/context.py
1 1 from django.conf import settings 2 2 from django.core.exceptions import ImproperlyConfigured 3 from django.utils.importlib import import_module 3 4 4 5 _standard_context_processors = None 5 6 … … 62 63 63 64 def update(self, other_dict): 64 65 "Like dict.update(). Pushes an entire dictionary's keys and values onto the context." 65 if not hasattr(other_dict, '__getitem__'): 66 if not hasattr(other_dict, '__getitem__'): 66 67 raise TypeError('other_dict must be a mapping (dictionary-like) object.') 67 68 self.dicts = [other_dict] + self.dicts 68 69 return other_dict … … 77 78 i = path.rfind('.') 78 79 module, attr = path[:i], path[i+1:] 79 80 try: 80 mod = __import__(module, {}, {}, [attr])81 mod = import_module(module) 81 82 except ImportError, e: 82 83 raise ImproperlyConfigured('Error importing request processor module %s: "%s"' % (module, e)) 83 84 try: -
django/template/loader.py
22 22 23 23 from django.core.exceptions import ImproperlyConfigured 24 24 from django.template import Origin, Template, Context, TemplateDoesNotExist, add_to_builtins 25 from django.utils.importlib import import_module 25 26 from django.conf import settings 26 27 27 28 template_source_loaders = None … … 51 52 i = path.rfind('.') 52 53 module, attr = path[:i], path[i+1:] 53 54 try: 54 mod = __import__(module, globals(), locals(), [attr])55 mod = import_module(module) 55 56 except ImportError, e: 56 57 raise ImproperlyConfigured, 'Error importing template source loader %s: "%s"' % (module, e) 57 58 try: -
AUTHORS
75 75 Chris Cahoon <chris.cahoon@gmail.com> 76 76 Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com> 77 77 Trevor Caira <trevor@caira.com> 78 Brett Cannon <brett@python.org> 78 79 Ricardo Javier Cárdenes Medina <ricardo.cardenes@gmail.com> 79 80 Jeremy Carbaugh <jcarbaugh@gmail.com> 80 81 carljm <carl@dirtcircle.com>