Changed naked except statements to catch only subclasses of Exception.
Naked except statements catch subclasses of BaseException which
can occur anywhere (i.e. KeyboardInterrupt).
Unexpected issues can occur when the exception happens during the
loading of a module. The python interpreter doesn't know about a
module's failed load and does not remove it from sys.modules. This
is particularly a problem on AppEngine where python will think the
module is loaded but in fact the module load has failed.
See: http://code.google.com/p/googleappengine/issues/detail?id=1409
Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>
diff --git a/jinja2/nodes.py b/jinja2/nodes.py
index 6446c70..7c6b358 100644
--- a/jinja2/nodes.py
+++ b/jinja2/nodes.py
@@ -375,7 +375,7 @@
f = _binop_to_func[self.operator]
try:
return f(self.left.as_const(eval_ctx), self.right.as_const(eval_ctx))
- except:
+ except Exception:
raise Impossible()
@@ -390,7 +390,7 @@
f = _uaop_to_func[self.operator]
try:
return f(self.node.as_const(eval_ctx))
- except:
+ except Exception:
raise Impossible()
@@ -555,16 +555,16 @@
if self.dyn_args is not None:
try:
args.extend(self.dyn_args.as_const(eval_ctx))
- except:
+ except Exception:
raise Impossible()
if self.dyn_kwargs is not None:
try:
kwargs.update(self.dyn_kwargs.as_const(eval_ctx))
- except:
+ except Exception:
raise Impossible()
try:
return filter_(obj, *args, **kwargs)
- except:
+ except Exception:
raise Impossible()
@@ -604,16 +604,16 @@
if self.dyn_args is not None:
try:
args.extend(self.dyn_args.as_const(eval_ctx))
- except:
+ except Exception:
raise Impossible()
if self.dyn_kwargs is not None:
try:
kwargs.update(self.dyn_kwargs.as_const(eval_ctx))
- except:
+ except Exception:
raise Impossible()
try:
return obj(*args, **kwargs)
- except:
+ except Exception:
raise Impossible()
@@ -628,7 +628,7 @@
try:
return self.environment.getitem(self.node.as_const(eval_ctx),
self.arg.as_const(eval_ctx))
- except:
+ except Exception:
raise Impossible()
def can_assign(self):
@@ -648,7 +648,7 @@
eval_ctx = get_eval_context(self, eval_ctx)
return self.environment.getattr(self.node.as_const(eval_ctx),
self.attr)
- except:
+ except Exception:
raise Impossible()
def can_assign(self):
@@ -695,7 +695,7 @@
new_value = op.expr.as_const(eval_ctx)
result = _cmpop_to_func[op.op](value, new_value)
value = new_value
- except:
+ except Exception:
raise Impossible()
return result