[xml] using "raise" in Python error handler callbacks

Whilst experimenting with the Python bindings I noticed that exceptions are not propagated when using registerErrorHandler(). If I run the following I get the error message:

        /etc/passwd : failed to parse.

However, there is no Traceback for the "raise".  Is this correct?

import libxml2
import sys

def callback(ctx, str):
    print str
    raise ("How come I don't see this exception: " % str)

libxml2.registerErrorHandler (callback, "!!!")

def processNode(reader):
    print "%d %d %s %d" % (reader.Depth(), reader.NodeType(),
                           reader.Name(), reader.IsEmptyElement())

def streamFile(filename):
        reader = libxml2.newTextReaderFilename(filename)
        reader.SetParserProp(libxml2.PARSER_DEFAULTATTRS, 1)
        reader.SetParserProp(libxml2.PARSER_VALIDATE, 1)
        print "unable to open %s" % (filename)

    ret = reader.Read()

    while ret == 1:
        ret = reader.Read()

    if ret != 0:
        print "%s : failed to parse" % (filename)
        sys.exit (1)

    if reader.IsValid() != 1:
        print "Document failed to validate"

streamFile ("/etc/passwd")

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