[Python-checkins] python/dist/src/Modules datetimemodule.c,1.9,1.10

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月22日 10:10:24 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv8612/python/Modules
Modified Files:
	datetimemodule.c 
Log Message:
classify_object(): Renamed more meaningfully, to classify_utcoffset().
Also changed logic so that instances of user-defined subclasses of date,
time, and datetime are called OFFSET_NAIVE instead of OFFSET_UNKNOWN.
Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** datetimemodule.c	22 Dec 2002 03:43:39 -0000	1.9
--- datetimemodule.c	22 Dec 2002 18:10:22 -0000	1.10
***************
*** 790,800 ****
 } naivety;
 
! /* Classify a datetime object as to whether it's naive or offset-aware. See
 * the "naivety" typedef for details. If the type is aware, *offset is set
 * to minutes east of UTC (as returned by the tzinfo.utcoffset() method).
! * If the type is offset-naive, *offset is set to 0.
 */
 static naivety
! classify_object(PyObject *op, int *offset)
 {
 	int none;
--- 790,800 ----
 } naivety;
 
! /* Classify an object as to whether it's naive or offset-aware. See
 * the "naivety" typedef for details. If the type is aware, *offset is set
 * to minutes east of UTC (as returned by the tzinfo.utcoffset() method).
! * If the type is offset-naive (or unknown, or error), *offset is set to 0.
 */
 static naivety
! classify_utcoffset(PyObject *op, int *offset)
 {
 	int none;
***************
*** 802,816 ****
 
 	*offset = 0;
! 	if (PyDateTime_CheckExact(op) ||
! 	 PyTime_CheckExact(op) ||
! 	 PyDate_CheckExact(op))
! 		return OFFSET_NAIVE;
! 
! 	tzinfo = get_tzinfo_member(op);	/* NULL means none, not error */
 	if (tzinfo == Py_None)
 		return OFFSET_NAIVE;
! 	if (tzinfo == NULL)
! 		return OFFSET_UNKNOWN;
! 
 	*offset = call_utcoffset(tzinfo, op, &none);
 	if (*offset == -1 && PyErr_Occurred())
--- 802,813 ----
 
 	*offset = 0;
! 	tzinfo = get_tzinfo_member(op);	/* NULL means no tzinfo, not error */
 	if (tzinfo == Py_None)
 		return OFFSET_NAIVE;
! 	if (tzinfo == NULL) {
! 		/* note that a datetime passes the PyDate_Check test */
! 		return (PyTime_Check(op) || PyDate_Check(op)) ?
! 		 OFFSET_NAIVE : OFFSET_UNKNOWN;
! 	}
 	*offset = call_utcoffset(tzinfo, op, &none);
 	if (*offset == -1 && PyErr_Occurred())
***************
*** 3090,3099 ****
 		return NULL;
 	}
! 	n1 = classify_object((PyObject *)self, &offset1);
 	assert(n1 != OFFSET_UNKNOWN);
 	if (n1 == OFFSET_ERROR)
 		return NULL;
 
! 	n2 = classify_object(other, &offset2);
 	assert(n2 != OFFSET_UNKNOWN);
 	if (n2 == OFFSET_ERROR)
--- 3087,3096 ----
 		return NULL;
 	}
! 	n1 = classify_utcoffset((PyObject *)self, &offset1);
 	assert(n1 != OFFSET_UNKNOWN);
 	if (n1 == OFFSET_ERROR)
 		return NULL;
 
! 	n2 = classify_utcoffset(other, &offset2);
 	assert(n2 != OFFSET_UNKNOWN);
 	if (n2 == OFFSET_ERROR)
***************
*** 3151,3155 ****
 		PyObject *temp;
 
! 		n = classify_object((PyObject *)self, &offset);
 		assert(n != OFFSET_UNKNOWN);
 		if (n == OFFSET_ERROR)
--- 3148,3152 ----
 		PyObject *temp;
 
! 		n = classify_utcoffset((PyObject *)self, &offset);
 		assert(n != OFFSET_UNKNOWN);
 		if (n == OFFSET_ERROR)
***************
*** 3558,3567 ****
 		return NULL;
 	}
! 	n1 = classify_object((PyObject *)self, &offset1);
 	assert(n1 != OFFSET_UNKNOWN);
 	if (n1 == OFFSET_ERROR)
 		return NULL;
 
! 	n2 = classify_object(other, &offset2);
 	assert(n2 != OFFSET_UNKNOWN);
 	if (n2 == OFFSET_ERROR)
--- 3555,3564 ----
 		return NULL;
 	}
! 	n1 = classify_utcoffset((PyObject *)self, &offset1);
 	assert(n1 != OFFSET_UNKNOWN);
 	if (n1 == OFFSET_ERROR)
 		return NULL;
 
! 	n2 = classify_utcoffset(other, &offset2);
 	assert(n2 != OFFSET_UNKNOWN);
 	if (n2 == OFFSET_ERROR)
***************
*** 3613,3617 ****
 		PyObject *temp;
 
! 		n = classify_object((PyObject *)self, &offset);
 		assert(n != OFFSET_UNKNOWN);
 		if (n == OFFSET_ERROR)
--- 3610,3614 ----
 		PyObject *temp;
 
! 		n = classify_utcoffset((PyObject *)self, &offset);
 		assert(n != OFFSET_UNKNOWN);
 		if (n == OFFSET_ERROR)
***************
*** 4467,4476 ****
 			PyDateTime_Delta *delta;
 
! 			n1 = classify_object(left, &offset1);
 			assert(n1 != OFFSET_UNKNOWN);
 			if (n1 == OFFSET_ERROR)
 				return NULL;
 
! 			n2 = classify_object(right, &offset2);
 			assert(n2 != OFFSET_UNKNOWN);
 			if (n2 == OFFSET_ERROR)
--- 4464,4473 ----
 			PyDateTime_Delta *delta;
 
! 			n1 = classify_utcoffset(left, &offset1);
 			assert(n1 != OFFSET_UNKNOWN);
 			if (n1 == OFFSET_ERROR)
 				return NULL;
 
! 			n2 = classify_utcoffset(right, &offset2);
 			assert(n2 != OFFSET_UNKNOWN);
 			if (n2 == OFFSET_ERROR)

AltStyle によって変換されたページ (->オリジナル) /