def syntax_error(self, message): "Handles fatal errors." if self._can_locate(): self.err_handler.fatalError( saxlib.SAXParseException(message, None, self)) else: self.err_handler.fatalError(saxlib.SAXException(message, None))
def parseFile(self, fileobj): "Parses the given file." if self._can_locate(): self.doc_handler.setDocumentLocator(self) self.reset() while 1: buf = fileobj.read(16384) if buf == "": break try: self.feed(buf) except RuntimeError, e: self.err_handler.fatalError(saxlib.SAXException(str(e), e))
def _parse(self, file): bit = GetNextBit(file) while bit: if bit.type == "start": self.doc_handler.startElement(bit.label, AttributeItem(bit.item)) elif bit.type == "end": self.doc_handler.endElement(bit.label) elif bit.type == "text": self.doc_handler.characters(bit.body, 0, len(bit.body)) elif bit.type == "empty": self.doc_handler.startElement(bit.label, AttributeItem(bit.item)) self.doc_handler.endElement(bit.label) elif bit.type == "bad": self.err_handler.fatalError( saxlib.SAXException("Syntax error", None)) elif bit.type == "pi": print "?pi" else: print "###" + bit.type bit = GetNextBit(file)
def unknown_charref(self, no): "Handles non-ASCII character references." self.err_handler.fatalError( saxlib.SAXException("Reference to unknown character '%d'" % no, None))
def unknown_entityref(self, name): "Handles entity references by throwing an error." self.err_handler.fatalError( saxlib.SAXException("Reference to unknown entity " "'%s'" % name, None))
def report_unbalanced(self, gi): "Reports unbalanced tags." self.err_handler.fatalError( saxlib.SAXException("Unbalanced end tag for '%s'" % gi, None))