mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
python: Switch to xmlCtxtSetErrorHandler
This commit is contained in:
@ -1568,20 +1568,34 @@ typedef struct
|
|||||||
typedef xmlParserCtxtPyCtxt *xmlParserCtxtPyCtxtPtr;
|
typedef xmlParserCtxtPyCtxt *xmlParserCtxtPyCtxtPtr;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
libxml_xmlParserCtxtGenericErrorFuncHandler(void *ctx, int severity, char *str)
|
libxml_xmlParserCtxtErrorHandler(void *ctx, const xmlError *error)
|
||||||
{
|
{
|
||||||
PyObject *list;
|
PyObject *list;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
xmlParserCtxtPtr ctxt;
|
xmlParserCtxtPtr ctxt;
|
||||||
xmlParserCtxtPyCtxtPtr pyCtxt;
|
xmlParserCtxtPyCtxtPtr pyCtxt;
|
||||||
|
int severity;
|
||||||
|
|
||||||
ctxt = (xmlParserCtxtPtr)ctx;
|
ctxt = (xmlParserCtxtPtr)ctx;
|
||||||
pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private;
|
pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private;
|
||||||
|
|
||||||
|
if ((error->domain == XML_FROM_VALID) ||
|
||||||
|
(error->domain == XML_FROM_DTD)) {
|
||||||
|
if (error->level == XML_ERR_WARNING)
|
||||||
|
severity = XML_PARSER_SEVERITY_VALIDITY_WARNING;
|
||||||
|
else
|
||||||
|
severity = XML_PARSER_SEVERITY_VALIDITY_ERROR;
|
||||||
|
} else {
|
||||||
|
if (error->level == XML_ERR_WARNING)
|
||||||
|
severity = XML_PARSER_SEVERITY_WARNING;
|
||||||
|
else
|
||||||
|
severity = XML_PARSER_SEVERITY_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
list = PyTuple_New(4);
|
list = PyTuple_New(4);
|
||||||
PyTuple_SetItem(list, 0, pyCtxt->arg);
|
PyTuple_SetItem(list, 0, pyCtxt->arg);
|
||||||
Py_XINCREF(pyCtxt->arg);
|
Py_XINCREF(pyCtxt->arg);
|
||||||
PyTuple_SetItem(list, 1, libxml_charPtrWrap(str));
|
PyTuple_SetItem(list, 1, libxml_constcharPtrWrap(error->message));
|
||||||
PyTuple_SetItem(list, 2, libxml_intWrap(severity));
|
PyTuple_SetItem(list, 2, libxml_intWrap(severity));
|
||||||
PyTuple_SetItem(list, 3, Py_None);
|
PyTuple_SetItem(list, 3, Py_None);
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
@ -1595,46 +1609,6 @@ libxml_xmlParserCtxtGenericErrorFuncHandler(void *ctx, int severity, char *str)
|
|||||||
Py_XDECREF(result);
|
Py_XDECREF(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
libxml_xmlParserCtxtErrorFuncHandler(void *ctx, const char *msg, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, msg);
|
|
||||||
libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_ERROR,libxml_buildMessage(msg,ap));
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
libxml_xmlParserCtxtWarningFuncHandler(void *ctx, const char *msg, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, msg);
|
|
||||||
libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_WARNING,libxml_buildMessage(msg,ap));
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
libxml_xmlParserCtxtValidityErrorFuncHandler(void *ctx, const char *msg, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, msg);
|
|
||||||
libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_ERROR,libxml_buildMessage(msg,ap));
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
libxml_xmlParserCtxtValidityWarningFuncHandler(void *ctx, const char *msg, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, msg);
|
|
||||||
libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_WARNING,libxml_buildMessage(msg,ap));
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
libxml_xmlParserCtxtSetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args)
|
libxml_xmlParserCtxtSetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
@ -1670,16 +1644,10 @@ libxml_xmlParserCtxtSetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *a
|
|||||||
pyCtxt->arg = pyobj_arg;
|
pyCtxt->arg = pyobj_arg;
|
||||||
|
|
||||||
if (pyobj_f != Py_None) {
|
if (pyobj_f != Py_None) {
|
||||||
ctxt->sax->error = libxml_xmlParserCtxtErrorFuncHandler;
|
xmlCtxtSetErrorHandler(ctxt, libxml_xmlParserCtxtErrorHandler, ctxt);
|
||||||
ctxt->sax->warning = libxml_xmlParserCtxtWarningFuncHandler;
|
|
||||||
ctxt->vctxt.error = libxml_xmlParserCtxtValidityErrorFuncHandler;
|
|
||||||
ctxt->vctxt.warning = libxml_xmlParserCtxtValidityWarningFuncHandler;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ctxt->sax->error = xmlParserError;
|
xmlCtxtSetErrorHandler(ctxt, NULL, NULL);
|
||||||
ctxt->vctxt.error = xmlParserValidityError;
|
|
||||||
ctxt->sax->warning = xmlParserWarning;
|
|
||||||
ctxt->vctxt.warning = xmlParserValidityWarning;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
py_retval = libxml_intWrap(1);
|
py_retval = libxml_intWrap(1);
|
||||||
|
Reference in New Issue
Block a user