Ticket #3465: 3465_2.diff

File 3465_2.diff, 3.2 KB (added by Gary Wilson <gary.wilson@…>, 18 years ago)

fixed a couple of spelling errors and added comments to one of the tests

  • django/template/__init__.py

    === modified file 'django/template/__init__.py'
     
    665665                except (TypeError, AttributeError):
    666666                    try: # list-index lookup
    667667                        current = current[int(bits[0])]
    668                     except (IndexError, ValueError, KeyError):
     668                    except (IndexError, # list index out of range
     669                            ValueError, # invalid literal for int()
     670                            KeyError, # current is a dict without `int(bits[0])` key
     671                            TypeError, # unsubscriptable object
     672                            ):
    669673                        raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bits[0], current)) # missing attribute
    670674                except Exception, e:
    671675                    if getattr(e, 'silent_variable_failure', False):
  • tests/regressiontests/templates/tests.py

    === modified file 'tests/regressiontests/templates/tests.py'
     
    127127            # Fail silently when accessing a non-simple method
    128128            'basic-syntax20': ("{{ var.method2 }}", {"var": SomeClass()}, ("","INVALID")),
    129129
     130            # List-index syntax allows a template to access a certain item of a subscriptable object.
     131            'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"),
     132
     133            # Fail silently when the list index is out of range.
     134            'list-index02': ("{{ var.5 }}", {"var": ["first item", "second item"]}, ("", "INVALID")),
     135
     136            # Fail silently when the variable is not a subscriptable object.
     137            'list-index03': ("{{ var.1 }}", {"var": None}, ("", "INVALID")),
     138
     139            # Fail silently when variable is a dict without the specified key.
     140            'list-index04': ("{{ var.1 }}", {"var": {}}, ("", "INVALID")),
     141
     142            # Dictionary lookup wins out when dict's key is a string.
     143            'list-index05': ("{{ var.1 }}", {"var": {'1': "hello"}}, "hello"),
     144
     145            # But list-index lookup wins out when dict's key is an int, which
     146            # behind the scenes is really a dictionary lookup (for a dict)
     147            # after converting the key to an int.
     148            'list-index06': ("{{ var.1 }}", {"var": {1: "hello"}}, "hello"),
     149
     150            # Dictionary lookup wins out when there is a string and int version of the key.
     151            'list-index07': ("{{ var.1 }}", {"var": {'1': "hello", 1: "world"}}, "hello"),
     152           
    130153            # Basic filter usage
    131154            'basic-syntax21': ("{{ var|upper }}", {"var": "Django is the greatest!"}, "DJANGO IS THE GREATEST!"),
    132155
     
    167190            'basic-syntax33': (r'1{{ var.method3 }}2', {"var": SomeClass()}, ("12", "1INVALID2")),
    168191
    169192            # In methods that raise an exception without a "silent_variable_attribute" set to True,
    170             # the exception propogates
     193            # the exception propagates
    171194            'basic-syntax34': (r'1{{ var.method4 }}2', {"var": SomeClass()}, SomeOtherException),
    172195
    173196            # Escaped backslash in argument
Back to Top