Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Lib/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
1766. code and encoding can be None in case the values cannot
be determined.

On Windows, raise a `WindowsError` if retrieving the locale fails.

"""

return _getdefaultlocale(envvars)
Expand All @@ -569,12 +571,11 @@ def _getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
code, encoding = _locale._getdefaultlocale()
except (ImportError, AttributeError):
pass
except OSError as e:
if sys.platform == "win32" and isinstance(e, WindowsError):
Comment thread
mokurin000 marked this conversation as resolved.
Outdated
raise
else:
# make sure the code/encoding values are valid
if sys.platform == "win32" and code and code[:2] == "0x":
# map windows language identifier to language name
code = windows_locale.get(int(code, 0))
# ...add other platform-specific processing here, if
# add other platform-specific processing here, if
# necessary...
return code, encoding

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed Windows 95 compatibility for :func:`locale.getdefaultlocale`.
15 changes: 2 additions & 13 deletions Modules/_localemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,20 +555,9 @@ _locale__getdefaultlocale_impl(PyObject *module)
return Py_BuildValue("ss", locale, encoding);
}

/* If we end up here, this windows version didn't know about
ISO639/ISO3166 names (it's probably Windows 95). Return the
Windows language identifier instead (a hexadecimal number) */

locale[0] = '0';
locale[1] = 'x';
if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE,
locale+2, sizeof(locale)-2)) {
return Py_BuildValue("ss", locale, encoding);
}

/* cannot determine the language code (very unlikely) */
Py_INCREF(Py_None);
return Py_BuildValue("Os", Py_None, encoding);
/* if any of GetLocaleInfoA above failed */
return PyErr_SetFromWindowsErr(0);
Comment thread
mokurin000 marked this conversation as resolved.
Outdated
}
#endif

Expand Down
Loading