Index: Modules/datetimemodule.c =================================================================== --- Modules/datetimemodule.c (révision 73867) +++ Modules/datetimemodule.c (copie de travail) @@ -1365,18 +1365,20 @@ return buffer + x; } -static void +static char * isoformat_time(PyDateTime_DateTime *dt, char buffer[], int bufflen) { + int x; int us = DATE_GET_MICROSECOND(dt); - PyOS_snprintf(buffer, bufflen, + x = PyOS_snprintf(buffer, bufflen, "%02d:%02d:%02d", /* 8 characters */ DATE_GET_HOUR(dt), DATE_GET_MINUTE(dt), DATE_GET_SECOND(dt)); if (us) - PyOS_snprintf(buffer + 8, bufflen - 8, ".%06d", us); + x += PyOS_snprintf(buffer + 8, bufflen - 8, ".%06d", us); + return buffer + x; } /* --------------------------------------------------------------------------- @@ -4200,8 +4202,8 @@ cp = isoformat_date((PyDateTime_Date *)self, buffer, sizeof(buffer)); assert(cp != NULL); *cp++ = sep; - isoformat_time(self, cp, sizeof(buffer) - (cp - buffer)); - result = PyString_FromString(buffer); + cp = isoformat_time(self, cp, sizeof(buffer) - (cp - buffer)); + result = PyString_FromStringAndSize(buffer, cp - buffer); if (result == NULL || ! HASTZINFO(self)) return result; Index: Lib/test/test_datetime.py =================================================================== --- Lib/test/test_datetime.py (révision 73867) +++ Lib/test/test_datetime.py (copie de travail) @@ -1173,6 +1173,7 @@ self.assertEqual(t.isoformat(), "0002-03-02T04:05:01.000123") self.assertEqual(t.isoformat('T'), "0002-03-02T04:05:01.000123") self.assertEqual(t.isoformat(' '), "0002-03-02 04:05:01.000123") + self.assertEqual(t.isoformat('\x00'), "0002-03-02\x0004:05:01.000123") # str is ISO format with the separator forced to a blank. self.assertEqual(str(t), "0002-03-02 04:05:01.000123")