Re: [xml] Python bindings default error handling

On 07/05/2008, Daniel Veillard <veillard redhat com> wrote:
On Wed, Apr 30, 2008 at 05:13:11PM +0100, Martin (gzlist) wrote:
 > Anyway, while I was looking at something more complicated on the error
 > handling front (fixing it so the exceptions actually included the
 > info), I thought I'd try and patch this in passing.

  Hum, there is a more fundamental problem with trying to redirrect
 all libxml2 errors to python, simply that your python module may not be
 the only part of the application using libxml2, and in a framework like
 Apache, this means you're very likely to introduce side effects for
 other parts by doing so.

Right, I get the issues with using print-to-stream or get-last-error
approaches to fault handling in complicated, concurrent programs - but
that's what libxml2 is built around. For general cases, the current
python bindings seem to do roughly the right thing.

  I'm afraid any approach based on a global automatic redirection is
 annoying in highly modulars apps like Apache.
  Still the patch makes sense because it doesn't directly increase
 the reliance in the global handler.

Yup, it just makes most cases where you'd currently need to give a
scripted error callback simpler, by working with the typical python
method of redirecting a std stream.

  For libxslt, yes I see a few use cases of stderr in libxslt/python/libxslt.c
 and it would be good to clean this up,

The fprintf(stderr...) cases look like they could just be swapped out
for PySys_WriteStderr, and libxslt_xsltErrorFuncHandler is a hairier
version of libxml_xmlErrorFuncHandler... is there any reason for the
buffer growing code?
For that matter, I don't quite get how the two are intended to play
together. On module load, libxml2 sets the hander, and thread default
handler, to its callback. That does exactly the same as no handler,
unless a global var is set to a python callback. On libxslt module
load, it hijacks the libxml2 handler, but *not* the thread default,
sets the libxslt handler, and also does nothing unless... a different
global variable is set. Then on the python level, libxml2 explicitly
checks to see if libxslt is loaded so it doesn't use the hijacked
Surely there's an easier way? Can some of this copied code be removed,
rather than adding another function in both places to make both the
global callbacks obey sys.stderr?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]