summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-02-20 12:01:12 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2011-02-20 12:01:12 -0500
commitcb9ebd2288031c96dda349a8eb42bf6bacbec8f1 (patch)
tree9aff8978129a13f9b861df6a5846a2b9a41cbda4
parentcff83675deb802e8c2aa78c98dc0e1ce4a179ac1 (diff)
downloadmako-cb9ebd2288031c96dda349a8eb42bf6bacbec8f1.tar.gz
got all tests to pass again
-rw-r--r--mako/parsetree.py11
-rw-r--r--mako/runtime.py44
-rw-r--r--test/test_def.py4
3 files changed, 41 insertions, 18 deletions
diff --git a/mako/parsetree.py b/mako/parsetree.py
index 3ef85e6..53a980d 100644
--- a/mako/parsetree.py
+++ b/mako/parsetree.py
@@ -361,9 +361,14 @@ class NamespaceTag(Tag):
self.name = attributes.get('name', '__anon_%s' % hex(abs(id(self))))
if not 'name' in attributes and not 'import' in attributes:
raise exceptions.CompileException(
- "'name' and/or 'import' attributes are required "
- "for <%namespace>",
- **self.exception_kwargs)
+ "'name' and/or 'import' attributes are required "
+ "for <%namespace>",
+ **self.exception_kwargs)
+ if 'file' in attributes and 'module' in attributes:
+ raise exceptions.CompileException(
+ "<%namespace> may only have one of 'file' or 'module'",
+ **self.exception_kwargs
+ )
def declared_identifiers(self):
return []
diff --git a/mako/runtime.py b/mako/runtime.py
index 42707e4..e0df124 100644
--- a/mako/runtime.py
+++ b/mako/runtime.py
@@ -302,7 +302,7 @@ class Namespace(object):
"""
key = (self, uri)
- if key in self.context.namepaces:
+ if key in self.context.namespaces:
return self.context.namespaces[key]
else:
ns = TemplateNamespace(uri, self.context._copy(),
@@ -374,22 +374,12 @@ class Namespace(object):
if self.callables:
for key in self.callables:
yield (key, self.callables[key])
-
+
def __getattr__(self, key):
if key in self.callables:
val = self.callables[key]
-
elif self.inherits:
val = getattr(self.inherits, key)
-
- elif self.template and self.template.has_def(key):
- callable_ = self.template._get_def_callable(key)
- val = util.partial(callable_, self.context)
-
- elif self.module and hasattr(self.module, key):
- callable_ = getattr(self._module, key)
- val = util.partial(callable_, self.context)
-
else:
raise AttributeError(
"Namespace '%s' has no member '%s'" %
@@ -463,6 +453,21 @@ class TemplateNamespace(Namespace):
for k in self.template.module._exports:
yield (k, get(k))
+ def __getattr__(self, key):
+ if key in self.callables:
+ val = self.callables[key]
+ elif self.template.has_def(key):
+ callable_ = self.template._get_def_callable(key)
+ val = util.partial(callable_, self.context)
+ elif self.inherits:
+ val = getattr(self.inherits, key)
+
+ else:
+ raise AttributeError(
+ "Namespace '%s' has no member '%s'" %
+ (self.name, key))
+ setattr(self, key, val)
+ return val
class ModuleNamespace(Namespace):
"""A :class:`.Namespace` specific to a Python module instance."""
@@ -499,6 +504,21 @@ class ModuleNamespace(Namespace):
if k[0] != '_':
yield (k, get(k))
+ def __getattr__(self, key):
+ if key in self.callables:
+ val = self.callables[key]
+ elif hasattr(self.module, key):
+ callable_ = getattr(self.module, key)
+ val = util.partial(callable_, self.context)
+ elif self.inherits:
+ val = getattr(self.inherits, key)
+ else:
+ raise AttributeError(
+ "Namespace '%s' has no member '%s'" %
+ (self.name, key))
+ setattr(self, key, val)
+ return val
+
def supports_caller(func):
"""Apply a caller_stack compatibility decorator to a plain
Python function.
diff --git a/test/test_def.py b/test/test_def.py
index 00f904c..3ec63ff 100644
--- a/test/test_def.py
+++ b/test/test_def.py
@@ -367,9 +367,7 @@ class ScopeTest(TemplateTest):
""")
# test via inheritance
- print l.get_template("main").code
- import pdb
- pdb.set_trace()
+ #print l.get_template("main").code
assert result_lines(l.get_template("main").render()) == [
"this is main. x is 12",
"this is a, x is 12"