summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-09-02 15:08:34 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-09-02 15:08:34 -0400
commit8bb8f0b520937754a9e833e289149a4547b314dc (patch)
treef0690df7471a67af3621062354a3d62e2d62a3c8
parent49db3f99c9f09caec8d63534b371808fbd4c2209 (diff)
downloadmako-8bb8f0b520937754a9e833e289149a4547b314dc.tar.gz
- adjust the new multiline ${} in tag feature to allow trailing whitespace,
doesn't occur on Python 2.7
-rw-r--r--mako/parsetree.py17
-rw-r--r--test/test_call.py7
2 files changed, 16 insertions, 8 deletions
diff --git a/mako/parsetree.py b/mako/parsetree.py
index 824762d..12b0498 100644
--- a/mako/parsetree.py
+++ b/mako/parsetree.py
@@ -268,14 +268,16 @@ class Tag(Node):
for key in self.attributes:
if key in expressions:
expr = []
- for x in re.compile(r'(\${.+?})', re.S).split(self.attributes[key]):
+ for x in re.compile(r'(\${.+?})',
+ re.S).split(self.attributes[key]):
m = re.compile(r'^\${(.+?)}$', re.S).match(x)
if m:
- code = ast.PythonCode(m.group(1), **self.exception_kwargs)
- undeclared_identifiers = undeclared_identifiers.union(
- code.undeclared_identifiers
- )
- expr.append("(%s)" % m.group(1))
+ code = ast.PythonCode(m.group(1).rstrip(),
+ **self.exception_kwargs)
+ undeclared_identifiers = \
+ undeclared_identifiers.union(
+ code.undeclared_identifiers)
+ expr.append('(%s)' % m.group(1))
else:
if x:
expr.append(repr(x))
@@ -391,7 +393,8 @@ class DefTag(Tag):
def undeclared_identifiers(self):
res = []
for c in self.function_decl.defaults:
- res += list(ast.PythonCode(c, **self.exception_kwargs).undeclared_identifiers)
+ res += list(ast.PythonCode(c, **self.exception_kwargs).
+ undeclared_identifiers)
return res + list(self.filter_args.\
undeclared_identifiers.\
difference(filters.DEFAULT_ESCAPES.keys())
diff --git a/test/test_call.py b/test/test_call.py
index d47ec11..fecb2de 100644
--- a/test/test_call.py
+++ b/test/test_call.py
@@ -47,6 +47,9 @@ class CallTest(TemplateTest):
def test_new_syntax(self):
"""test foo:bar syntax, including multiline args and expression eval."""
+ # note the trailing whitespace in the bottom ${} expr, need to strip
+ # that off < python 2.7
+
t = Template("""
<%def name="foo(x, y, q, z)">
${x}
@@ -64,7 +67,9 @@ class CallTest(TemplateTest):
(1, 2),
(3, 4),
(5, 6)
- ]}"/>
+ ]
+
+ }"/>
""")
eq_(