Fixed #13311 -- Modified the tag library import process so it doesn't mask import errors in the tag library itself. Thanks to amccurdy for the report, and Alex Gaynor for the suggested fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12944 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-04-11 06:48:46 +00:00
parent b579350cd1
commit aed032d0ac
1 changed files with 12 additions and 2 deletions

View File

@ -48,6 +48,7 @@ u'<html><h1>Hello</h1></html>'
>>> t.render(c) >>> t.render(c)
u'<html></html>' u'<html></html>'
""" """
import imp
import re import re
from inspect import getargspec from inspect import getargspec
@ -979,10 +980,19 @@ def import_library(taglib_module):
Verifies that the library contains a 'register' attribute, and Verifies that the library contains a 'register' attribute, and
returns that attribute as the representation of the library returns that attribute as the representation of the library
""" """
# We need to be able to tell the difference between a tag library that
# doesn't exist, and a tag library with errors in it.
# find_module() finds, but doesn't actually load the module requested.
# If it raises ImportError, it means the module doesn't exist.
# If you then use load_module(), any ImportError is guaranteed to be
# an actual import problem with the module.
app_path, taglib = taglib_module.rsplit('.',1)
app_module = import_module(app_path)
try: try:
mod = import_module(taglib_module) imp.find_module(taglib, app_module.__path__)
except ImportError: except ImportError,e:
return None return None
mod = import_module(taglib_module)
try: try:
return mod.register return mod.register
except AttributeError: except AttributeError: