mirror of
https://github.com/python/cpython.git
synced 2025-11-11 14:44:57 +00:00
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
3 changed files with 15 additions and 49 deletions
|
|
@ -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
|
\function{localtime()}. The \var{format} parameter uses the same
|
||||||
directives as those used by \function{strftime()}; it defaults to
|
directives as those used by \function{strftime()}; it defaults to
|
||||||
\code{"\%a \%b \%d \%H:\%M:\%S \%Y"} which matches the formatting
|
\code{"\%a \%b \%d \%H:\%M:\%S \%Y"} which matches the formatting
|
||||||
returned by \function{ctime()}. The same platform caveats apply; see
|
returned by \function{ctime()}. If \var{string} cannot be parsed
|
||||||
the local \UNIX{} documentation for restrictions or additional
|
according to \var{format}, \exception{ValueError} is raised. If the
|
||||||
supported directives. If \var{string} cannot be parsed according to
|
string to be parsed has excess data after parsing,
|
||||||
\var{format}, \exception{ValueError} is raised. Values which are not
|
\exception{ValueError} is raised. The default values used to fill in
|
||||||
provided as part of the input string are filled in with default
|
any missing data is \code{(1900, 1, 1, 0, 0, 0, 0, 1, -1)} .
|
||||||
values; the specific values are platform-dependent as the XPG standard
|
|
||||||
does not provide sufficient information to constrain the result.
|
Support for the \code{\%Z} directive is based on the values contained in
|
||||||
\end{funcdesc}
|
\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}
|
\begin{datadesc}{struct_time}
|
||||||
The type of the time value sequence returned by \function{gmtime()},
|
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.
|
- 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
|
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.");
|
is not present, current time as returned by localtime() is used.");
|
||||||
#endif /* HAVE_STRFTIME */
|
#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 *
|
static PyObject *
|
||||||
time_strptime(PyObject *self, PyObject *args)
|
time_strptime(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
|
@ -467,10 +429,8 @@ time_strptime(PyObject *self, PyObject *args)
|
||||||
return strptime_result;
|
return strptime_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !HAVE_STRPTIME */
|
|
||||||
|
|
||||||
PyDoc_STRVAR(strptime_doc,
|
PyDoc_STRVAR(strptime_doc,
|
||||||
"strptime(string, format) -> tuple\n\
|
"strptime(string, format) -> struct_time\n\
|
||||||
\n\
|
\n\
|
||||||
Parse a string to a time tuple according to a format specification.\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()).");
|
See the library reference manual for formatting codes (same as strftime()).");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue