Message10968
$ ./dist/bin/jython
Jython 2.7.1b3 (default:a07c595b410f, Oct 20 2016, 21:07:16)
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_111
Type "help", "copyright", "credits" or "license" for more information.
>>> import cStringIO
>>> s = cStringIO.StringIO(u'中文')
>>> s.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
at org.python.core.PyString.<init>(PyString.java:64)
at org.python.core.PyString.<init>(PyString.java:70)
at org.python.modules.cStringIO$StringIO.read(cStringIO.java:225)
at org.python.modules.cStringIO$StringIO.read(cStringIO.java:198)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
From https://docs.python.org/2/library/stringio.html:
Unlike the StringIO module, this module is not able to accept Unicode strings that cannot be encoded as plain ASCII strings.
Python 2 handles it well:
$ python2
Python 2.7.12 (default, Jun 28 2016, 08:31:05)
[GCC 6.1.1 20160602] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cStringIO
>>> s = cStringIO.StringIO(u'中文')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Jython should throw a Python exception instead of a Java one in this case. |
|
Date |
User |
Action |
Args |
2016-10-20 13:12:52 | yan12125 | set | recipients:
+ yan12125 |
2016-10-20 13:12:52 | yan12125 | set | messageid: <1476969172.79.0.172212034968.issue2527@psf.upfronthosting.co.za> |
2016-10-20 13:12:52 | yan12125 | link | issue2527 messages |
2016-10-20 13:12:51 | yan12125 | create | |
|