[xml] Python bindings default error handling

Currently libxml2 ignores the value of sys.stderr and prints straight
to c stderr. This caught me out a couple of times in the past, when
using from within apache (ended up raw in the error log) and when
trying to pass on the problems reported to another process. Setting
your own callback can get the desired effect, but it would be nice for
this to just work.

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.

Went hunting for how other cpython deals with error logging, found a
couple of things along the right lines.
In ctypes PrintError <
(attached, extract_ctypes_callback.c) is a minimal version.
In python itself, PySys_WriteStderr
(attached, extract_python_sysmodule.c) is pretty much perfect for a
default error callback, but for the arg mismatch (no dummy void*). The
mywrite function that actually does all the work covers all bases,
including short circuiting the common case.

So, one approach is to adapt (err... "copy wholesale") that function
(attached, libxml2_stderr.patch) for use with the current callback
function. Do the libxslt bindings also need looking at? I don't
suggest taking the patch exactly as-is (borrowed function should
probably go somewhere else at least), but something along these lines
would be nice.


Attachment: extract_ctypes_callback.c
Description: Text Data

Attachment: extract_python_sysmodule.c
Description: Text Data

Attachment: libxml2_stderr.patch
Description: Binary data

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