classification
Title: locale.resetlocale is broken
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: locale.getdefaultlocale doesnt handle all locales gracefully
View: 813449
Superseder:
Assigned To: Nosy List: BreamoreBoy, georg.brandl, georg.brandl, jlgijsbers, loewis, meonkeys, mhammond, syvere, tim_one
Priority: normal Keywords:

Created on 2002-01-16 04:56 by syvere, last changed 2010-08-17 21:22 by BreamoreBoy.

Messages (9)
msg8774 - (view) Author: Syver Enstad (syvere) Date: 2002-01-16 04:56
locale.setlocale doesn't recognize the the format that 
locale.py uses to set the locale, ie. no_NO and 
friends.

The only way I've succeeded in setting the locale on 
Python 2.1 is to use the format described in the 
Visual C++ C-runtime library docs for setlocale where 
a more verbose format is used to set the locale.
msg8775 - (view) Author: Tim Peters (tim_one) * (Python committer) Date: 2002-01-16 05:07
Logged In: YES 
user_id=31435

Mark, know anything about this?  I don't.
msg8776 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-01-16 11:50
Logged In: YES 
user_id=21627

Can you provide a detailed test case? AFAIK, no_NO is indeed
no supported locale name on Windows, and I don't think
Python aanywhere uses it without the application explicitly
saying so.
msg8777 - (view) Author: Syver Enstad (syvere) Date: 2002-01-16 13:39
Logged In: YES 
user_id=428736

Sorry, I forgot to mention the testcase I am using. The 
test case that fails is the locale module itself, when 
running it as a standalone application that is.

To be more specific:
  File "d:\devtools\python21\lib\locale.py", line 384, in 
resetlocale
    _setlocale(category, _build_localename(getdefaultlocale
()))
locale.Error: locale setting not supported

And to clarify what input getdefaultlocale returns on my 
machine:

>>> locale.getdefaultlocale()
('no_NO', 'cp1252')

and:
>>> locale._build_localename(locale.getdefaultlocale())
'no_NO.cp1252'

By the way, is this bug fixed in python 2.2?
msg8778 - (view) Author: Johannes Gijsbers (jlgijsbers) * Date: 2004-11-08 18:59
Logged In: YES 
user_id=469548

Still reproducible with Python 2.4:

Python 2.4b2 (#19, Nov  8 2004, 11:15:07)
[GCC 3.3.5 (Debian 1:3.3.5-2)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> import locale
>>> locale.getdefaultlocale()
['en_US', 'utf']
>>> locale.resetlocale()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/johannes/python/Lib/locale.py", line 389, in
resetlocale
    _setlocale(category, _build_localename(getdefaultlocale()))
locale.Error: unsupported locale setting

Note that if I run python with 'LANG=nl_NL python', the
error does not occur.

http://python.org/sf/813449 seems to be the same bug, BTW.
msg8779 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-05 18:04
Logged In: YES 
user_id=1188172

As this is not Windows specific, setting Category to Library.
msg8780 - (view) Author: Adam Monsen (meonkeys) Date: 2005-09-13 22:27
Logged In: YES 
user_id=259388

I'm seeing this error on Fedora Core 4:

Python 2.4.1 (#1, May 16 2005, 15:19:29) 
[GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> import locale; locale.getdefaultlocale()
('en_US', 'utf')
>>> locale.resetlocale()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/locale.py", line 389, in resetlocale
    _setlocale(category, _build_localename(getdefaultlocale()))
locale.Error: unsupported locale setting
msg8781 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-20 19:09
Logged In: YES 
user_id=849994

The same applies to other locales.

From #813449 (a duplicate of this):
"""
This is a known limitation: getdefaultlocale should not be
used in new code.

If the intention is to compute the locale's encoding,
locale.getpreferredencoding should be used instead.
"""
msg114172 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-08-17 21:22
Still a problems on py3k.  Set stage to needs patch as it's so easy to reproduce.
History
Date User Action Args
2010-08-17 21:22:44BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
nosy: + BreamoreBoy
messages: + msg114172

assignee: mhammond ->
stage: test needed -> needs patch
2009-02-13 02:24:59ajaksu2setdependencies: + locale.getdefaultlocale doesnt handle all locales gracefully
type: behavior
stage: test needed
versions: + Python 2.6, - Python 2.4
2002-01-16 04:56:12syverecreate