Mailing List Archive

CVS: python/nondist/sandbox/datetime datetime.c,1.9,1.10
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory usw-pr-cvs1:/tmp/cvs-serv29339

Modified Files:
datetime.c
Log Message:
When compiled using Python 2.3, use the new METH_CLASS method flag
instead of using extra code in the module initialization.


Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** datetime.c 26 Mar 2002 22:38:45 -0000 1.9
--- datetime.c 28 Mar 2002 14:07:43 -0000 1.10
***************
*** 361,382 ****
}

- static PyMethodDef datetime_methods[] = {
- {"isocalendar", (PyCFunction)datetime_isocalendar, METH_NOARGS,
- "Return a 3-tuple containing ISO year, week number, and weekday.\n\n"
- "The first ISO week of the year is the (Mon-Sun) week containing the\n"
- "year's first Thursday; everything rest derives from that."},
- {"isoformat", (PyCFunction)datetime_isoformat, METH_VARARGS|METH_KEYWORDS,
- "Return the day of the week represented by the datetime.\n"
- "Monday == 1 ... Sunday == 7"},
- {"isoweekday", (PyCFunction)datetime_isoweekday, METH_NOARGS,
- "Return the day of the week represented by the datetime.\n"
- "Monday == 1 ... Sunday == 7"},
- {"weekday", (PyCFunction)datetime_weekday, METH_NOARGS,
- "Return the day of the week represented by the datetime.\n"
- "Monday == 0 ... Sunday == 6"},
- {NULL}
- };
-
-
static PyObject *
datetime_now(PyObject *self, PyObject *cls)
--- 361,364 ----
***************
*** 401,409 ****
}

static PyMethodDef datetime_now_mdef = {
"now", (PyCFunction)datetime_now, METH_O,
"Return a new datetime that represents the current time."
};
!

static char datetime_doc[] =
--- 383,416 ----
}

+ static PyMethodDef datetime_methods[] = {
+ #if PY_VERSION_HEX >= 0x02030000
+ /* Class methods: */
+ {"now", (PyCFunction)datetime_now, METH_O | METH_CLASS,
+ "Return a new datetime that represents the current time."},
+ #endif
+ /* Instance methods: */
+ {"isocalendar", (PyCFunction)datetime_isocalendar, METH_NOARGS,
+ "Return a 3-tuple containing ISO year, week number, and weekday.\n\n"
+ "The first ISO week of the year is the (Mon-Sun) week containing the\n"
+ "year's first Thursday; everything rest derives from that."},
+ {"isoformat", (PyCFunction)datetime_isoformat, METH_VARARGS|METH_KEYWORDS,
+ "Return the day of the week represented by the datetime.\n"
+ "Monday == 1 ... Sunday == 7"},
+ {"isoweekday", (PyCFunction)datetime_isoweekday, METH_NOARGS,
+ "Return the day of the week represented by the datetime.\n"
+ "Monday == 1 ... Sunday == 7"},
+ {"weekday", (PyCFunction)datetime_weekday, METH_NOARGS,
+ "Return the day of the week represented by the datetime.\n"
+ "Monday == 0 ... Sunday == 6"},
+ {NULL}
+ };
+
+
+ #if PY_VERSION_HEX < 0x02030000
static PyMethodDef datetime_now_mdef = {
"now", (PyCFunction)datetime_now, METH_O,
"Return a new datetime that represents the current time."
};
! #endif

static char datetime_doc[] =
***************
*** 466,470 ****
{
PyObject *m;
! PyObject *d, *dt, *tmp;
int err;

--- 473,477 ----
{
PyObject *m;
! PyObject *d, *dt;
int err;

***************
*** 484,498 ****
Py_DECREF(dt);

! dt = PyCFunction_New(&datetime_now_mdef, NULL);
! if (dt == NULL)
! return;
! tmp = PyClassMethod_New(dt);
! Py_DECREF(dt);
! if (tmp == NULL)
! return;
! err = PyDict_SetItemString(d, "now", tmp);
! Py_DECREF(tmp);
! if (err < 0)
! return;

m = Py_InitModule3("_datetime", functions,
--- 491,510 ----
Py_DECREF(dt);

! #if PY_VERSION_HEX < 0x02030000
! {
! PyObject *tmp;
! dt = PyCFunction_New(&datetime_now_mdef, NULL);
! if (dt == NULL)
! return;
! tmp = PyClassMethod_New(dt);
! Py_DECREF(dt);
! if (tmp == NULL)
! return;
! err = PyDict_SetItemString(d, "now", tmp);
! Py_DECREF(tmp);
! if (err < 0)
! return;
! }
! #endif

m = Py_InitModule3("_datetime", functions,