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

noreply@sourceforge.net noreply@sourceforge.net
Sun, 29 Sep 2002 15:17:57 -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 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