From: <pj...@us...> - 2010-04-02 01:42:13
|
Revision: 6996 http://jython.svn.sourceforge.net/jython/?rev=6996&view=rev Author: pjenvey Date: 2010-04-02 01:42:07 +0000 (Fri, 02 Apr 2010) Log Message: ----------- have Java objects' __unicode__ pass-thru the result of their toString fixes #1563 Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/NEWS trunk/jython/src/org/python/core/PyJavaType.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/ToUnicode.java Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2010-04-01 12:07:25 UTC (rev 6995) +++ trunk/jython/Lib/test/test_java_integration.py 2010-04-02 01:42:07 UTC (rev 6996) @@ -20,7 +20,8 @@ from javax.swing.tree import TreePath from org.python.core.util import FileUtil -from org.python.tests import BeanImplementation, Child, Child2, Listenable, CustomizableMapHolder +from org.python.tests import (BeanImplementation, Child, Child2, + CustomizableMapHolder, Listenable, ToUnicode) from org.python.tests.mro import (ConfusedOnGetitemAdd, FirstPredefinedGetitem, GetitemAdder) class InstantiationTest(unittest.TestCase): @@ -478,6 +479,13 @@ unserializer = ObjectInputStream(input) self.assertEqual(date_list, unserializer.readObject()) +class UnicodeTest(unittest.TestCase): + + def test_unicode_conversion(self): + test = unicode(ToUnicode()) + self.assertEqual(type(test), unicode) + self.assertEqual(test, u"Circle is 360\u00B0") + def test_main(): test_support.run_unittest(InstantiationTest, BeanTest, @@ -493,7 +501,8 @@ JavaDelegationTest, SecurityManagerTest, JavaWrapperCustomizationTest, - SerializationTest) + SerializationTest, + UnicodeTest) if __name__ == "__main__": test_main() Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-04-01 12:07:25 UTC (rev 6995) +++ trunk/jython/NEWS 2010-04-02 01:42:07 UTC (rev 6996) @@ -20,6 +20,7 @@ - [ 1426 ] JSR 223 Bindings changes not taking effect and leaking between threads; unnecessary synchronization - [ 1548 ] Parentheses in CLASSPATH cause errors in jython.bat - [ 1576 ] files opened in 'a+' mode not readable + - [ 1563 ] unicode() for Java objects working differently in 2.2 and 2.5 - Fix runtime issues during exitfuncs triggered via SystemRestart (such as during Django or Pylons development mode reloading) - Fix pickling of collections.defaultdict objects Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2010-04-01 12:07:25 UTC (rev 6995) +++ trunk/jython/src/org/python/core/PyJavaType.java 2010-04-02 01:42:07 UTC (rev 6996) @@ -542,6 +542,12 @@ return Py.newString(self.getJavaProxy().toString()); } }); + addMethod(new PyBuiltinMethodNarrow("__unicode__") { + @Override + public PyObject __call__() { + return new PyUnicode(self.toString()); + } + }); } if(forClass == Comparable.class) { addMethod(new ComparableMethod("__lt__", 1) { Added: trunk/jython/tests/java/org/python/tests/ToUnicode.java =================================================================== --- trunk/jython/tests/java/org/python/tests/ToUnicode.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/ToUnicode.java 2010-04-02 01:42:07 UTC (rev 6996) @@ -0,0 +1,9 @@ +package org.python.tests; + +public class ToUnicode { + + @Override + public String toString() { + return "Circle is 360\u00B0"; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |