A more nuanced approach to Python warnings.
commita229adb19a99292d2705ab742aba5808d75536ca
authorM. Levinson <mlevins@users.sourceforge.net>
Sat, 12 Mar 2011 18:59:04 +0000 (12 13:59 -0500)
committerwitekfl <witekfl@poczta.onet.pl>
Fri, 5 Jul 2013 10:29:58 +0000 (5 12:29 +0200)
tree201afa410af2d35dfc79acc20cd751a2bc98aca5
parent91515990c83ecda97c597fd498140896be0bc547
A more nuanced approach to Python warnings.

By default some Python warning messages would be written to standard error
by the interpreter. To prevent these warnings from making a mess of the
ELinks screen, all warnings were turned into exceptions so they could be
caught and displayed through the usual report_scripting_error() mechanism.

With Python 3.2, this approach backfires: A new class of ResourceWarnings
that are filtered by default (and hence would *not* have been written to
standard error) are now turned into exceptions, and these exceptions can't
be caught because they're emitted from the interpreter's cleanup code. As
a result, the uncaught exceptions would make a mess of the ELinks screen.

The new solution is to replace Python's standard library function
warnings.showwarning() with one that turns warning messages into exceptions.
This means we'll wait until a warning would have been written to standard
error before turning it into an exception, so other warnings that would
never have reached that point because they're filtered will remain unseen.

(The behavior of warning messages is described in the documentation for
the "warnings" module from Python's standard library.)
src/scripting/python/core.c