Ticket #11421: 11421.patch
File 11421.patch, 3.4 KB (added by , 15 years ago) |
---|
-
django/template/__init__.py
139 139 class InvalidTemplateLibrary(Exception): 140 140 pass 141 141 142 class AttributeLookupError(Exception): 143 pass 144 142 145 class Origin(object): 143 146 def __init__(self, name): 144 147 self.name = name … … 713 716 current = current[bit] 714 717 except (TypeError, AttributeError, KeyError): 715 718 try: # attribute lookup 716 current = getattr(current, bit) 719 try: 720 current = getattr(current, bit) 721 except AttributeError, e: 722 raise AttributeLookupError(e) 717 723 if callable(current): 718 724 if getattr(current, 'alters_data', False): 719 725 current = settings.TEMPLATE_STRING_IF_INVALID … … 724 730 # GOTCHA: This will also catch any TypeError 725 731 # raised in the function itself. 726 732 current = settings.TEMPLATE_STRING_IF_INVALID # invalid method call 733 except AttributeError: 734 raise 727 735 except Exception, e: 728 736 if getattr(e, 'silent_variable_failure', False): 729 737 current = settings.TEMPLATE_STRING_IF_INVALID 730 738 else: 731 739 raise 732 except (TypeError, Attribute Error):740 except (TypeError, AttributeLookupError): 733 741 try: # list-index lookup 734 742 current = current[int(bit)] 735 743 except (IndexError, # list index out of range -
tests/regressiontests/templates/tests.py
88 88 89 89 def method4(self): 90 90 raise SomeOtherException 91 92 def method5(self): 93 raise AttributeError("callable exists but raises this") 91 94 92 95 class OtherClass: 93 96 def method(self): … … 303 306 304 307 # Fail silently when a variable's attribute isn't found 305 308 'basic-syntax11': ("{{ var.blech }}", {"var": SomeClass()}, ("","INVALID")), 306 309 307 310 # Raise TemplateSyntaxError when trying to access a variable beginning with an underscore 308 311 'basic-syntax12': ("{{ var.__dict__ }}", {"var": SomeClass()}, template.TemplateSyntaxError), 309 312 … … 340 343 'basic-syntax25': ('{{ "fred" }}', {}, "fred"), 341 344 'basic-syntax26': (r'{{ "\"fred\"" }}', {}, "\"fred\""), 342 345 'basic-syntax27': (r'{{ _("\"fred\"") }}', {}, "\"fred\""), 346 347 # Don't fail silently if variable did exist but raised an 348 # AttributeError on execution 349 'basic-syntax28': ("{{ var.method5 }}", {"var": SomeClass()}, AttributeError), 343 350 344 351 # List-index syntax allows a template to access a certain item of a subscriptable object. 345 352 'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"),