[MacPorts] #21517: py26-eyed3-0.6.17 LookupError: unknown encoding: x-mac-japanese

MacPorts noreply at macports.org
Sun Sep 20 05:47:32 PDT 2009


#21517: py26-eyed3-0.6.17 LookupError: unknown encoding: x-mac-japanese
---------------------------------+------------------------------------------
 Reporter:  null.atou@…          |       Owner:  macports-tickets@…                   
     Type:  enhancement          |      Status:  new                                  
 Priority:  Normal               |   Milestone:                                       
Component:  ports                |     Version:  1.8.0                                
 Keywords:  Python, locale       |        Port:  python26, python25                   
---------------------------------+------------------------------------------
 When the python script eyeD3 execute under Japanese environment,
 'LookupError: unknown encoding: x-mac-japanese' has occurred.
 {{{
 % __CF_USER_TEXT_ENCODING=$UID:0:0 eyeD3 hoge.mp3   <--- encoding is 'mac-
 roman'
 (snip, no error but many Mojibake occur!)
 % __CF_USER_TEXT_ENCODING=$UID:1:14 eyeD3 hoge.mp3  <--- In Japanese
 environment, __CF_USER_TEXT_ENCODING already set
 (snip)
 Uncaught exception: unknown encoding: x-mac-japanese
 Traceback (most recent call last):
   File "/opt/local/bin/eyeD3", line 1215, in <module>
     retval = main();
   File "/opt/local/bin/eyeD3", line 1192, in main
     retval = app.handleFile(f);
   File "/opt/local/bin/eyeD3", line 566, in handleFile
     self.printTag(self.tag);
   File "/opt/local/bin/eyeD3", line 937, in printTag
     "replace"),
 LookupError: unknown encoding: x-mac-japanese
 }}}
 This is because python26 (and also python25) don't look LANG env-
 var(ja_JP.UTF-8 in many case in Japan), but get an encoding name 'x-mac-
 japanese' from CoreFoundation CFStringGetSystemEncoding() and
 CFStringConvertEncodingToIANACharSetName() (see 'Lib/locale.py' and a
 source 'Modules/_localemodule.c'). Then, unfortunately, a python only
 knows codecs in the codec table[http://docs.python.org/library/codecs
 #standard-encodings]. In the table, there are no 'x-mac-japanese' or 'x
 -mac-trad-chinese' or 'x-mac-korean' etc... So a simple test is here:
 {{{
 % __CF_USER_TEXT_ENCODING=$UID:1:14 python -c 'import locale; print
 "getdefaultlocale is", locale.getdefaultlocale(), ", getpreferredencoding
 :", locale.getpreferredencoding();'
 getdefaultlocale is (None, 'x-mac-japanese') , getpreferredencoding : x
 -mac-japanese
 % __CF_USER_TEXT_ENCODING=$UID:1:14 /usr/bin/python -c 'import locale;
 print "getdefaultlocale is", locale.getdefaultlocale(), ",
 getpreferredencoding :", locale.getpreferredencoding();'
 getdefaultlocale is ('ja_JP', 'UTF8') , getpreferredencoding : UTF-8
 }}}
 Yes, apple's python2.6.1 in Snow Leopard (and also apple's python2.5.1 in
 Leopard) looks not CF_... but LANG.

 I referred to web pages (in Japanese)
 [http://metareal.jottit.com/tracinstall here] and
 [http://www.metareal.org/2007/09/09/fixup-python-locale-problems-by-apple-
 darwin-patch/ here], and made a simple patch arround locale problem. Under
 this patch, python26 looks LANG env-var and get well-known encoding
 'UTF-8', so, no error, no mojibake is  occurred in eyeD3:-)

 By the way, there is no unknown encoding error in python31 because a
 similar change applies in Modules/_localemodule.c in version 3.1.

-- 
Ticket URL: <http://trac.macports.org/ticket/21517>
MacPorts <http://www.macports.org/>
Ports system for Mac OS


More information about the macports-tickets mailing list