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

Skip to content

Commit 20def8b

Browse files
committed
Make temporary change of using _strptime for time.strptime permanent.
Flesh out docs to better explain time.strptime (closes bug #697990).
1 parent 592c4cc commit 20def8b

3 files changed

Lines changed: 15 additions & 49 deletions

File tree

Doc/lib/libtime.tex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,17 @@ \section{\module{time} ---
288288
\function{localtime()}. The \var{format} parameter uses the same
289289
directives as those used by \function{strftime()}; it defaults to
290290
\code{"\%a \%b \%d \%H:\%M:\%S \%Y"} which matches the formatting
291-
returned by \function{ctime()}. The same platform caveats apply; see
292-
the local \UNIX{} documentation for restrictions or additional
293-
supported directives. If \var{string} cannot be parsed according to
294-
\var{format}, \exception{ValueError} is raised. Values which are not
295-
provided as part of the input string are filled in with default
296-
values; the specific values are platform-dependent as the XPG standard
297-
does not provide sufficient information to constrain the result.
298-
\end{funcdesc}
291+
returned by \function{ctime()}. If \var{string} cannot be parsed
292+
according to \var{format}, \exception{ValueError} is raised. If the
293+
string to be parsed has excess data after parsing,
294+
\exception{ValueError} is raised. The default values used to fill in
295+
any missing data is \code{(1900, 1, 1, 0, 0, 0, 0, 1, -1)} .
296+
297+
Support for the \code{\%Z} directive is based on the values contained in
298+
\code{tzname} and whether \code{daylight} is true. Because of this
299+
it is platform-specifc sans recognition for UTC and GMT which are
300+
always known (and are considered to be non-daylight savings
301+
timezones).
299302

300303
\begin{datadesc}{struct_time}
301304
The type of the time value sequence returned by \function{gmtime()},

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Extension modules
1818

1919
- SSL no longer crashes the interpreter when the remote side disconnects.
2020

21+
- time.strptime now exclusively uses the Python implementation
22+
contained within the _strptime module.
23+
2124
Library
2225
-------
2326

Modules/timemodule.c

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -416,44 +416,6 @@ See the library reference manual for formatting codes. When the time tuple\n\
416416
is not present, current time as returned by localtime() is used.");
417417
#endif /* HAVE_STRFTIME */
418418

419-
#undef HAVE_STRPTIME
420-
#ifdef HAVE_STRPTIME
421-
422-
#if 0
423-
/* Enable this if it's not declared in <time.h> */
424-
extern char *strptime(const char *, const char *, struct tm *);
425-
#endif
426-
427-
static PyObject *
428-
time_strptime(PyObject *self, PyObject *args)
429-
{
430-
struct tm tm;
431-
char *fmt = "%a %b %d %H:%M:%S %Y";
432-
char *buf;
433-
char *s;
434-
435-
if (!PyArg_ParseTuple(args, "s|s:strptime", &buf, &fmt))
436-
return NULL;
437-
memset((void *) &tm, '\0', sizeof(tm));
438-
s = strptime(buf, fmt, &tm);
439-
if (s == NULL) {
440-
PyErr_SetString(PyExc_ValueError, "format mismatch");
441-
return NULL;
442-
}
443-
while (*s && isspace(Py_CHARMASK(*s)))
444-
s++;
445-
if (*s) {
446-
PyErr_Format(PyExc_ValueError,
447-
"unconverted data remains: '%.400s'", s);
448-
return NULL;
449-
}
450-
return tmtotuple(&tm);
451-
}
452-
453-
#endif /* HAVE_STRPTIME */
454-
455-
#ifndef HAVE_STRPTIME
456-
457419
static PyObject *
458420
time_strptime(PyObject *self, PyObject *args)
459421
{
@@ -467,10 +429,8 @@ time_strptime(PyObject *self, PyObject *args)
467429
return strptime_result;
468430
}
469431

470-
#endif /* !HAVE_STRPTIME */
471-
472432
PyDoc_STRVAR(strptime_doc,
473-
"strptime(string, format) -> tuple\n\
433+
"strptime(string, format) -> struct_time\n\
474434
\n\
475435
Parse a string to a time tuple according to a format specification.\n\
476436
See the library reference manual for formatting codes (same as strftime()).");

0 commit comments

Comments
 (0)