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
1 changed files with 24 additions and 12 deletions

View File

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