[Python-checkins] cpython (3.2): Issue #5905: time.strftime() is now using the locale encoding, instead of

victor.stinner python-checkins at python.org
Fri Dec 9 20:19:11 CET 2011


http://hg.python.org/cpython/rev/8620e6901e58
changeset: 73904:8620e6901e58
branch: 3.2
parent: 73894:8ed2c4d4df62
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Fri Dec 09 20:19:24 2011 +0100
summary:
 Issue #5905: time.strftime() is now using the locale encoding, instead of
UTF-8, if the wcsftime() function is not available.
files:
 Misc/NEWS | 3 +++
 Modules/timemodule.c | 13 ++++---------
 2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -90,6 +90,9 @@
 Library
 -------
 
+- Issue #5905: time.strftime() is now using the locale encoding, instead of
+ UTF-8, if the wcsftime() function is not available.
+
 - Issue #8641: Update IDLE 3 syntax coloring to recognize b".." and not u"..".
 Patch by Tal Einat.
 
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -3,8 +3,6 @@
 #include "Python.h"
 #include "_time.h"
 
-#define TZNAME_ENCODING "utf-8"
-
 #include <ctype.h>
 
 #ifdef HAVE_SYS_TYPES_H
@@ -48,8 +46,6 @@
 #if defined(MS_WINDOWS) && !defined(__BORLANDC__)
 /* Win32 has better clock replacement; we have our own version below. */
 #undef HAVE_CLOCK
-#undef TZNAME_ENCODING
-#define TZNAME_ENCODING "mbcs"
 #endif /* MS_WINDOWS && !defined(__BORLANDC__) */
 
 #if defined(PYOS_OS2)
@@ -502,7 +498,7 @@
 fmt = format;
 #else
 /* Convert the unicode string to an ascii one */
- format = PyUnicode_AsEncodedString(format_arg, TZNAME_ENCODING, NULL);
+ format = PyUnicode_EncodeFSDefault(format_arg);
 if (format == NULL)
 return NULL;
 fmt = PyBytes_AS_STRING(format);
@@ -546,8 +542,7 @@
 #ifdef HAVE_WCSFTIME
 ret = PyUnicode_FromWideChar(outbuf, buflen);
 #else
- ret = PyUnicode_Decode(outbuf, buflen,
- TZNAME_ENCODING, NULL);
+ ret = PyUnicode_DecodeFSDefaultAndSize(outbuf, buflen);
 #endif
 PyMem_Free(outbuf);
 break;
@@ -789,8 +784,8 @@
 #endif /* PYOS_OS2 */
 #endif
 PyModule_AddIntConstant(m, "daylight", daylight);
- otz0 = PyUnicode_Decode(tzname[0], strlen(tzname[0]), TZNAME_ENCODING, NULL);
- otz1 = PyUnicode_Decode(tzname[1], strlen(tzname[1]), TZNAME_ENCODING, NULL);
+ otz0 = PyUnicode_DecodeFSDefaultAndSize(tzname[0], strlen(tzname[0]));
+ otz1 = PyUnicode_DecodeFSDefaultAndSize(tzname[1], strlen(tzname[1]));
 PyModule_AddObject(m, "tzname", Py_BuildValue("(NN)", otz0, otz1));
 #else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
 #ifdef HAVE_STRUCT_TM_TM_ZONE
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /