Commit ec79b1ca authored by Brett Cannon's avatar Brett Cannon

Merged revisions 75020 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r75020 | brett.cannon | 2009-09-22 12:13:27 -0700 (Tue, 22 Sep 2009) | 1 line

  Fix whitespace.
........
parent 73753d35
...@@ -452,9 +452,9 @@ time_strftime(PyObject *self, PyObject *args) ...@@ -452,9 +452,9 @@ time_strftime(PyObject *self, PyObject *args)
} else if (!gettmarg(tup, &buf)) } else if (!gettmarg(tup, &buf))
return NULL; return NULL;
/* Checks added to make sure strftime() does not crash Python by /* Checks added to make sure strftime() does not crash Python by
indexing blindly into some array for a textual representation indexing blindly into some array for a textual representation
by some bad index (fixes bug #897625). by some bad index (fixes bug #897625).
Also support values of zero from Python code for arguments in which Also support values of zero from Python code for arguments in which
that is out of range by forcing that value to the lowest value that that is out of range by forcing that value to the lowest value that
...@@ -475,50 +475,50 @@ time_strftime(PyObject *self, PyObject *args) ...@@ -475,50 +475,50 @@ time_strftime(PyObject *self, PyObject *args)
(1) gettmarg() handles bounds-checking. (1) gettmarg() handles bounds-checking.
(2) Python's acceptable range is one greater than the range in C, (2) Python's acceptable range is one greater than the range in C,
thus need to check against automatic decrement by gettmarg(). thus need to check against automatic decrement by gettmarg().
*/ */
if (buf.tm_mon == -1) if (buf.tm_mon == -1)
buf.tm_mon = 0; buf.tm_mon = 0;
else if (buf.tm_mon < 0 || buf.tm_mon > 11) { else if (buf.tm_mon < 0 || buf.tm_mon > 11) {
PyErr_SetString(PyExc_ValueError, "month out of range"); PyErr_SetString(PyExc_ValueError, "month out of range");
return NULL; return NULL;
} }
if (buf.tm_mday == 0) if (buf.tm_mday == 0)
buf.tm_mday = 1; buf.tm_mday = 1;
else if (buf.tm_mday < 0 || buf.tm_mday > 31) { else if (buf.tm_mday < 0 || buf.tm_mday > 31) {
PyErr_SetString(PyExc_ValueError, "day of month out of range"); PyErr_SetString(PyExc_ValueError, "day of month out of range");
return NULL; return NULL;
} }
if (buf.tm_hour < 0 || buf.tm_hour > 23) { if (buf.tm_hour < 0 || buf.tm_hour > 23) {
PyErr_SetString(PyExc_ValueError, "hour out of range"); PyErr_SetString(PyExc_ValueError, "hour out of range");
return NULL; return NULL;
} }
if (buf.tm_min < 0 || buf.tm_min > 59) { if (buf.tm_min < 0 || buf.tm_min > 59) {
PyErr_SetString(PyExc_ValueError, "minute out of range"); PyErr_SetString(PyExc_ValueError, "minute out of range");
return NULL; return NULL;
} }
if (buf.tm_sec < 0 || buf.tm_sec > 61) { if (buf.tm_sec < 0 || buf.tm_sec > 61) {
PyErr_SetString(PyExc_ValueError, "seconds out of range"); PyErr_SetString(PyExc_ValueError, "seconds out of range");
return NULL; return NULL;
} }
/* tm_wday does not need checking of its upper-bound since taking /* tm_wday does not need checking of its upper-bound since taking
``% 7`` in gettmarg() automatically restricts the range. */ ``% 7`` in gettmarg() automatically restricts the range. */
if (buf.tm_wday < 0) { if (buf.tm_wday < 0) {
PyErr_SetString(PyExc_ValueError, "day of week out of range"); PyErr_SetString(PyExc_ValueError, "day of week out of range");
return NULL; return NULL;
} }
if (buf.tm_yday == -1) if (buf.tm_yday == -1)
buf.tm_yday = 0; buf.tm_yday = 0;
else if (buf.tm_yday < 0 || buf.tm_yday > 365) { else if (buf.tm_yday < 0 || buf.tm_yday > 365) {
PyErr_SetString(PyExc_ValueError, "day of year out of range"); PyErr_SetString(PyExc_ValueError, "day of year out of range");
return NULL; return NULL;
} }
/* Normalize tm_isdst just in case someone foolishly implements %Z /* Normalize tm_isdst just in case someone foolishly implements %Z
based on the assumption that tm_isdst falls within the range of based on the assumption that tm_isdst falls within the range of
[-1, 1] */ [-1, 1] */
if (buf.tm_isdst < -1) if (buf.tm_isdst < -1)
buf.tm_isdst = -1; buf.tm_isdst = -1;
else if (buf.tm_isdst > 1) else if (buf.tm_isdst > 1)
buf.tm_isdst = 1; buf.tm_isdst = 1;
#ifdef HAVE_WCSFTIME #ifdef HAVE_WCSFTIME
tmpfmt = PyBytes_FromStringAndSize(NULL, tmpfmt = PyBytes_FromStringAndSize(NULL,
...@@ -614,14 +614,15 @@ is not present, current time as returned by localtime() is used."); ...@@ -614,14 +614,15 @@ is not present, current time as returned by localtime() is used.");
static PyObject * static PyObject *
time_strptime(PyObject *self, PyObject *args) time_strptime(PyObject *self, PyObject *args)
{ {
PyObject *strptime_module = PyImport_ImportModuleNoBlock("_strptime"); PyObject *strptime_module = PyImport_ImportModuleNoBlock("_strptime");
PyObject *strptime_result; PyObject *strptime_result;
if (!strptime_module) if (!strptime_module)
return NULL; return NULL;
strptime_result = PyObject_CallMethod(strptime_module, "_strptime_time", "O", args); strptime_result = PyObject_CallMethod(strptime_module,
Py_DECREF(strptime_module); "_strptime_time", "O", args);
return strptime_result; Py_DECREF(strptime_module);
return strptime_result;
} }
PyDoc_STRVAR(strptime_doc, PyDoc_STRVAR(strptime_doc,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment