1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

magic-removal: Fixes #1396 -- Added exception handler (and silent_variable_failure check) for edge case in descriptor lookup.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2604 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2006-04-01 03:14:35 +00:00
parent 859e652d36
commit 0d6f2f8707

View File

@ -603,9 +603,9 @@ def resolve_variable(path, context):
if path[0] in '0123456789':
number_type = '.' in path and float or int
try:
current = number_type(path)
current = number_type(path)
except ValueError:
current = settings.TEMPLATE_STRING_IF_INVALID
current = settings.TEMPLATE_STRING_IF_INVALID
elif path[0] in ('"', "'") and path[0] == path[-1]:
current = path[1:-1]
else:
@ -637,6 +637,11 @@ def resolve_variable(path, context):
current = current[int(bits[0])]
except (IndexError, ValueError, KeyError):
raise VariableDoesNotExist, "Failed lookup for key [%s] in %r" % (bits[0], current) # missing attribute
except Exception, e:
if getattr(e, 'silent_variable_failure', False):
current = settings.TEMPLATE_STRING_IF_INVALID
else:
raise
del bits[0]
return current