[Python-checkins] python/nondist/sandbox/datetime doc.txt,1.38,1.39 obj_date.c,1.44,1.45 obj_datetime.c,1.43,1.44

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月09日 15:16:41 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv17929
Modified Files:
	doc.txt obj_date.c obj_datetime.c 
Log Message:
The METH_CLASS bug has been fixed in Python CVS (thanks to Thomas Heller
and Guido!, so fiddled the code here to work again. It's an improvement
this way.
Index: doc.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/doc.txt,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** doc.txt	9 Dec 2002 19:50:33 -0000	1.38
--- doc.txt	9 Dec 2002 23:16:38 -0000	1.39
***************
*** 5,12 ****
 - timetz needs a C implementation.
 
- - The METH_CLASS bug affects about a dozen functions here. They'll need
- to be recoded in minor ways when the bug gets fixed. The bug needs to
- be fixed.
- 
 - Subclass relationships. Currently datetime is a subclass of date.
 I like this in practice, and think it's theoretically sound too.
--- 5,8 ----
***************
*** 23,26 ****
--- 19,27 ----
 CLOSED
 ======
+ - The METH_CLASS bug affects about a dozen functions here. They'll need
+ to be recoded in minor ways when the bug gets fixed. The bug needs to
+ be fixed.
+ Done.
+ 
 - What should str() do? It generally acts like a synonym for isoformat()
 now. But
Index: obj_date.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_date.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** obj_date.c	9 Dec 2002 19:50:33 -0000	1.44
--- obj_date.c	9 Dec 2002 23:16:39 -0000	1.45
***************
*** 91,95 ****
 */
 static PyObject *
! date_today(PyObject *self, PyObject *cls)
 {
 	PyObject *time;
--- 91,95 ----
 */
 static PyObject *
! date_today(PyObject *cls, PyObject *dummy)
 {
 	PyObject *time;
***************
*** 113,123 ****
 /* Return new date from given timestamp (Python timestamp -- a double). */
 static PyObject *
! date_fromtimestamp(PyObject *self, PyObject *args)
 {
- 	PyObject *cls;
 	double timestamp;
 	PyObject *result = NULL;
 
! 	if (PyArg_ParseTuple(args, "Od:fromtimestamp", &cls, &timestamp))
 		result = date_local_from_time_t(cls, (time_t)timestamp);
 	return result;
--- 113,122 ----
 /* Return new date from given timestamp (Python timestamp -- a double). */
 static PyObject *
! date_fromtimestamp(PyObject *cls, PyObject *args)
 {
 	double timestamp;
 	PyObject *result = NULL;
 
! 	if (PyArg_ParseTuple(args, "d:fromtimestamp", &timestamp))
 		result = date_local_from_time_t(cls, (time_t)timestamp);
 	return result;
***************
*** 128,139 ****
 */
 static PyObject *
! date_fromordinal(PyObject *self, PyObject *args)
 {
 	PyObject *result = NULL;
- 	PyObject *cls;
 	long ordinal;
 
 
! 	if (PyArg_ParseTuple(args, "Ol:formordinal", &cls, &ordinal)) {
 		long year;
 		long month;
--- 127,137 ----
 */
 static PyObject *
! date_fromordinal(PyObject *cls, PyObject *args)
 {
 	PyObject *result = NULL;
 	long ordinal;
 
 
! 	if (PyArg_ParseTuple(args, "l:formordinal", &ordinal)) {
 		long year;
 		long month;
***************
*** 478,486 ****
 static PyMethodDef date_methods[] = {
 	/* Class methods: */
- 	/* XXX METH_CLASS is implemented incorrectly:
- 	 * XXX http://www.python.org/sf/548651
- 	 * XXX The signatures of these methods will need to change (for
- 	 * XXX the better) when that's fixed.
- 	 */
 	{"fromtimestamp", (PyCFunction)date_fromtimestamp, METH_VARARGS |
 							 METH_CLASS,
--- 476,479 ----
***************
*** 493,497 ****
 	 	 "ordinal.")},
 
! 	{"today", (PyCFunction)date_today,	METH_O | METH_CLASS,
 	 PyDoc_STR("Current date or datetime: same as "
 	 	 "self.__class__.fromtimestamp(time.time()).")},
--- 486,490 ----
 	 	 "ordinal.")},
 
! 	{"today", (PyCFunction)date_today, METH_NOARGS | METH_CLASS,
 	 PyDoc_STR("Current date or datetime: same as "
 	 	 "self.__class__.fromtimestamp(time.time()).")},
Index: obj_datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetime.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** obj_datetime.c	9 Dec 2002 19:50:33 -0000	1.43
--- obj_datetime.c	9 Dec 2002 23:16:39 -0000	1.44
***************
*** 188,198 ****
 /* Return new local datetime from timestamp (Python timestamp -- a double). */
 static PyObject *
! datetime_fromtimestamp(PyObject *self, PyObject *args)
 {
- 	PyObject *cls;
 	double timestamp;
 	PyObject *result = NULL;
 
! 	if (PyArg_ParseTuple(args, "Od:fromtimestamp", &cls, &timestamp))
 		result = datetime_from_timestamp(cls, localtime, timestamp);
 	return result;
--- 188,197 ----
 /* Return new local datetime from timestamp (Python timestamp -- a double). */
 static PyObject *
! datetime_fromtimestamp(PyObject *cls, PyObject *args)
 {
 	double timestamp;
 	PyObject *result = NULL;
 
! 	if (PyArg_ParseTuple(args, "d:fromtimestamp", &timestamp))
 		result = datetime_from_timestamp(cls, localtime, timestamp);
 	return result;
***************
*** 201,211 ****
 /* Return new UTC datetime from timestamp (Python timestamp -- a double). */
 static PyObject *
! datetime_utcfromtimestamp(PyObject *self, PyObject *args)
 {
- 	PyObject *cls;
 	double timestamp;
 	PyObject *result = NULL;
 
! 	if (PyArg_ParseTuple(args, "Od:utcfromtimestamp", &cls, &timestamp))
 		result = datetime_from_timestamp(cls, gmtime, timestamp);
 	return result;
--- 200,209 ----
 /* Return new UTC datetime from timestamp (Python timestamp -- a double). */
 static PyObject *
! datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
 {
 	double timestamp;
 	PyObject *result = NULL;
 
! 	if (PyArg_ParseTuple(args, "d:utcfromtimestamp", &timestamp))
 		result = datetime_from_timestamp(cls, gmtime, timestamp);
 	return result;
***************
*** 216,220 ****
 */
 static PyObject *
! datetime_now(PyObject *self, PyObject *cls)
 {
 	return datetime_best_possible(cls, localtime);
--- 214,218 ----
 */
 static PyObject *
! datetime_now(PyObject *cls, PyObject *dummy)
 {
 	return datetime_best_possible(cls, localtime);
***************
*** 225,229 ****
 */
 static PyObject *
! datetime_utcnow(PyObject *self, PyObject *cls)
 {
 	return datetime_best_possible(cls, gmtime);
--- 223,227 ----
 */
 static PyObject *
! datetime_utcnow(PyObject *cls, PyObject *dummy)
 {
 	return datetime_best_possible(cls, gmtime);
***************
*** 232,250 ****
 /* Return new datetime from date and time arguments. */
 static PyObject *
! datetime_combine(PyObject *self, PyObject *args, PyObject *kw)
 {
! 	/* XXX Ack! The METH_CLASS bug (see below) makes us pass a
! 	 * XXX keyword name for the class argument. Rather than try to
! 	 * XXX work around it, we pass an "impossible" class name. This
! 	 * XXX function will need some reworking when the bug is fixed.
! 	 */
! 	static char *keywords[] = {" cls ", "date", "time", NULL};
! 	PyObject *cls;
 	PyObject *date;
 	PyObject *time;
 	PyObject *result = NULL;
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "OO!O!:combine", keywords,
! 					&cls,
 					&PyDateTime_DateType, &date,
 					&PyDateTime_TimeType, &time))
--- 230,241 ----
 /* Return new datetime from date and time arguments. */
 static PyObject *
! datetime_combine(PyObject *cls, PyObject *args, PyObject *kw)
 {
! 	static char *keywords[] = {"date", "time", NULL};
 	PyObject *date;
 	PyObject *time;
 	PyObject *result = NULL;
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "O!O!:combine", keywords,
 					&PyDateTime_DateType, &date,
 					&PyDateTime_TimeType, &time))
***************
*** 601,615 ****
 static PyMethodDef datetime_methods[] = {
 	/* Class methods: */
- 	/* XXX METH_CLASS is implemented incorrectly:
- 	 * XXX http://www.python.org/sf/548651
- 	 * XXX The signatures of these methods will need to change (for
- 	 * XXX the better) when that's fixed.
- 	 */
 	{"now", (PyCFunction)datetime_now,
! 	 METH_O | METH_CLASS,
 	 PyDoc_STR("Return a new datetime representing local day and time.")},
 
 	{"utcnow", (PyCFunction)datetime_utcnow,
! 	 METH_O | METH_CLASS,
 	 PyDoc_STR("Return a new datetime representing UTC day and time.")},
 
--- 592,601 ----
 static PyMethodDef datetime_methods[] = {
 	/* Class methods: */
 	{"now", (PyCFunction)datetime_now,
! 	 METH_NOARGS | METH_CLASS,
 	 PyDoc_STR("Return a new datetime representing local day and time.")},
 
 	{"utcnow", (PyCFunction)datetime_utcnow,
! 	 METH_NOARGS | METH_CLASS,
 	 PyDoc_STR("Return a new datetime representing UTC day and time.")},
 
***************
*** 625,629 ****
 
 	{"combine", (PyCFunction)datetime_combine,
! 	 METH_KEYWORDS | METH_CLASS,
 	 PyDoc_STR("date, time -> datetime with same date and time fields")},
 
--- 611,615 ----
 
 	{"combine", (PyCFunction)datetime_combine,
! 	 METH_VARARGS | METH_KEYWORDS | METH_CLASS,
 	 PyDoc_STR("date, time -> datetime with same date and time fields")},
 

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