Make temporary change of using _strptime for time.strptime permanent.
Flesh out docs to better explain time.strptime (closes bug #697990).
This commit is contained in:
parent
592c4cc460
commit
20def8bb19
|
@ -288,14 +288,17 @@ value is a \class{struct_time} as returned by \function{gmtime()} or
|
|||
\function{localtime()}. The \var{format} parameter uses the same
|
||||
directives as those used by \function{strftime()}; it defaults to
|
||||
\code{"\%a \%b \%d \%H:\%M:\%S \%Y"} which matches the formatting
|
||||
returned by \function{ctime()}. The same platform caveats apply; see
|
||||
the local \UNIX{} documentation for restrictions or additional
|
||||
supported directives. If \var{string} cannot be parsed according to
|
||||
\var{format}, \exception{ValueError} is raised. Values which are not
|
||||
provided as part of the input string are filled in with default
|
||||
values; the specific values are platform-dependent as the XPG standard
|
||||
does not provide sufficient information to constrain the result.
|
||||
\end{funcdesc}
|
||||
returned by \function{ctime()}. If \var{string} cannot be parsed
|
||||
according to \var{format}, \exception{ValueError} is raised. If the
|
||||
string to be parsed has excess data after parsing,
|
||||
\exception{ValueError} is raised. The default values used to fill in
|
||||
any missing data is \code{(1900, 1, 1, 0, 0, 0, 0, 1, -1)} .
|
||||
|
||||
Support for the \code{\%Z} directive is based on the values contained in
|
||||
\code{tzname} and whether \code{daylight} is true. Because of this
|
||||
it is platform-specifc sans recognition for UTC and GMT which are
|
||||
always known (and are considered to be non-daylight savings
|
||||
timezones).
|
||||
|
||||
\begin{datadesc}{struct_time}
|
||||
The type of the time value sequence returned by \function{gmtime()},
|
||||
|
|
|
@ -18,6 +18,9 @@ Extension modules
|
|||
|
||||
- SSL no longer crashes the interpreter when the remote side disconnects.
|
||||
|
||||
- time.strptime now exclusively uses the Python implementation
|
||||
contained within the _strptime module.
|
||||
|
||||
Library
|
||||
-------
|
||||
|
||||
|
|
|
@ -416,44 +416,6 @@ See the library reference manual for formatting codes. When the time tuple\n\
|
|||
is not present, current time as returned by localtime() is used.");
|
||||
#endif /* HAVE_STRFTIME */
|
||||
|
||||
#undef HAVE_STRPTIME
|
||||
#ifdef HAVE_STRPTIME
|
||||
|
||||
#if 0
|
||||
/* Enable this if it's not declared in <time.h> */
|
||||
extern char *strptime(const char *, const char *, struct tm *);
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
time_strptime(PyObject *self, PyObject *args)
|
||||
{
|
||||
struct tm tm;
|
||||
char *fmt = "%a %b %d %H:%M:%S %Y";
|
||||
char *buf;
|
||||
char *s;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|s:strptime", &buf, &fmt))
|
||||
return NULL;
|
||||
memset((void *) &tm, '\0', sizeof(tm));
|
||||
s = strptime(buf, fmt, &tm);
|
||||
if (s == NULL) {
|
||||
PyErr_SetString(PyExc_ValueError, "format mismatch");
|
||||
return NULL;
|
||||
}
|
||||
while (*s && isspace(Py_CHARMASK(*s)))
|
||||
s++;
|
||||
if (*s) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"unconverted data remains: '%.400s'", s);
|
||||
return NULL;
|
||||
}
|
||||
return tmtotuple(&tm);
|
||||
}
|
||||
|
||||
#endif /* HAVE_STRPTIME */
|
||||
|
||||
#ifndef HAVE_STRPTIME
|
||||
|
||||
static PyObject *
|
||||
time_strptime(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
@ -467,10 +429,8 @@ time_strptime(PyObject *self, PyObject *args)
|
|||
return strptime_result;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRPTIME */
|
||||
|
||||
PyDoc_STRVAR(strptime_doc,
|
||||
"strptime(string, format) -> tuple\n\
|
||||
"strptime(string, format) -> struct_time\n\
|
||||
\n\
|
||||
Parse a string to a time tuple according to a format specification.\n\
|
||||
See the library reference manual for formatting codes (same as strftime()).");
|
||||
|
|
Loading…
Reference in New Issue