-
-
Notifications
You must be signed in to change notification settings - Fork 650
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
Use locale.getpreferredencoding rather than locale.getlocale as latter can fail if Python doesn't know the locale #11384
Conversation
…r can fail if Python doesn't know the locale Fixes nvaccess#11155
I'm not sure that locale.getpreferredencoding actually honours the locale NVDA is set to, rather it only honours the locale the Windows user account is configured for. Perhaps we can catch the exception from locale.getlocale and fall back to locale.getpreferredencoding? |
I actually think this pr is right, and @michaelDCurran's concern doesn't apply here.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this pr doesn't fix the issue that locale.getlocale fails when NVDA is set to Aragonese. I think that's still a thing that should be addressed in a follow up. May be we should file this against Python or something.
source/textUtils.py
Outdated
@@ -18,6 +17,8 @@ | |||
from logHandler import log | |||
|
|||
WCHAR_ENCODING = "utf_16_le" | |||
USERANSICODEPAGE = locale.getpreferredencoding() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the style used for constants here:
USERANSICODEPAGE = locale.getpreferredencoding() | |
USER_ANSI_CODE_PAGE = locale.getpreferredencoding() |
Or rather
USERANSICODEPAGE = locale.getpreferredencoding() | |
SYSTEM_PREFERRED_ENCODING = locale.getpreferredencoding() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed it to USER_ANSI_CODE_PAGE
because it can be set per Windows user account and is not global to the system.
Note: potentially marking this for further investigation once we move to Python 3.8 and later. Thanks.
|
@LeonarddeR wrote:
I don't think there is much we can do about that - an as a locale code is simply not known to Windows that's why Python fails. |
@LeonarddeR All your commends are now addressed. |
If the aim is to get the codepage of the system, then I am happy with
this pr.
|
Link to issue number:
Fixes #11155
Summary of the issue:
Whenever we needed to access the ANSI Windows code page we were using
locale.getlocale
. This was problematic for two reasons:Description of how this pull request fixes the issue:
In places where
locale.getlocale
was formerly used I've switched tolocale.getpreferredencoding
as this method returns ANSI code page of the current Windows user.Testing performed:
Switched NVDA language to Aragonese, navigated in Notepad, run dialog and cmd - previously navigation was not possible due to the fact that AN was not recognized as a valid locale by Python.
Known issues with pull request:
locale.getlocale
in textUtils module to deal with offset differences between Python 3 strings and Windows wide character strings with surrogate characters #9545 so it is possible that it breaks something which I haven't considered.Change log entry:
Bug fixes
It is once again possible to navigate in various controls when NVDA is set to Aragonese.