0x0
  7   aˆl–ßi~”*_)%‚~àYS�ÿ�þHcY²Ën¾y ?ò„iöÙñ¿î ?÷     a# DEBUG and error logging

from lxml.includes cimport xmlerror
from lxml cimport cvarargs

DEF GLOBAL_ERROR_LOG = u"_GlobalErrorLog"
DEF XSLT_ERROR_LOG = u"_XSLTErrorLog"

# module level API functions

def clear_error_log():
    u"""clear_error_log()

    Clear the global error log.  Note that this log is already bound to a
    fixed size.

    Note: since lxml 2.2, the global error log is local to a thread
    and this function will only clear the global error log of the
    current thread.
    """
    _getThreadErrorLog(GLOBAL_ERROR_LOG).clear()


# setup for global log:

cdef void _initThreadLogging():
    # Disable generic error lines from libxml2.
    _connectGenericErrorLog(None)

    # Divert XSLT error messages to the global XSLT error log instead of stderr.
    xslt.xsltSetGenericErrorFunc(NULL, <xmlerror.xmlGenericErrorFunc>_receiveXSLTError)


# Logging classes

@cython.final
@cython.freelist(16)
cdef class _LogEntry:
    """A log message entry from an error log.

    Attributes:

    - message: the message text
    - domain: the domain ID (see lxml.etree.ErrorDomains)
    - type: the message type ID (see lxml.etree.ErrorTypes)
    - level: the log level ID (see lxml.etree.ErrorLevels)
    - line: the line at which the message originated (if applicable)
    - column: the character column at which the message originated (if applicable)
    - filename: the name of the file in which the message originated (if applicable)
    - path: the location in which the error was found (if available)
    """
    cdef readonly int domain
    cdef readonly int type
    cdef readonly int level
    cdef readonly int line
    cdef readonly int column
    cdef basestring _message
    cdef basestring _filename
    cdef char* _c_message
    cdef xmlChar* _c_filename
    cdef xmlChar* _c_path

    def __dealloc__(self):
        tree.xmlFree(self._c_message)
        tree.xmlFree(self._c_filename)
        tree.xmlFree(self._c_path)

    @cython.final
    cdef _setError(self, xmlerror.xmlError* error):
        self.domain   = error.domain
        self.type     = error.code
        self.level    = <int>error.level
        self.line     = error.line
        self.column   = error.int2
        self._c_message = NULL
        self._c_filename = NULL
        self._c_path = NULL
        if (error.message is NULL or
                error.message[0] == b'\0' or
                error.message[0] == b'\n' and error.message[1] == b'\0'):
            self._message = u"unknown error"
        else:
            self._message = None
            self._c_message = <char*> tree.xmlStrdup(
                <const_xmlChar*> error.message)
            if not self._c_message:
                raise MemoryError()
        if error.file is NULL:
            self._filename = u'<string>'
        else:
            self._filename = None
            self._c_filename = tree.xmlStrdup(<const_xmlChar*> error.file)
            if not self._c_filename:
                raise MemoryError()
        if error.node is not NULL:
            self._c_path = tree.xmlGetNodePath(<xmlNode*> error.node)

    @cython.final
    cdef _setGeneric(self, int domain, int type, int level, int line,
                     message, filename):
        self.domain  = domain
        self.type    = type
        self.level   = level
        self.line    = line
        self.column  = 0
        self._message = message
        self._filename = filename
        self._c_path = NULL

    def __repr__(self):
        return u"%s:%d:%d:%s:%s:%s: %s" % (
            self.filename, self.line, self.column, self.level_name,
            self.domain_name, self.type_name, self.message)

    @property
    def domain_name(self):
        """The name of the error domain.  See lxml.etree.ErrorDomains
        """
        return ErrorDomains._getName(self.domain, u"unknown")

    @property
    def type_name(self):
        """The name of the error type.  See lxml.etree.ErrorTypes
        """
        if self.domain == ErrorDomains.RELAXNGV:
            ge