This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: locale.setlocale(locale.LC_ALL, locale.getlocale()) fails for some locales
Type: behavior Stage:
Components: Extension Modules, Library (Lib), macOS Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: ronaldoussoren Nosy List: exarkun, ronaldoussoren, vstinner
Priority: normal Keywords:

Created on 2011-06-29 18:51 by exarkun, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg139445 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2011-06-29 18:51
Consider this transcript from OS X 10.6:

>>> import locale
>>> locale.getlocale()
(None, None)
>>> locale.setlocale(locale.LC_ALL, _)
'C'
>>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
'en_US.UTF-8'
>>> locale.getlocale()
('en_US', 'UTF8')
>>> locale.setlocale(locale.LC_ALL, _)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/locale.py", line 494, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
>>> 

OS X does not recognize 'en_US.UTF8', only 'en_US.UTF-8'.  However, when passed a tuple, the locale module tries to normalize the values.  It ends up turning the result of getlocale from ('en_US', 'UTF-8') into 'en_US.UTF8'.
msg139446 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-06-29 18:55
Good news: it's a duplicate and it's already fixed! See issues #10090 and #10154. The fix is part of Python 3.1.4 (released the 12th june 2011) and Python 2.7.2 (released the 12 june 2011), and will be part of Python 3.2.1.
msg139447 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-06-29 18:56
(Python 2.6 only accepts security fixes, no more bug fixes. It's time to upgrade to 2.7!)
History
Date User Action Args
2022-04-11 14:57:19adminsetgithub: 56652
2011-06-29 18:56:30vstinnersetmessages: + msg139447
2011-06-29 18:55:23vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg139446

resolution: duplicate
2011-06-29 18:51:16exarkuncreate