From: <pj...@us...> - 2008-11-10 02:53:09
|
Revision: 5562 http://jython.svn.sourceforge.net/jython/?rev=5562&view=rev Author: pjenvey Date: 2008-11-10 02:53:05 +0000 (Mon, 10 Nov 2008) Log Message: ----------- fix %c formatting to support unicode refs #1768075, fixes #1780767 Modified Paths: -------------- trunk/jython/Lib/test/test_unicode_jy.py trunk/jython/src/org/python/core/PyString.java Modified: trunk/jython/Lib/test/test_unicode_jy.py =================================================================== --- trunk/jython/Lib/test/test_unicode_jy.py 2008-11-10 01:22:11 UTC (rev 5561) +++ trunk/jython/Lib/test/test_unicode_jy.py 2008-11-10 02:53:05 UTC (rev 5562) @@ -4,6 +4,7 @@ Made for Jython. """ import re +import sys import unittest from test import test_support @@ -58,7 +59,20 @@ self.assertEqual(float(u'\u0663.\u0661'), 3.1) self.assertEqual(complex(u'\u0663.\u0661'), 3.1+0j) + def test_formatchar(self): + self.assertEqual('%c' % 255, '\xff') + self.assertRaises(OverflowError, '%c'.__mod__, 256) + result = u'%c' % 256 + self.assert_(isinstance(result, unicode)) + self.assertEqual(result, u'\u0100') + if sys.maxunicode == 0xffff: + self.assertEqual(u'%c' % sys.maxunicode, u'\uffff') + else: + self.assertEqual(u'%c' % sys.maxunicode, u'\U0010ffff') + self.assertRaises(OverflowError, '%c'.__mod__, sys.maxunicode + 1) + + def test_main(): test_support.run_unittest(UnicodeTestCase) Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2008-11-10 01:22:11 UTC (rev 5561) +++ trunk/jython/src/org/python/core/PyString.java 2008-11-10 02:53:05 UTC (rev 5562) @@ -2960,12 +2960,16 @@ } throw e; } - if (val < 0) { - throw Py.OverflowError("unsigned byte integer is less than minimum"); - } else if (val > 255) { - throw Py.OverflowError("unsigned byte integer is greater than maximum"); + if (!needUnicode) { + if (val < 0) { + throw Py.OverflowError("unsigned byte integer is less than minimum"); + } else if (val > 255) { + throw Py.OverflowError("unsigned byte integer is greater than maximum"); + } + } else if (val < 0 || val > PySystemState.maxunicode) { + throw Py.OverflowError("%c arg not in range(0x110000) (wide Python build)"); } - string = new Character((char)val).toString(); + string = new String(new int[] {val}, 0, 1); break; default: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |