From: <am...@us...> - 2010-04-16 17:37:51
|
Revision: 7027 http://jython.svn.sourceforge.net/jython/?rev=7027&view=rev Author: amak Date: 2010-04-16 17:37:44 +0000 (Fri, 16 Apr 2010) Log Message: ----------- Fix for bug 1510: minidom is not parsing comment information correctly http://bugs.jython.org/issue1510 Thanks to William Bernardet for the bug report and the patch. Modified Paths: -------------- trunk/jython/Lib/test/test_pulldom.py trunk/jython/Lib/xml/sax/drivers2/drv_javasax.py Modified: trunk/jython/Lib/test/test_pulldom.py =================================================================== --- trunk/jython/Lib/test/test_pulldom.py 2010-04-14 02:39:55 UTC (rev 7026) +++ trunk/jython/Lib/test/test_pulldom.py 2010-04-16 17:37:44 UTC (rev 7027) @@ -22,6 +22,7 @@ <p>Some greek: ΑΒΓΔΕ</p> <greek attrs="ΖΗΘΙΚ"/> <?greek ΛΜΝΞΟ?> + <!--ΛΜΝΞΟ--> </document> """ @@ -35,7 +36,7 @@ text.append(node.data) try: result = u"".join(text) - self.failUnlessEqual(repr(result), r"u'\n Some greek: \u0391\u0392\u0393\u0394\u0395\n \n \n'") + self.failUnlessEqual(repr(result), r"u'\n Some greek: \u0391\u0392\u0393\u0394\u0395\n \n \n \n'") except Exception, x: self.fail("Unexpected exception joining text pieces: %s" % str(x)) @@ -66,6 +67,17 @@ except Exception, x: self.fail("Unexpected exception joining pi data pieces: %s" % str(x)) + def testComment(self): + commentText = [] + for event, node in pulldom.parse(self.testFile): + if event == pulldom.COMMENT: + commentText.append(node.data) + try: + result = u"".join(commentText) + self.failUnlessEqual(repr(result), r"u'ΛΜΝΞΟ'") + except Exception, x: + self.fail("Unexpected exception joining comment data pieces: %s" % str(x)) + def test_main(): tests = [ UnicodeTests, Modified: trunk/jython/Lib/xml/sax/drivers2/drv_javasax.py =================================================================== --- trunk/jython/Lib/xml/sax/drivers2/drv_javasax.py 2010-04-14 02:39:55 UTC (rev 7026) +++ trunk/jython/Lib/xml/sax/drivers2/drv_javasax.py 2010-04-16 17:37:44 UTC (rev 7027) @@ -25,6 +25,7 @@ from org.python.core import FilelikeInputStream from org.xml.sax.helpers import XMLReaderFactory from org.xml import sax as javasax + from org.xml.sax.ext import LexicalHandler except ImportError: raise _exceptions.SAXReaderNotAvailable("SAX is not on the classpath", None) @@ -119,7 +120,7 @@ return self.sysId # --- JavaSAXParser -class JavaSAXParser(xmlreader.XMLReader, javasax.ContentHandler): +class JavaSAXParser(xmlreader.XMLReader, javasax.ContentHandler, LexicalHandler): "SAX driver for the Java SAX parsers." def __init__(self, jdriver = None): @@ -133,6 +134,10 @@ self.setEntityResolver(self.getEntityResolver()) self.setErrorHandler(self.getErrorHandler()) self.setDTDHandler(self.getDTDHandler()) + try: + self._parser.setProperty("http://xml.org/sax/properties/lexical-handler", self) + except Exception, x: + pass # XMLReader methods @@ -206,6 +211,9 @@ def processingInstruction(self, target, data): self._cont_handler.processingInstruction(target, data) + def comment(self, char, start, len): + self._cont_handler.comment(unicode(String(char, start, len))) + class AttributesImpl: def __init__(self, attrs = None): self._attrs = attrs This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |