summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2016-03-18 19:35:48 +0100
committerStefan Behnel <stefan_ml@behnel.de>2016-03-18 19:35:48 +0100
commit02b06d4fa57e5a6a6eb64e20b82536e731cc6944 (patch)
tree3f35ea032ae30f38a6c80f9ff27a529c711814c5
parent477e721dc083ed512182d9a2339bb64ee9f37937 (diff)
downloadpython-lxml-02b06d4fa57e5a6a6eb64e20b82536e731cc6944.tar.gz
LP#1551797: Repair XSLT error logging. Patch by Marcus Brinkmann.
-rw-r--r--src/lxml/tests/test_xslt.py14
-rw-r--r--src/lxml/xmlerror.pxi5
2 files changed, 19 insertions, 0 deletions
diff --git a/src/lxml/tests/test_xslt.py b/src/lxml/tests/test_xslt.py
index 6ee82c5c..36c875f8 100644
--- a/src/lxml/tests/test_xslt.py
+++ b/src/lxml/tests/test_xslt.py
@@ -259,6 +259,20 @@ class ETreeXSLTTestCase(HelperTestCase):
self.assertRaises(etree.XSLTParseError,
etree.XSLT, style)
+ exc = None
+ try:
+ etree.XSLT(style)
+ except etree.XSLTParseError as e:
+ exc = e
+ self.assertTrue(exc is not None)
+ self.assertTrue(len(e.error_log) == 4)
+
+ errors = '''<string>:0:0:ERROR:XSLT:ERR_OK: compilation error
+<string>:0:0:ERROR:XSLT:ERR_OK: xsltStylePreCompute: unknown xsl:foo
+<string>:0:0:ERROR:XSLT:ERR_OK: compilation error
+<string>:0:0:ERROR:XSLT:ERR_OK: xsltParseStylesheetTop: unknown foo element'''
+ self.assertEqual(str(e.error_log), errors)
+
def test_xslt_parameters(self):
tree = self.parse('<a><b>B</b><c>C</c></a>')
style = self.parse('''\
diff --git a/src/lxml/xmlerror.pxi b/src/lxml/xmlerror.pxi
index 5294b500..60a47a63 100644
--- a/src/lxml/xmlerror.pxi
+++ b/src/lxml/xmlerror.pxi
@@ -378,6 +378,7 @@ cdef class _ErrorLogContext:
recursively stacked log contexts.
"""
cdef xmlerror.xmlStructuredErrorFunc old_error_func
+ cdef xmlerror.xmlGenericErrorFunc old_xslt_error_func
cdef void* old_error_context
cdef class _ErrorLog(_ListErrorLog):
@@ -407,6 +408,8 @@ cdef class _ErrorLog(_ListErrorLog):
self._logContexts.append(context)
xmlerror.xmlSetStructuredErrorFunc(
<void*>self, <xmlerror.xmlStructuredErrorFunc>_receiveError)
+ xslt.xsltSetGenericErrorFunc(
+ <void*>self, <xmlerror.xmlGenericErrorFunc>_receiveXSLTError)
return 0
@cython.final
@@ -414,6 +417,8 @@ cdef class _ErrorLog(_ListErrorLog):
cdef _ErrorLogContext context = self._logContexts.pop()
xmlerror.xmlSetStructuredErrorFunc(
context.old_error_context, context.old_error_func)
+ xslt.xsltSetGenericErrorFunc(
+ context.old_error_context, context.old_xslt_error_func)
return 0
cpdef clear(self):