From: <am...@us...> - 2010-04-01 12:07:35
|
Revision: 6995 http://jython.svn.sourceforge.net/jython/?rev=6995&view=rev Author: amak Date: 2010-04-01 12:07:25 +0000 (Thu, 01 Apr 2010) Log Message: ----------- Some unittests for unicode usage with xml.dom.pulldom Modified Paths: -------------- trunk/jython/Lib/xml/sax/drivers2/drv_javasax.py trunk/jython/NEWS Added Paths: ----------- trunk/jython/Lib/test/test_pulldom.py Added: trunk/jython/Lib/test/test_pulldom.py =================================================================== --- trunk/jython/Lib/test/test_pulldom.py (rev 0) +++ trunk/jython/Lib/test/test_pulldom.py 2010-04-01 12:07:25 UTC (rev 6995) @@ -0,0 +1,77 @@ +""" + This is not an exhaustive pulldom test suite. + Instead, it is a place to put jython-specific tests, + relating to bugs like this one, for example. + + "xml.dom.Node.data returns bytestrings of decoded unicode" + http://bugs.jython.org/issue1583 + + amak. +""" + +import StringIO +import unittest +from xml.dom import pulldom +from test import test_support + +class UnicodeTests(unittest.TestCase): + + testDoc = """\ +<?xml version="1.0" encoding="ascii"?> +<document> + <p>Some greek: ΑΒΓΔΕ</p> + <greek attrs="ΖΗΘΙΚ"/> + <?greek ΛΜΝΞΟ?> +</document> +""" + + def setUp(self): + self.testFile = StringIO.StringIO(self.testDoc) + + def testTextNodes(self): + text = [] + for event, node in pulldom.parse(self.testFile): + if event == pulldom.CHARACTERS: + 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'") + except Exception, x: + self.fail("Unexpected exception joining text pieces: %s" % str(x)) + + def testAttributes(self): + attrText = [] + for event, node in pulldom.parse(self.testFile): + if event == pulldom.START_ELEMENT: + for attrIx in range(node.attributes.length): + attrText.append(node.attributes.item(attrIx).value) + try: + result = u"".join(attrText) + self.failUnlessEqual(repr(result), r"u'\u0396\u0397\u0398\u0399\u039a'") + except Exception, x: + self.fail("Unexpected exception joining attribute text pieces: %s" % str(x)) + + def testProcessingInstruction(self): + piText = [] + for event, node in pulldom.parse(self.testFile): + if event == pulldom.PROCESSING_INSTRUCTION: + piText.append(node.data) + try: + result = u"".join(piText) + # Weird how the repr for PI data is different from text and char data. + # Still, the whole xml.dom.* and xml.sax.* hierarchy is rather a + # labyrinthine mess under jython, mostly because it's so old, and + # yet survived through major evolutionary changes in both jython and java. + self.failUnlessEqual(repr(result), r"u'ΛΜΝΞΟ'") + except Exception, x: + self.fail("Unexpected exception joining pi data pieces: %s" % str(x)) + +def test_main(): + tests = [ + UnicodeTests, + ] + suites = [unittest.makeSuite(klass, 'test') for klass in tests] + test_support.run_suite(unittest.TestSuite(suites)) + +if __name__ == "__main__": + test_main() Modified: trunk/jython/Lib/xml/sax/drivers2/drv_javasax.py =================================================================== --- trunk/jython/Lib/xml/sax/drivers2/drv_javasax.py 2010-04-01 07:41:40 UTC (rev 6994) +++ trunk/jython/Lib/xml/sax/drivers2/drv_javasax.py 2010-04-01 12:07:25 UTC (rev 6995) @@ -188,7 +188,7 @@ self._cont_handler.characters(String(char, start, len).getBytes('utf-8').tostring().decode('utf-8')) def ignorableWhitespace(self, char, start, len): - self._cont_handler.ignorableWhitespace(str(String(char, start, len))) + self._cont_handler.ignorableWhitespace(String(char, start, len).getBytes('utf-8').tostring().decode('utf-8')) def endElement(self, uri, lname, qname): if self._namespaces: Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-04-01 07:41:40 UTC (rev 6994) +++ trunk/jython/NEWS 2010-04-01 12:07:25 UTC (rev 6995) @@ -2,6 +2,7 @@ Jython 2.5.2a1 Bugs Fixed + - [ 1583 ] xml.dom.Node.data returns bytestrings of decoded unicode - [ 1225 ] socket.getservbyname/port() not yet supported - [ 1532 ] Cannot use docstring when defining class - [ 1530 ] BoolOp in multiple assign causes VerifyError This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |