Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locale.getdefaultlocale doesnt handle all locales gracefully #39317

Closed
doko42 opened this issue Sep 27, 2003 · 4 comments
Closed

locale.getdefaultlocale doesnt handle all locales gracefully #39317

doko42 opened this issue Sep 27, 2003 · 4 comments
Labels
extension-modules C modules in the Modules dir

Comments

@doko42
Copy link
Member

doko42 commented Sep 27, 2003

BPO 813449
Nosy @loewis, @birkenfeld, @doko42

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2006-02-20.19:08:43.000>
created_at = <Date 2003-09-27.08:54:36.000>
labels = ['extension-modules']
title = 'locale.getdefaultlocale doesnt handle all locales gracefully'
updated_at = <Date 2006-02-20.19:08:43.000>
user = 'https://github.com/doko42'

bugs.python.org fields:

activity = <Date 2006-02-20.19:08:43.000>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Extension Modules']
creation = <Date 2003-09-27.08:54:36.000>
creator = 'doko'
dependencies = []
files = []
hgrepos = []
issue_num = 813449
keywords = []
message_count = 4.0
messages = ['18402', '18403', '18404', '18405']
nosy_count = 4.0
nosy_names = ['loewis', 'georg.brandl', 'doko', 'jlgijsbers']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue813449'
versions = ['Python 2.3']

@doko42
Copy link
Member Author

doko42 commented Sep 27, 2003

[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...

@doko42 doko42 closed this as completed Sep 27, 2003
@doko42 doko42 added the extension-modules C modules in the Modules dir label Sep 27, 2003
@doko42 doko42 closed this as completed Sep 27, 2003
@doko42 doko42 added the extension-modules C modules in the Modules dir label Sep 27, 2003
@loewis
Copy link
Mannequin

loewis mannequin commented Oct 4, 2003

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.

@jlgijsbers
Copy link
Mannequin

jlgijsbers mannequin commented Nov 8, 2004

Logged In: YES
user_id=469548

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

@birkenfeld
Copy link
Member

Logged In: YES
user_id=849994

Closing as duplicate of bpo-504219.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir
Projects
None yet
Development

No branches or pull requests

2 participants