def parseFileAndReport(filename, _open=file):
    """
    Parse and return the contents of the given lore XHTML document.

    @type filename: C{str}
    @param filename: The name of a file containing a lore XHTML document to
    load.

    @raise process.ProcessingFailure: When the contents of the specified file
    cannot be parsed.

    @rtype: A DOM Document
    @return: The document contained in C{filename}.
    """
    content = _TagTrackingContentHandler()
    error = _LocationReportingErrorHandler(content)
    parser = make_parser()
    parser.setContentHandler(content)
    parser.setErrorHandler(error)

    # In order to call a method on the expat parser which will be used by this
    # parser, we need the expat parser to be created.  This doesn't happen
    # until reset is called, normally by the parser's parse method.  That's too
    # late for us, since it will then go on to parse the document without
    # letting us do any extra set up.  So, force the expat parser to be created
    # here, and then disable reset so that the parser created is the one
    # actually used to parse our document.  Resetting is only needed if more
    # than one document is going to be parsed, and that isn't the case here.
    parser.reset()
    parser.reset = lambda: None

    # This is necessary to make the xhtml1 transitional declaration optional.
    # It causes LocalEntityResolver.resolveEntity(None, None) to be called.
    # LocalEntityResolver handles that case by giving out the xhtml1
    # transitional dtd.  Unfortunately, there is no public API for manipulating
    # the expat parser when using xml.sax.  Using the private _parser attribute
    # may break.  It's also possible that make_parser will return a parser
    # which doesn't use expat, but uses some other parser.  Oh well. :(
    # -exarkun
    parser._parser.UseForeignDTD(True)
    parser.setEntityResolver(_LocalEntityResolver(filename))

    # This is probably no-op because expat is not a validating parser.  Who
    # knows though, maybe you figured out a way to not use expat.
    parser.setFeature(feature_validation, False)

    fObj = _open(filename)
    try:
        try:
            parser.parse(fObj)
        except __HOLE__, e:
            raise process.ProcessingFailure(
                e.strerror + ", filename was '" + filename + "'")
    finally:
        fObj.close()
    return content.document
dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/twisted/lore/tree.py/parseFileAndReport