[Python-checkins] r46264 - python/trunk/Modules/grpmodule.c

brett.cannon python-checkins at python.org
Fri May 26 00:00:15 CEST 2006


Author: brett.cannon
Date: Fri May 26 00:00:14 2006
New Revision: 46264

Modified:
   python/trunk/Modules/grpmodule.c
Log:
Move over to use of METH_O and METH_NOARGS.


Modified: python/trunk/Modules/grpmodule.c
==============================================================================
--- python/trunk/Modules/grpmodule.c	(original)
+++ python/trunk/Modules/grpmodule.c	Fri May 26 00:00:14 2006
@@ -84,12 +84,18 @@
 }
 
 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 @@
 }
 
 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 @@
 }
 
 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 */


More information about the Python-checkins mailing list