diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 8643da0540f37b..f307a5da457fd1 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -23,6 +23,9 @@ from unittest import mock from copy import copy +if sys.platform == 'win32': + import locale + # These tests are not particularly useful if Python was invoked with -S. # If you add tests that are useful under -S, this skip should be moved # to the class level. @@ -534,11 +537,20 @@ def test_startup_imports(self): if sys.platform != 'darwin': # http://bugs.python.org/issue19209 self.assertNotIn('copyreg', modules, stderr) - # http://bugs.python.org/issue19218> - collection_mods = {'_collections', 'collections', 'functools', - 'heapq', 'itertools', 'keyword', 'operator', - 'reprlib', 'types', 'weakref' - }.difference(sys.builtin_module_names) + if sys.platform == 'win32' and locale.getpreferredencoding() == 'cp65001': + # if the default ansi codepage on Windows is 65001 (UTF-8) + # cp65001.py is loaded but not in the set of frozen modules + collection_mods = {'_collections', 'itertools', 'types', + 'weakref' + }.difference(sys.builtin_module_names) + else: + # http://bugs.python.org/issue19218> + # if the default ansi codepage on Windows is 1252 (Western European) + # cp1252.py is loaded from frozen.c + collection_mods = {'_collections', 'collections', 'functools', + 'heapq', 'itertools', 'keyword', 'operator', + 'reprlib', 'types', 'weakref' + }.difference(sys.builtin_module_names) self.assertFalse(modules.intersection(collection_mods), stderr) def test_startup_interactivehook(self): diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 3df17ac4fb68f5..2caba3b37bcdcd 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1619,9 +1619,28 @@ init_timezone(PyObject *m) And I'm lazy and hate C so nyer. */ #ifdef HAVE_DECL_TZNAME +#ifdef MS_WINDOWS +# include + // https://bugs.python.org/issue36778 + // workaround bug in UCRT + // strptime fails if the current locale is a Unicode locale + int cp = GetACP(); + char* save_locale = NULL; + if (cp == CP_UTF8 || cp == CP_UTF7) + { + save_locale = setlocale(LC_CTYPE, NULL); + setlocale(LC_CTYPE, "C"); + } +#endif PyObject *otz0, *otz1; tzset(); PyModule_AddIntConstant(m, "timezone", _Py_timezone); +#ifdef MS_WINDOWS + if (cp == CP_UTF8 || cp == CP_UTF7) + { + setlocale(LC_CTYPE, save_locale); + } +#endif #ifdef HAVE_ALTZONE PyModule_AddIntConstant(m, "altzone", altzone); #else