Пример #1
0
def _parseXML(context, unfinished, validate, remote):
    if context is None:
        raise LSException(LSException.PARSE_ERR, DOMError(DOMError.SEVERITY_FATAL_ERROR))

    Parser_configure(context, validate, remote)
    Parser_parse(context)
    doc = Parser_document(context)
    error = Parser_error()

    try:
        if validate and not Parser_valid(context):

            # NOTE: May not be the correct exception.

            raise LSException(
                LSException.PARSE_ERR,
                DOMError(
                    DOMError.SEVERITY_FATAL_ERROR,
                    get_parse_error_message() or "Document did not validate"
                    ))

        elif unfinished and (error is None or Parser_errorCode(error) == XML_ERR_TAG_NOT_FINISHED):

            # NOTE: There may be other unfinished conditions.

            return doc

        elif error is not None and Parser_errorLevel(error) == XML_ERR_FATAL:
            raise LSException(
                LSException.PARSE_ERR,
                DOMError(
                    DOMError.SEVERITY_FATAL_ERROR,
                    get_parse_error_message() or "Document caused fatal error"
                    ))

        else:

            # NOTE: Could provide non-fatal errors or warnings.

            return doc

    finally:
        Parser_resetError(error)
        libxml2mod.xmlFreeParserCtxt(context)
Пример #2
0
def _parseXML(context, unfinished, validate, remote):
    if context is None:
        raise LSException(LSException.PARSE_ERR, DOMError(DOMError.SEVERITY_FATAL_ERROR))

    Parser_configure(context, validate, remote)
    Parser_parse(context)
    doc = Parser_document(context)
    error = Parser_error()

    try:
        if validate and not Parser_valid(context):

            # NOTE: May not be the correct exception.

            raise LSException(
                LSException.PARSE_ERR,
                DOMError(
                    DOMError.SEVERITY_FATAL_ERROR,
                    get_parse_error_message() or "Document did not validate"
                    ))

        elif unfinished and (error is None or Parser_errorCode(error) == XML_ERR_TAG_NOT_FINISHED):

            # NOTE: There may be other unfinished conditions.

            return doc

        elif error is not None and Parser_errorLevel(error) == XML_ERR_FATAL:
            raise LSException(
                LSException.PARSE_ERR,
                DOMError(
                    DOMError.SEVERITY_FATAL_ERROR,
                    get_parse_error_message() or "Document caused fatal error"
                    ))

        else:

            # NOTE: Could provide non-fatal errors or warnings.

            return doc

    finally:
        Parser_resetError(error)
        libxml2mod.xmlFreeParserCtxt(context)
Пример #3
0
 def __del__(self):
     if self._o != None:
         libxml2mod.xmlFreeParserCtxt(self._o)
     self._o = None
Пример #4
0
 def __del__(self):
     if self._o != None:
         libxml2mod.xmlFreeParserCtxt(self._o)
     self._o = None