[Python-bugs-list] [ python-Bugs-797447 ] locale.setlocale(locale.LC_ALL, "de") raises exception

SourceForge.net noreply at sourceforge.net
Mon Sep 1 02:02:05 EDT 2003


Bugs item #797447, was opened at 2003-08-30 06:16
Message generated for change (Comment added) made by anadelonbrin
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=797447&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Peter Otten (potten)
Assigned to: Martin v. Löwis (loewis)
Summary: locale.setlocale(locale.LC_ALL, "de") raises exception

Initial Comment:
Python 2.3 (#1, Jul 30 2003, 11:19:43) 
[GCC 3.2] on linux2 
Type "help", "copyright", "credits" or "license" for more 
information. 
>>> import locale as lo 
>>> lo.setlocale(lo.LC_ALL, 'de') 
Traceback (most recent call last): 
  File "<stdin>", line 1, in ? 
  File "/usr/local/lib/python2.3/locale.py", line 381, in 
setlocale 
    return _setlocale(category, locale) 
locale.Error: locale setting not supported 
 
The above was taken from the example section of the 
locale module documentation. 
 
But this works: 
 
>>> lo.setlocale(lo.LC_ALL, 'de_DE') 
'de_DE' 
>>> 
 
So the error message should at least be changed to 
"unknown/unsupported locale" and the documentation 
example updated to 'de_DE' instead of 'de'. 
 
However, if there are no side effects, I'd prefer to 
change the locale.setlocale() implementation to always 
normalize() the locale: 
 
def setlocale(category, locale=None): 
    if locale: 
        if type(locale) is not type(""): 
            # convert to string 
            locale = _build_localename(locale) 
        locale = normalize(locale) 
    return _setlocale(category, locale) 
 

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

Comment By: Tony Meyer (anadelonbrin)
Date: 2003-09-01 20:02

Message:
Logged In: YES 
user_id=552329

Just my 2c, but I would agree that a wording change to 
either "unsupported locale setting" or "%s locale setting not 
supported" with the attempted locale would be much clearer.

No opinion on (2) :)

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

Comment By: Peter Otten (potten)
Date: 2003-09-01 09:37

Message:
Logged In: YES 
user_id=703365

(1) I read "locale setting not supported" and understood (not 
being a native speaker) "(any) locale setting not supported", 
whereas "unknown/unsupported locale" would make it clear 
you can set a locale but not the one that was requested. 
 
(2) I would expect setlocale(..., "de") and setlocale(..., 
("de", None)) to either both fail or both succeed, but 
currently only the latter form works; thus the proposed 
change in the code. 
 
I hope this clarifies the issue and you will reconsider. 

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

Comment By: Martin v. Löwis (loewis)
Date: 2003-09-01 05:00

Message:
Logged In: YES 
user_id=21627

I fail to see the bug. "locale setting not supported" is
exactly identical, in its meaning, with "unsupported locale".

Changing the example to de_DE won't help much, either, since
the next system might support "de" but not "de_DE", or it
might support "de_DE.ISO-8859-1" only. Locale names are not
standardized.

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

Comment By: Peter Otten (potten)
Date: 2003-08-30 19:29

Message:
Logged In: YES 
user_id=703365

I forgot to mention that the following also works: 
 
>>> import locale 
>>> locale.setlocale(locale.LC_ALL, ("de", None)) 
'de_DE.ISO8859-1' 
>>> 
 
So the it really seems to be an implementation rather than a 
documentation issue. 

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

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



More information about the Python-bugs-list mailing list