classification
Title: _parse_localename fail to parse 'en_IL'
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, eryksun, hodai goldman, lemburg, mangrisano
Priority: normal Keywords: patch

Created on 2019-06-07 16:33 by hodai goldman, last changed 2019-06-13 03:46 by eryksun.

Pull Requests
URL Status Linked Edit
PR 14027 open hodai goldman, 2019-06-12 21:09
Messages (5)
msg344966 - (view) Author: hodai goldman (hodai goldman) * Date: 2019-06-07 16:33
_parse_localename fail to parse 'US_IL':

Traceback (most recent call last):
  File "/usr/bin/flowblade", line 78, in <module>
    app.main(modules_path)
  File "/usr/share/flowblade/Flowblade/app.py", line 194, in main
    translations.init_languages()
  File "/usr/share/flowblade/Flowblade/translations.py", line 39, in init_languages
    lc, encoding = locale.getdefaultlocale()
  File "/usr/lib/python2.7/locale.py", line 545, in getdefaultlocale
    return _parse_localename(localename)
  File "/usr/lib/python2.7/locale.py", line 477, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: en_IL


need to add another check for '_' separator, code:

    if '.' in code:
        return tuple(code.split('.')[:2])
msg344967 - (view) Author: Michele Angrisano (mangrisano) * Date: 2019-06-07 16:44
Hi Hodai, thank you for the report.
Would you be interested to propose a Pull Request for this issue?

You can read the devguide for more informations.

Thank you. :)
msg344968 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-06-07 16:45
How come your locale doesn't have encoding associated with it? The bit you're looking at is not really relevant, though.
msg345075 - (view) Author: hodai goldman (hodai goldman) * Date: 2019-06-09 08:21
hi Michele,
Yes i wold propose a Pull Request.
SilentGhost: I don't know.
msg345454 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-06-13 03:46
Windows prefers locale names based on RFC 4646 language tags, which use a hyphen instead of an underscore (e.g. "en-UK"). This name format doesn't include an encoding. The C runtime (not the Windows API) makes one exception to support ".utf8" and ".utf-8" (e.g. "en-UK.utf8"). If UTF-8 is not specified, setlocale implicitly uses the ANSI codepage of the given locale (which is not to be confused with the ANSI codepage of the system locale).

As noted in this issue, _parse_localename currently fails if there's no encoding. hodai's PR 14027 addresses this case by looking for underscore in the name. In Windows, it should also look for hyphen. Also, instead of using None for the encoding in this case, in Windows we can look it up via ___lc_codepage_func [1]. This could be added as _locale._lc_codepage_func.

[1] https://docs.microsoft.com/en-us/cpp/c-runtime-library/lc-codepage-func?view=vs-2019
History
Date User Action Args
2019-06-13 03:46:02eryksunsetnosy: + eryksun
messages: + msg345454
2019-06-12 21:09:47hodai goldmansetkeywords: + patch
stage: patch review
pull_requests: + pull_request13891
2019-06-09 08:21:47hodai goldmansetmessages: + msg345075
2019-06-07 16:45:09SilentGhostsettitle: _parse_localename fail to parse 'US_IL' -> _parse_localename fail to parse 'en_IL'
nosy: + SilentGhost

messages: + msg344968

components: + Library (Lib)
type: crash -> behavior
2019-06-07 16:44:00mangrisanosetnosy: + mangrisano, lemburg
messages: + msg344967
2019-06-07 16:33:21hodai goldmancreate