Mercurial > genshi > mirror
diff markup/input.py @ 209:fc6b2fb66518 trunk
* Fix bug in handling of undefined entities. Thanks to Arnar for reporting the issue on IRC.
* Enable the `XMLParser` to handle HTML entities without requiring the declaration of a HTML document type.
author | cmlenz |
---|---|
date | Tue, 29 Aug 2006 16:34:40 +0000 |
parents | 28bfc6aafab7 |
children | 13d2d4420628 |
line wrap: on
line diff
--- a/markup/input.py +++ b/markup/input.py @@ -80,7 +80,11 @@ parser.EndCdataSectionHandler = self._handle_end_cdata parser.ProcessingInstructionHandler = self._handle_pi parser.CommentHandler = self._handle_comment + + # Tell Expat that we'll handle non-XML entities ourselves + # (in _handle_other) parser.DefaultHandler = self._handle_other + parser.UseForeignDTD() # Location reporting is only support in Python >= 2.4 if not hasattr(parser, 'CurrentLineNumber'): @@ -184,9 +188,13 @@ text = unichr(htmlentitydefs.name2codepoint[text[1:-1]]) self._enqueue(TEXT, text) except KeyError: - lineno, offset = self._getpos() - raise expat.error("undefined entity %s: line %d, column %d" % - (text, lineno, offset)) + filename, lineno, offset = self._getpos() + error = expat.error('undefined entity "%s": line %d, column %d' + % (text, lineno, offset)) + error.code = expat.errors.XML_ERROR_UNDEFINED_ENTITY + error.lineno = lineno + error.offset = offset + raise error def XML(text):