[ python-Bugs-813449 ] locale.getdefaultlocale doesnt handle all locales gracefully

SourceForge.net noreply at sourceforge.net
Mon Feb 20 20:08:43 CET 2006


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

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Extension Modules
Group: Python 2.3
>Status: Closed
>Resolution: Duplicate
Priority: 5
Submitted By: Matthias Klose (doko)
Assigned to: Nobody/Anonymous (nobody)
Summary: locale.getdefaultlocale doesnt handle all locales gracefully

Initial Comment:
[forwarded from http://bugs.debian.org/185776]

$ LC_ALL=en_ZA python
Python 2.3.1 (#2, Sep 24 2003, 11:39:14) 
[GCC 3.3.2 20030908 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import locale
>>> locale.getdefaultlocale()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/locale.py", line 346, in
getdefaultlocale
    return _parse_localename(localename)
  File "/usr/lib/python2.3/locale.py", line 280, in
_parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: en_ZA

Note that locale.getlocale correctly returns (None, None)

locale.getdefaultlocale() calls _parse_localename,
which throws a ValueError if normalize e.g. does not
return an encoding.

If this behaviour in python is "as it should be",
locale.getdefaultlocale should document it as such, to
make it clear to apps using getdefaultlocale that they
*must indeed* handle such an exception gracefully. (In
this case, it could probably be a "normal" bug, then
the "important" bug belongs with apt-listchanges.)

The problem might be (depending on "specifications")
either getlocale returning ValueError in the "unknown"
case, or it could be because locale_alias does not
contain an entry for en_ZA...


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

>Comment By: Georg Brandl (gbrandl)
Date: 2006-02-20 19:08

Message:
Logged In: YES 
user_id=849994

Closing as duplicate of #504219.

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

Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2004-11-08 18:59

Message:
Logged In: YES 
user_id=469548

http://python.org/sf/504219 seems to be the same bug.

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

Comment By: Martin v. Löwis (loewis)
Date: 2003-10-04 08:06

Message:
Logged In: YES 
user_id=21627

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.

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

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


More information about the Python-bugs-list mailing list