[Python-bugs-list] [ python-Bugs-616002 ] getdefaultlocale failure on OS X

noreply@sourceforge.net noreply@sourceforge.net
Mon, 30 Sep 2002 00:38:29 -0700


Bugs item #616002, was opened at 2002-09-29 02:20
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=616002&group_id=5470

Category: IDLE
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Brian Lenihan (brianl)
Assigned to: Nobody/Anonymous (nobody)
Summary: getdefaultlocale failure on OS X

Initial Comment:
My OS X laptop did not have LANG  set in the bash
envrionment and idle (AquaTK) failed to launch with an
AttributeError in IOBinding.py

        try:
            encoding = locale.getdefaultlocale()[1]
            codecs.lookup(encoding)
        except (ValueError, LookupError):
            pass

encoding = encoding.lower()
^^^^^

encoding is None here because locale.getdefaultlocale()
returns (None, None) when the locale can't be determined.

After finding that adding LANG=en_US to my .bashrc
didn't help, I Iearned OS X GUI apps don't use the
shell's environment, but do use whatever they find in
~/.MacOSX/environment.plist.  Adding a couple lines:

        <key>LANG</key>
        <string>en_US</string>

makes idle happy.   An alternative would be to make
sure encoding never gets set to None.

--- IOBinding.py.orig   Sat Sep 28 17:17:02 2002
+++ IOBinding.py        Sat Sep 28 17:17:42 2002
@@ -64,7 +64,7 @@
         # which may give a clue. Unfortunately,
getdefaultlocale has
         # bugs that can cause ValueError.
         try:
-            encoding = locale.getdefaultlocale()[1]
+            encoding = locale.getdefaultlocale()[1] or
'ascii'
             codecs.lookup(encoding)
         except (ValueError, LookupError):
             pass
 




 
 



----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2002-09-30 09:38

Message:
Logged In: YES 
user_id=21627

I agree that there is a bug somewhere. I also suspect that
the bug is in IDLE, but I think it is wrong to fall-back to
ASCII on OS X (I'm almost certain that the user's encoding
is never just ASCII on that system). I suspect that it is
MacRoman or some such, but I also suspect that this either
might vary with the localized version of OS X (assuming
there are localized versions), or with a per-user setting.

----------------------------------------------------------------------

Comment By: Brian Lenihan (brianl)
Date: 2002-09-30 04:18

Message:
Logged In: YES 
user_id=17671

I've done a little digging and have yet to find a
satisfactory answer.

This article: 
http://developer.apple.com/internet/macosx/perl.html has
instructions for upgrading perl to 5.8.0

"OS X has one of the necessary environment variables set
(LANG), but without the above, you'll get annoying error
messages each time you try to run a script. The above
assumes the tcsh shell; if you prefer bash, use echo "export
LC_ALL=C" >> ~/.bash_profile instead."

I'll keep digging for a good answer, but I still believe
there is a bug here.  If you look in IOBinding.py, you'll
see that encoding is given a default value of "ascii".   It
should leave the section with that value intact or with
ascii replaced with the proper locale.

The possibility that getdefaultlocale will punt and return
(None, None) is not taken into account in IOBinding.py

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-09-30 00:17

Message:
Logged In: YES 
user_id=21627

Can you please find out how to determine the user's
prefererred encoding on OS X?

Yes, getdefaultlocale is broken, but that is by design, and
cannot be fixed. So we should reduce its usage instead of
trying to correct it.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=616002&group_id=5470