Move over to use of METH_O and METH_NOARGS.

This commit is contained in:
Brett Cannon 2006-05-25 22:00:14 +00:00
parent 45c6472f99
commit 4c803f1c81

View file

@ -84,12 +84,18 @@ mkgrent(struct group *p)
} }
static PyObject * static PyObject *
grp_getgrgid(PyObject *self, PyObject *args) grp_getgrgid(PyObject *self, PyObject *pyo_id)
{ {
PyObject *py_int_id;
unsigned int gid; unsigned int gid;
struct group *p; struct group *p;
if (!PyArg_ParseTuple(args, "I:getgrgid", &gid))
return NULL; py_int_id = PyNumber_Int(pyo_id);
if (!py_int_id)
return NULL;
gid = PyInt_AS_LONG(py_int_id);
Py_DECREF(py_int_id);
if ((p = getgrgid(gid)) == NULL) { if ((p = getgrgid(gid)) == NULL) {
PyErr_Format(PyExc_KeyError, "getgrgid(): gid not found: %d", gid); PyErr_Format(PyExc_KeyError, "getgrgid(): gid not found: %d", gid);
return NULL; return NULL;
@ -98,27 +104,33 @@ grp_getgrgid(PyObject *self, PyObject *args)
} }
static PyObject * static PyObject *
grp_getgrnam(PyObject *self, PyObject *args) grp_getgrnam(PyObject *self, PyObject *pyo_name)
{ {
PyObject *py_str_name;
char *name; char *name;
struct group *p; struct group *p;
if (!PyArg_ParseTuple(args, "s:getgrnam", &name))
return NULL; py_str_name = PyObject_Str(pyo_name);
if (!py_str_name)
return NULL;
name = PyString_AS_STRING(py_str_name);
if ((p = getgrnam(name)) == NULL) { if ((p = getgrnam(name)) == NULL) {
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name); PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name);
Py_DECREF(py_str_name);
return NULL; return NULL;
} }
Py_DECREF(py_str_name);
return mkgrent(p); return mkgrent(p);
} }
static PyObject * static PyObject *
grp_getgrall(PyObject *self, PyObject *args) grp_getgrall(PyObject *self, PyObject *ignore)
{ {
PyObject *d; PyObject *d;
struct group *p; struct group *p;
if (!PyArg_ParseTuple(args, ":getgrall"))
return NULL;
if ((d = PyList_New(0)) == NULL) if ((d = PyList_New(0)) == NULL)
return NULL; return NULL;
setgrent(); setgrent();
@ -136,15 +148,15 @@ grp_getgrall(PyObject *self, PyObject *args)
} }
static PyMethodDef grp_methods[] = { static PyMethodDef grp_methods[] = {
{"getgrgid", grp_getgrgid, METH_VARARGS, {"getgrgid", grp_getgrgid, METH_O,
"getgrgid(id) -> tuple\n\ "getgrgid(id) -> tuple\n\
Return the group database entry for the given numeric group ID. If\n\ Return the group database entry for the given numeric group ID. If\n\
id is not valid, raise KeyError."}, id is not valid, raise KeyError."},
{"getgrnam", grp_getgrnam, METH_VARARGS, {"getgrnam", grp_getgrnam, METH_O,
"getgrnam(name) -> tuple\n\ "getgrnam(name) -> tuple\n\
Return the group database entry for the given group name. If\n\ Return the group database entry for the given group name. If\n\
name is not valid, raise KeyError."}, name is not valid, raise KeyError."},
{"getgrall", grp_getgrall, METH_VARARGS, {"getgrall", grp_getgrall, METH_NOARGS,
"getgrall() -> list of tuples\n\ "getgrall() -> list of tuples\n\
Return a list of all available group entries, in arbitrary order."}, Return a list of all available group entries, in arbitrary order."},
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */