Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db62389

Browse files
author
Victor Stinner
committed
(Merge 3.2) Issue #5905: time.strftime() is now using the locale encoding,
instead of UTF-8, if the wcsftime() function is not available.
2 parents 7f54f75 + 720f34a commit db62389

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ Core and Builtins
406406
Library
407407
-------
408408

409+
- Issue #5905: time.strftime() is now using the locale encoding, instead of
410+
UTF-8, if the wcsftime() function is not available.
411+
409412
- Issue #8641: Update IDLE 3 syntax coloring to recognize b".." and not u"..".
410413
Patch by Tal Einat.
411414

Modules/timemodule.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@
3030
#endif /* MS_WINDOWS */
3131
#endif /* !__WATCOMC__ || __QNX__ */
3232

33-
#if defined(HAVE_MBCS)
34-
# define TZNAME_ENCODING "mbcs"
35-
#else
36-
# define TZNAME_ENCODING "utf-8"
37-
#endif
38-
3933
#if defined(PYOS_OS2)
4034
#define INCL_DOS
4135
#define INCL_ERRORS
@@ -492,7 +486,7 @@ time_strftime(PyObject *self, PyObject *args)
492486
fmt = format;
493487
#else
494488
/* Convert the unicode string to an ascii one */
495-
format = PyUnicode_AsEncodedString(format_arg, TZNAME_ENCODING, NULL);
489+
format = PyUnicode_EncodeFSDefault(format_arg);
496490
if (format == NULL)
497491
return NULL;
498492
fmt = PyBytes_AS_STRING(format);
@@ -536,8 +530,7 @@ time_strftime(PyObject *self, PyObject *args)
536530
#ifdef HAVE_WCSFTIME
537531
ret = PyUnicode_FromWideChar(outbuf, buflen);
538532
#else
539-
ret = PyUnicode_Decode(outbuf, buflen,
540-
TZNAME_ENCODING, NULL);
533+
ret = PyUnicode_DecodeFSDefaultAndSize(outbuf, buflen);
541534
#endif
542535
PyMem_Free(outbuf);
543536
break;
@@ -769,8 +762,8 @@ PyInit_timezone(PyObject *m) {
769762
#endif /* PYOS_OS2 */
770763
#endif
771764
PyModule_AddIntConstant(m, "daylight", daylight);
772-
otz0 = PyUnicode_Decode(tzname[0], strlen(tzname[0]), TZNAME_ENCODING, NULL);
773-
otz1 = PyUnicode_Decode(tzname[1], strlen(tzname[1]), TZNAME_ENCODING, NULL);
765+
otz0 = PyUnicode_DecodeFSDefaultAndSize(tzname[0], strlen(tzname[0]));
766+
otz1 = PyUnicode_DecodeFSDefaultAndSize(tzname[1], strlen(tzname[1]));
774767
PyModule_AddObject(m, "tzname", Py_BuildValue("(NN)", otz0, otz1));
775768
#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
776769
#ifdef HAVE_STRUCT_TM_TM_ZONE

0 commit comments

Comments
 (0)