Changed naked except statements to catch only subclasses of Exception.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
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.
authored by Ian Lewis · committed by Armin Ronacher · parent 64ff4fa · Browse files · 6 files·+18 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- See: http://code.google.com/p/googleappengine/issues/detail?id=1409
- Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>
Diff stats
6 files+18 added−18 removed
- other:+18 added−18 removed
Provenance
- Commit
ab014bd- Tree
bfa5a89- Author
Ian Lewis <IanMLewis@gmail.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
64ff4fa
6 files changed+18 added−18 removed
modified:jinja2/__init__.py+1 added-1 removed
28 unmodified lines29 __docformat__ = 'restructuredtext en'30 try:31 __version__ = __import__('pkg_resources') \32 .get_distribution('Jinja2').version33-except:33+except Exception:34 __version__ = 'unknown'35 36 # high level interface37 from jinja2.environment import Environment, Template36 unmodified linesmodified:jinja2/compiler.py+1 added-1 removed
1247 unmodified lines1248 const = const.__html__()1249 else:1250 const = escape(const)1251 const = finalize(const)1252- except:1252+ except Exception:1253 # if something goes wrong here we evaluate the node1254 # at runtime for easier debugging1255 body.append(child)1256 continue384 unmodified linesmodified:jinja2/environment.py+3 added-3 removed
352 unmodified lines353 except (TypeError, LookupError):354 if isinstance(argument, basestring):355 try:356 attr = str(argument)357- except:357+ except Exception:358 pass359 else:360 try:361 return getattr(obj, attr)523 unmodified lines885 """886 vars = dict(*args, **kwargs)887 try:888 return concat(self.root_render_func(self.new_context(vars)))889- except:889+ except Exception:890 exc_info = sys.exc_info()891 return self.environment.handle_exception(exc_info, True)892 893 def stream(self, *args, **kwargs):13 unmodified lines907 vars = dict(*args, **kwargs)908 try:909 for event in self.root_render_func(self.new_context(vars)):910 yield event911- except:911+ except Exception:912 exc_info = sys.exc_info()913 else:914 return915 yield self.environment.handle_exception(exc_info, True)203 unmodified linesmodified:jinja2/nodes.py+11 added-11 removed
373 unmodified lines374 eval_ctx = get_eval_context(self, eval_ctx)375 f = _binop_to_func[self.operator]376 try:377 return f(self.left.as_const(eval_ctx), self.right.as_const(eval_ctx))378- except:378+ except Exception:379 raise Impossible()380 381 382 class UnaryExpr(Expr):6 unmodified lines389 eval_ctx = get_eval_context(self, eval_ctx)390 f = _uaop_to_func[self.operator]391 try:392 return f(self.node.as_const(eval_ctx))393- except:393+ except Exception:394 raise Impossible()395 396 397 class Name(Expr):156 unmodified lines554 kwargs = dict(x.as_const(eval_ctx) for x in self.kwargs)555 if self.dyn_args is not None:556 try:557 args.extend(self.dyn_args.as_const(eval_ctx))558- except:558+ except Exception:559 raise Impossible()560 if self.dyn_kwargs is not None:561 try:562 kwargs.update(self.dyn_kwargs.as_const(eval_ctx))563- except:563+ except Exception:564 raise Impossible()565 try:566 return filter_(obj, *args, **kwargs)567- except:567+ except Exception:568 raise Impossible()569 570 571 class Test(Expr):31 unmodified lines603 kwargs = dict(x.as_const(eval_ctx) for x in self.kwargs)604 if self.dyn_args is not None:605 try:606 args.extend(self.dyn_args.as_const(eval_ctx))607- except:607+ except Exception:608 raise Impossible()609 if self.dyn_kwargs is not None:610 try:611 kwargs.update(self.dyn_kwargs.as_const(eval_ctx))612- except:612+ except Exception:613 raise Impossible()614 try:615 return obj(*args, **kwargs)616- except:616+ except Exception:617 raise Impossible()618 619 620 class Getitem(Expr):6 unmodified lines627 raise Impossible()628 try:629 return self.environment.getitem(self.node.as_const(eval_ctx),630 self.arg.as_const(eval_ctx))631- except:631+ except Exception:632 raise Impossible()633 634 def can_assign(self):635 return False11 unmodified lines647 try:648 eval_ctx = get_eval_context(self, eval_ctx)649 return self.environment.getattr(self.node.as_const(eval_ctx),650 self.attr)651- except:651+ except Exception:652 raise Impossible()653 654 def can_assign(self):655 return False38 unmodified lines694 for op in self.ops:695 new_value = op.expr.as_const(eval_ctx)696 result = _cmpop_to_func[op.op](value, new_value)697 value = new_value698- except:698+ except Exception:699 raise Impossible()700 return result701 702 199 unmodified linesmodified:jinja2/sandbox.py+1 added-1 removed
210 unmodified lines211 except (TypeError, LookupError):212 if isinstance(argument, basestring):213 try:214 attr = str(argument)215- except:215+ except Exception:216 pass217 else:218 try:219 value = getattr(obj, attr)52 unmodified linesmodified:jinja2/utils.py+1 added-1 removed
51 unmodified lines52 if not _error.args or _error.args[0] is not _test_gen_bug:53 def concat(gen):54 try:55 return _concat(list(gen))56- except:56+ except Exception:57 # this hack is needed so that the current frame58 # does not show up in the traceback.59 exc_type, exc_value, tb = sys.exc_info()60 raise exc_type, exc_value, tb.tb_next541 unmodified lines