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: unpack error in getdefaultlocale() on certain locales
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: lemburg Nosy List: calvin, lemburg, sorlov
Priority: normal Keywords:

Created on 2005-03-08 09:40 by calvin, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python_locale.diff calvin, 2005-03-08 09:40
Messages (12)
msg24504 - (view) Author: Bastian Kleineidam (calvin) Date: 2005-03-08 09:40
Patch fixes the locale breakage mentioned in the bug by
using the normalized locale var. Patch is against
current CVS.
msg24505 - (view) Author: Serge Orlov (sorlov) Date: 2005-03-09 19:26
Logged In: YES 
user_id=1235914

I don't get what this patch fixes. It actually changes
handling of locales with @ sign, but there is no mentioning
of that in bug 1158490. What do I miss?
msg24506 - (view) Author: Bastian Kleineidam (calvin) Date: 2005-03-09 19:59
Logged In: YES 
user_id=9205

I forgot an example. this fails for me on current CVS:
$ env LANG=de_DE@euro python2.5 -c "import locale; print
locale.getdefaultlocale()"
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "/usr/local/lib/python2.5/locale.py", line 357, in
getdefaultlocale
    return _parse_localename(localename)
  File "/usr/local/lib/python2.5/locale.py", line 280, in
_parse_localename
    code, modifier = code.split('@')
ValueError: need more than 1 value to unpack

The error is that the @ char is searched in the original
locale, but the split is done on the normalized locale.
Hence the unpack error.
msg24507 - (view) Author: Serge Orlov (sorlov) Date: 2005-03-09 20:31
Logged In: YES 
user_id=1235914

I think the correct fix is to remove the whole if '@' in
code:. There is also a comment that the code under if is
bogus. The reason for the breakage is that
locale.normalize('de_DE@euro') started to return
de_DE.ISO8859-15
msg24508 - (view) Author: Bastian Kleineidam (calvin) Date: 2005-03-09 21:35
Logged In: YES 
user_id=9205

Wouldn't removing the if '@' stuff break other cases? For
example locale.normalize('en_EN@euro') still returns
'en_EN@euro'. In this case the @euro part would not get
split off and will be returned. When I understand the
documentation of getdefaultlocale() correctly, it is not
supposed to return the @euro part.
msg24509 - (view) Author: Serge Orlov (sorlov) Date: 2005-03-10 13:58
Logged In: YES 
user_id=1235914

There is no en_EN@euro because England hasn't joined EU :)
If the code that tries to guess encoding is removed it will
raise an exception:
ValueError: unknown locale: en_EN@euro
Like locale command line tool prints warning:
LANG=en_EN@euro locale charmap
locale: Cannot set LC_CTYPE to default locale: No such file
or directory
locale: Cannot set LC_MESSAGES to default locale: No such
file or directory
locale: Cannot set LC_ALL to default locale: No such file or
directory
ANSI_X3.4-1968

msg24510 - (view) Author: Serge Orlov (sorlov) Date: 2005-03-10 14:01
Logged In: YES 
user_id=1235914

Sorry, I mean England hasn't accepted euro as default
currency, not that England hasn't joined EU. Sometimes I
write not what I think :)
msg24511 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2005-03-10 15:43
Logged In: YES 
user_id=38388

Sorry, but this patch doesn't fix the bug. See bug #1158490
for discussion.
msg24512 - (view) Author: Bastian Kleineidam (calvin) Date: 2005-03-10 16:06
Logged In: YES 
user_id=9205

Oops, I misread the bug report #1158490. I thought it is the
same problem as described here. This is a separate issue,
and I edited the summary accordingly. The bug can be
reproduced with:
$ env -i LANG=de_DE@euro python2.5 -c "import locale; print
locale.getdefaultlocale()"

Sorry for the misunderstanding.
msg24513 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2005-03-10 17:22
Logged In: YES 
user_id=38388

Change ticket type to bug.
msg24514 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2005-03-10 17:38
Logged In: YES 
user_id=38388

Reference:
http://www.delorie.com/gnu/docs/glibc/libc_138.html

Just as note to myself: 

Need to change the code in _parse_localename() - the special
casing of the euro modifier is wrong and should be removed
(the locale database now contains all valid references to
iso-8859-15). Looking at the locale database, it seems safe
to just strip off the modifier: if the database doesn't have
an entry for the modifier, there's nothing much we can do
with it anyway.
msg65804 - (view) Author: Bastian Kleineidam (calvin) Date: 2008-04-25 19:37
This bug is fixed. The fix has been checked in by Georg Brandl on
20.1.2006 here:
http://svn.python.org/view/python/trunk/Lib/locale.py?rev=42100&r1=39572&r2=42100

So this bug has been fixed in Python 2.5 all along. Why did I have this
error then? Perhaps I tested with 2.4 back then. Anyway, I think this
bug can be closed.
History
Date User Action Args
2022-04-11 14:56:10adminsetgithub: 41666
2008-04-25 20:40:12benjamin.petersonsetstatus: open -> closed
resolution: fixed
2008-04-25 19:37:22calvinsetmessages: + msg65804
2005-03-08 09:40:18calvincreate