[Python-checkins] python/dist/src/Modules datetimemodule.c,1.27,1.28
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Thu, 02 Jan 2003 13:28:10 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv18654/python/Modules
Modified Files:
datetimemodule.c
Log Message:
The tzinfo methods utcoffset() and dst() must return a timedelta object
(or None) now. In 2.3a1 they could also return an int or long, but that
was an unhelpfully redundant leftover from an earlier version wherein
they couldn't return a timedelta. TOOWTDI.
Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** datetimemodule.c 2 Jan 2003 19:35:54 -0000 1.27
--- datetimemodule.c 2 Jan 2003 21:28:08 -0000 1.28
***************
*** 630,638 ****
* result. tzinfo must be an instance of the tzinfo class. If the method
* returns None, this returns 0 and sets *none to 1. If the method doesn't
! * return a Python int or long or timedelta, TypeError is raised and this
! * returns -1. If it returns an int or long, but is outside the valid
! * range for a UTC minute offset, or it returns a timedelta and the value is
! * out of range or isn't a whole number of minutes, ValueError is raised and
! * this returns -1.
* Else *none is set to 0 and the integer method result is returned.
*/
--- 630,636 ----
* result. tzinfo must be an instance of the tzinfo class. If the method
* returns None, this returns 0 and sets *none to 1. If the method doesn't
! * return None or timedelta, TypeError is raised and this returns -1. If it
! * returnsa timedelta and the value is out of range or isn't a whole number
! * of minutes, ValueError is raised and this returns -1.
* Else *none is set to 0 and the integer method result is returned.
*/
***************
*** 642,646 ****
{
PyObject *u;
! long result = -1; /* Py{Int,Long}_AsLong return long */
assert(tzinfo != NULL);
--- 640,644 ----
{
PyObject *u;
! int result = -1;
assert(tzinfo != NULL);
***************
*** 657,666 ****
*none = 1;
}
- else if (PyInt_Check(u))
- result = PyInt_AS_LONG(u);
-
- else if (PyLong_Check(u))
- result = PyLong_AsLong(u);
-
else if (PyDelta_Check(u)) {
const int days = GET_TD_DAYS(u);
--- 655,658 ----
***************
*** 684,688 ****
else {
PyErr_Format(PyExc_TypeError,
! "tzinfo.%s() must return None, integer or "
"timedelta, not '%s'",
name, u->ob_type->tp_name);
--- 676,680 ----
else {
PyErr_Format(PyExc_TypeError,
! "tzinfo.%s() must return None or "
"timedelta, not '%s'",
name, u->ob_type->tp_name);
***************
*** 697,701 ****
result = -1;
}
! return (int)result;
}
--- 689,693 ----
result = -1;
}
! return result;
}
***************
*** 703,710 ****
* result. tzinfo must be an instance of the tzinfo class. If utcoffset()
* returns None, call_utcoffset returns 0 and sets *none to 1. If uctoffset()
! & doesn't return a Python int or long, TypeError is raised and this
! * returns -1. If utcoffset() returns an int outside the legitimate range
! * for a UTC offset, ValueError is raised and this returns -1. Else
! * *none is set to 0 and the offset is returned.
*/
static int
--- 695,702 ----
* result. tzinfo must be an instance of the tzinfo class. If utcoffset()
* returns None, call_utcoffset returns 0 and sets *none to 1. If uctoffset()
! * doesn't return None or timedelta, TypeError is raised and this returns -1.
! * If utcoffset() returns an invalid timedelta (out of range, or not a whole
! * # of minutes), ValueError is raised and this returns -1. Else *none is
! * set to 0 and the offset is returned (as int # of minutes east of UTC).
*/
static int
***************
*** 746,753 ****
* result. tzinfo must be an instance of the tzinfo class. If dst()
* returns None, call_dst returns 0 and sets *none to 1. If dst()
! & doesn't return a Python int or long, TypeError is raised and this
! * returns -1. If dst() returns an int outside the legitimate range
! * for a UTC offset, ValueError is raised and this returns -1. Else
! * *none is set to 0 and the offset is returned.
*/
static int
--- 738,745 ----
* result. tzinfo must be an instance of the tzinfo class. If dst()
* returns None, call_dst returns 0 and sets *none to 1. If dst()
! & doesn't return None or timedelta, TypeError is raised and this
! * returns -1. If dst() returns an invalid timedelta for for a UTC offset,
! * ValueError is raised and this returns -1. Else *none is set to 0 and
! * the offset is returned (as an int # of minutes east of UTC).
*/
static int