Skip to content

Commit

Permalink
- Fixed namespace.__getattr__() to raise
Browse files Browse the repository at this point in the history
  AttributeError on attribute not found
  instead of RuntimeError.  [ticket:104]
  • Loading branch information
zzzeek committed Mar 19, 2009
1 parent da73752 commit 3f87430
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
other uses there may be (but there may be).
Examples are in the "filtering" docs.

- Fixed namespace.__getattr__() to raise
AttributeError on attribute not found
instead of RuntimeError. [ticket:104]

- Added last_modified accessor to Template,
returns the time.time() when the module
was created. [ticket:97]

- Fixed lexing support for whitespace
around '=' sign in defs. [ticket:102]

Expand Down
2 changes: 1 addition & 1 deletion lib/mako/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def __getattr__(self, key):

if self.inherits is not None:
return getattr(self.inherits, key)
raise exceptions.RuntimeException("Namespace '%s' has no member '%s'" % (self.name, key))
raise AttributeError("Namespace '%s' has no member '%s'" % (self.name, key))

def supports_caller(func):
"""apply a caller_stack compatibility decorator to a plain Python function."""
Expand Down
17 changes: 16 additions & 1 deletion test/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,22 @@ def test_attr(self):
"foo lala",
]


def test_attr_raise(self):
l = lookup.TemplateLookup()

l.put_string("foo.html", """
<%def name="foo()">
</%def>
""")

l.put_string("bar.html", """
<%namespace name="foo" file="foo.html"/>
${foo.notfoo()}
""")

self.assertRaises(AttributeError, l.get_template("bar.html").render)

def test_custom_tag_1(self):
template = Template("""
Expand Down

0 comments on commit 3f87430

Please sign in to comment.