On Feb 23, 2010, at 3:49 PM, Chris Clark wrote:
> I seen a few email trails and (old) bugs on encoding support in Jython:
>
> http://sourceforge.net/mailarchive/forum.php?thread_name=d03bb4010901080735y38879c6t30829ded241337b0%40mail.gmail.com&forum_name=jython-users
> http://sourceforge.net/mailarchive/forum.php?thread_name=96c4692d0907251347m7e7da5ddv63487a66683b3d82%40mail.gmail.com&forum_name=jython-users
>
> http://bugs.jython.org/issue1410
> http://bugs.jython.org/issue1066
>
> but I'm still confused about what is and is not supported.
>
> Sample session:
>
> C:\jython2.5.1>dir C:\jython2.5.1\Lib\encodings\shift*py
> Volume in drive C has no label.
> Volume Serial Number is 547C-9409
>
> Directory of C:\jython2.5.1\Lib\encodings
>
> 09/26/2009 12:48 PM 1,039 shift_jis.py
> 09/26/2009 12:48 PM 1,059 shift_jisx0213.py
> 09/26/2009 12:48 PM 1,059 shift_jis_2004.py
> 3 File(s) 3,157 bytes
> 0 Dir(s) 3,572,412,416 bytes free
>
> C:\jython2.5.1>jython
> Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
> [Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_02
> Type "help", "copyright", "credits" or "license" for more information.
>>>> x=''
>>>> x.decode('shift_jis')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> LookupError: unknown encoding 'shift_jis'
>
> The encoding does exist, however there may be something going on with
> _codecs_jp (or I guess not going on) - here is what happens if the
> encoding is explicitly imported:
>
> C:\jython2.5.1\Lib\encodings>C:\jython2.5.1\jython
> Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
> [Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_02
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import shift_jis
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "shift_jis.py", line 7, in <module>
> import _codecs_jp, codecs
> ImportError: No module named _codecs_jp
>
>
> Here is what I was expecting :-)
>
> C:\jython2.5.1>c:\Python25\python
> Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
> (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> x=''
>>>> x.decode('shift_jis')
> u''
>
>
> Any tips/workarounds I can use? Is there something wrong with my install?
>
> Thanks in advance,
#1066 is the main bug for this issue -- we just currently lack support for the asian codecs like shiftjis. The ImportError in sample #2 is a symptom of that. The same ImportError happens when you attempt to use the codec but it's masked as a LookupError.
Supporting these via the JVM's nio codecs is definitely doable but nobody's gotten around to it yet.
--
Philip Jenvey
|