aboutsummaryrefslogtreecommitdiffstats
path: root/mako
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-03-12 01:27:25 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-03-12 01:27:25 -0400
commit8bebfc205230d41429a88c98b56d45acf7e67226 (patch)
treefc1cc3af6273fa57e7fe8f247975b037540a9266 /mako
parent936a524263b90071d601b09a63f3c86117769b61 (diff)
downloadexternal_python_mako-8bebfc205230d41429a88c98b56d45acf7e67226.tar.gz
external_python_mako-8bebfc205230d41429a88c98b56d45acf7e67226.tar.bz2
external_python_mako-8bebfc205230d41429a88c98b56d45acf7e67226.zip
- [feature] Added support for context managers,
i.e. "% with x as e:/ % endwith" support. Courtesy Ben Trofatter [ticket:147]
Diffstat (limited to 'mako')
-rw-r--r--mako/ast.py2
-rw-r--r--mako/parsetree.py2
-rw-r--r--mako/pygen.py2
3 files changed, 4 insertions, 2 deletions
diff --git a/mako/ast.py b/mako/ast.py
index 515d7b8..f2f09d6 100644
--- a/mako/ast.py
+++ b/mako/ast.py
@@ -83,6 +83,8 @@ class PythonFragment(PythonCode):
code = "if False:pass\n" + code + "pass"
elif keyword == 'except':
code = "try:pass\n" + code + "pass"
+ elif keyword == 'with':
+ code = code + "pass"
else:
raise exceptions.CompileException(
"Unsupported control keyword: '%s'" %
diff --git a/mako/parsetree.py b/mako/parsetree.py
index 8aa95d4..52bd156 100644
--- a/mako/parsetree.py
+++ b/mako/parsetree.py
@@ -64,7 +64,7 @@ class ControlLine(Node):
self.text = text
self.keyword = keyword
self.isend = isend
- self.is_primary = keyword in ['for','if', 'while', 'try']
+ self.is_primary = keyword in ['for','if', 'while', 'try', 'with']
if self.isend:
self._declared_identifiers = []
self._undeclared_identifiers = []
diff --git a/mako/pygen.py b/mako/pygen.py
index e38b383..b50e60e 100644
--- a/mako/pygen.py
+++ b/mako/pygen.py
@@ -108,7 +108,7 @@ class PythonPrinter(object):
# keep track of what the keyword was that indented us,
# if it is a python compound statement keyword
# where we might have to look for an "unindent" keyword
- match = re.match(r"^\s*(if|try|elif|while|for)", line)
+ match = re.match(r"^\s*(if|try|elif|while|for|with)", line)
if match:
# its a "compound" keyword, so we will check for "unindentors"
indentor = match.group(1)