[Lxml-checkins] r32377 - in lxml/trunk: . doc src/lxml src/lxml/tests

scoder at codespeak.net scoder at codespeak.net
Fri Sep 15 21:37:51 CEST 2006


Author: scoder
Date: Fri Sep 15 21:37:48 2006
New Revision: 32377

Modified:
   lxml/trunk/CHANGES.txt
   lxml/trunk/doc/resolvers.txt
   lxml/trunk/src/lxml/etree.pyx
   lxml/trunk/src/lxml/tests/test_xslt.py
   lxml/trunk/src/lxml/xmlerror.pxi
   lxml/trunk/src/lxml/xslt.pxi
Log:
fixed local error log for XSLT messages

Modified: lxml/trunk/CHANGES.txt
==============================================================================
--- lxml/trunk/CHANGES.txt	(original)
+++ lxml/trunk/CHANGES.txt	Fri Sep 15 21:37:48 2006
@@ -15,6 +15,8 @@
 Bugs fixed
 ----------
 
+* Error messages from XSLT did not reach ``XSLT.error_log``
+
 * Factories objectify.Element() and objectify.DataElement() were missing
   ``attrib`` and ``nsmap`` keyword arguments
 

Modified: lxml/trunk/doc/resolvers.txt
==============================================================================
--- lxml/trunk/doc/resolvers.txt	(original)
+++ lxml/trunk/doc/resolvers.txt	Fri Sep 15 21:37:48 2006
@@ -196,7 +196,7 @@
   >>> result = transform(normal_doc)
   Traceback (most recent call last):
     [...]
-  XSLTApplyError: runtime error, element 'value-of', line 6
+  XSLTApplyError: xsltLoadDocument: read rights for hoi:test denied
 
 There are a few things to keep in mind:
 

Modified: lxml/trunk/src/lxml/etree.pyx
==============================================================================
--- lxml/trunk/src/lxml/etree.pyx	(original)
+++ lxml/trunk/src/lxml/etree.pyx	Fri Sep 15 21:37:48 2006
@@ -1790,10 +1790,7 @@
 include "xmlid.pxi"      # XMLID and IDDict
 include "extensions.pxi" # XPath/XSLT extension functions
 include "xpath.pxi"      # XPath evaluation
-
-# XSL transformations
-# comment out to compile without libxslt
-include "xslt.pxi"
+include "xslt.pxi"       # XSL transformations
 
 
 ################################################################################

Modified: lxml/trunk/src/lxml/tests/test_xslt.py
==============================================================================
--- lxml/trunk/src/lxml/tests/test_xslt.py	(original)
+++ lxml/trunk/src/lxml/tests/test_xslt.py	Fri Sep 15 21:37:48 2006
@@ -366,6 +366,25 @@
         self.assertEqual('', style.tostring(result))
         self.assertEqual('', str(result))
 
+    def test_xslt_message(self):
+        xml = '<blah/>'
+        xslt = '''
+        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+          <xsl:template match="/">
+            <xsl:message>TEST TEST TEST</xsl:message>
+          </xsl:template>
+        </xsl:stylesheet>
+        '''
+
+        source = self.parse(xml)
+        styledoc = self.parse(xslt)
+        style = etree.XSLT(styledoc)
+        result = style.apply(source)
+        self.assertEqual('', style.tostring(result))
+        self.assertEqual('', str(result))
+        self.assert_("TEST TEST TEST" in [entry.message
+                                          for entry in style.error_log])
+
     def test_xslt_shortcut(self):
         tree = self.parse('<a><b>B</b><c>C</c></a>')
         style = self.parse('''\

Modified: lxml/trunk/src/lxml/xmlerror.pxi
==============================================================================
--- lxml/trunk/src/lxml/xmlerror.pxi	(original)
+++ lxml/trunk/src/lxml/xmlerror.pxi	Fri Sep 15 21:37:48 2006
@@ -9,17 +9,24 @@
     Note that this log is already bounded to a fixed size."""
     __GLOBAL_ERROR_LOG.clear()
 
-# setup functions
+# dummy function: no debug output at all
+cdef void _nullGenericErrorFunc(void* ctxt, char* msg, ...):
+    pass
+
+# setup for global log:
 
 cdef void _initThreadLogging():
-    "Setup logging for the current thread. Called from etree.initThread()."
-    # switch on line number reporting
-    _logLibxmlErrors()
-    try:
-        _logLibxsltErrors()
-    except NameError:
-        # compiled without libxslt
-        pass
+    # disable generic error lines from libxml2
+    xmlerror.xmlThrDefSetGenericErrorFunc(NULL, _nullGenericErrorFunc)
+    xmlerror.xmlSetGenericErrorFunc(NULL, _nullGenericErrorFunc)
+
+    # divert error messages to the global error log
+    xmlerror.xmlThrDefSetStructuredErrorFunc(NULL, _receiveError)
+    connectErrorLog(NULL)
+
+cdef void connectErrorLog(void* log):
+    xmlerror.xmlSetStructuredErrorFunc(log, _receiveError)
+    xslt.xsltSetGenericErrorFunc(log, _receiveXSLTError)
 
 
 # Logging classes
@@ -194,10 +201,10 @@
 
     cdef void connect(self):
         del self._entries[:]
-        xmlerror.xmlSetStructuredErrorFunc(<void*>self, _receiveError)
+        connectErrorLog(<void*>self)
 
     cdef void disconnect(self):
-        xmlerror.xmlSetStructuredErrorFunc(NULL, _receiveError)
+        connectErrorLog(NULL)
 
     def clear(self):
         del self._entries[:]
@@ -326,8 +333,9 @@
     cdef char* c_message
     cdef char* c_element
     cdef int i, text_size, element_size
-    if __DEBUG == 0 or msg is NULL or cstd.strlen(msg) < 10:
+    if __DEBUG == 0 or msg is NULL or cstd.strcmp(msg, '\n') == 0:
         return
+
     cstd.va_start(args, msg)
     if msg[0] == c'%' and msg[1] == c's':
         c_text = cstd.va_charptr(args)
@@ -374,17 +382,6 @@
         python.PyMem_Free(c_error.message)
     python.PyGILState_Release(gil_state)
 
-# dummy function: no debug output at all
-cdef void _nullGenericErrorFunc(void* ctxt, char* msg, ...):
-    pass
-
-# setup for global log:
-cdef void _logLibxmlErrors():
-    xmlerror.xmlThrDefSetGenericErrorFunc(NULL, _nullGenericErrorFunc)
-    xmlerror.xmlSetGenericErrorFunc(NULL, _nullGenericErrorFunc)
-
-    xmlerror.xmlThrDefSetStructuredErrorFunc(NULL, _receiveError)
-    xmlerror.xmlSetStructuredErrorFunc(NULL, _receiveError)
 
 ################################################################################
 ## CONSTANTS FROM "xmlerror.h" (or rather libxml-xmlerror.html)

Modified: lxml/trunk/src/lxml/xslt.pxi
==============================================================================
--- lxml/trunk/src/lxml/xslt.pxi	(original)
+++ lxml/trunk/src/lxml/xslt.pxi	Fri Sep 15 21:37:48 2006
@@ -21,9 +21,6 @@
 LIBXSLT_COMPILED_VERSION = __unpackIntVersion(xslt.LIBXSLT_VERSION)
 LIBXSLT_VERSION = __unpackIntVersion(xslt.xsltLibxsltVersion)
 
-cdef void _logLibxsltErrors():
-    xslt.xsltSetGenericErrorFunc(NULL, _receiveXSLTError)
-
 
 ################################################################################
 # Where do we store what?


More information about the lxml-checkins mailing list