Lingua extractor silently ignores try/except blocks instead or returning an error.
diff --git a/mako/ext/linguaplugin.py b/mako/ext/linguaplugin.py
index 248fbaa..09ef560 100644
--- a/mako/ext/linguaplugin.py
+++ b/mako/ext/linguaplugin.py
@@ -30,7 +30,10 @@
source = compat.b('if 1:') # Replace "else" with "if 1"
elif source.startswith('elif'):
source = source[2:] # Replace "elif" with "if"
- source += compat.b(' pass')
+ if source == 'try:' or source.startswith('except'):
+ source = compat.b('') # Ignore "try/except" altogether
+ else:
+ source += compat.b(' pass')
code = io.BytesIO(source)
for msg in self.python_extractor(
self.filename, self.options, code, code_lineno -1):
diff --git a/test/templates/gettext.mako b/test/templates/gettext.mako
index c174219..863b365 100644
--- a/test/templates/gettext.mako
+++ b/test/templates/gettext.mako
@@ -98,7 +98,7 @@
<p>${_("No action at a distance.")}</p>
-## TRANSLATOR: these blocks should be ignored during extraction
+## TRANSLATOR: nothing to extract from these blocks
% if 1==1:
<p>One is one!</p>
@@ -117,3 +117,11 @@
% while random.randint(1,6) != 6:
<p>Not 6!</p>
% endwhile
+
+## TRANSLATOR: for now, try/except blocks are ignored
+
+% try:
+<% 1/0 %>
+% except:
+<p>Failed!</p>
+% endtry