[Python-checkins] cpython: Issue #20152: Convert the grp module to Argument Clinic.
brett.cannon
python-checkins at python.org
Fri Aug 22 17:52:52 CEST 2014
http://hg.python.org/cpython/rev/2617db7e43a3
changeset: 92185:2617db7e43a3
user: Brett Cannon <brett at python.org>
date: Fri Aug 22 11:52:46 2014 -0400
summary:
Issue #20152: Convert the grp module to Argument Clinic.
files:
Modules/clinic/grpmodule.c.h | 87 ++++++++++++++++++++++++
Modules/grpmodule.c | 79 ++++++++++++++-------
2 files changed, 140 insertions(+), 26 deletions(-)
diff --git a/Modules/clinic/grpmodule.c.h b/Modules/clinic/grpmodule.c.h
new file mode 100644
--- /dev/null
+++ b/Modules/clinic/grpmodule.c.h
@@ -0,0 +1,87 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+PyDoc_STRVAR(grp_getgrgid__doc__,
+"getgrgid($module, /, id)\n"
+"--\n"
+"\n"
+"Return the group database entry for the given numeric group ID.\n"
+"\n"
+"If id is not valid, raise KeyError.");
+
+#define GRP_GETGRGID_METHODDEF \
+ {"getgrgid", (PyCFunction)grp_getgrgid, METH_VARARGS|METH_KEYWORDS, grp_getgrgid__doc__},
+
+static PyObject *
+grp_getgrgid_impl(PyModuleDef *module, PyObject *id);
+
+static PyObject *
+grp_getgrgid(PyModuleDef *module, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static char *_keywords[] = {"id", NULL};
+ PyObject *id;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O:getgrgid", _keywords,
+ &id))
+ goto exit;
+ return_value = grp_getgrgid_impl(module, id);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(grp_getgrnam__doc__,
+"getgrnam($module, /, name)\n"
+"--\n"
+"\n"
+"Return the group database entry for the given group name.\n"
+"\n"
+"If name is not valid, raise KeyError.");
+
+#define GRP_GETGRNAM_METHODDEF \
+ {"getgrnam", (PyCFunction)grp_getgrnam, METH_VARARGS|METH_KEYWORDS, grp_getgrnam__doc__},
+
+static PyObject *
+grp_getgrnam_impl(PyModuleDef *module, PyObject *name);
+
+static PyObject *
+grp_getgrnam(PyModuleDef *module, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static char *_keywords[] = {"name", NULL};
+ PyObject *name;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "U:getgrnam", _keywords,
+ &name))
+ goto exit;
+ return_value = grp_getgrnam_impl(module, name);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(grp_getgrall__doc__,
+"getgrall($module, /)\n"
+"--\n"
+"\n"
+"Return a list of all available group entries, in arbitrary order.\n"
+"\n"
+"An entry whose name starts with \'+\' or \'-\' represents an instruction\n"
+"to use YP/NIS and may not be accessible via getgrnam or getgrgid.");
+
+#define GRP_GETGRALL_METHODDEF \
+ {"getgrall", (PyCFunction)grp_getgrall, METH_NOARGS, grp_getgrall__doc__},
+
+static PyObject *
+grp_getgrall_impl(PyModuleDef *module);
+
+static PyObject *
+grp_getgrall(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
+{
+ return grp_getgrall_impl(module);
+}
+/*[clinic end generated code: output=4709a6ba40bb8df9 input=a9049054013a1b77]*/
diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c
--- a/Modules/grpmodule.c
+++ b/Modules/grpmodule.c
@@ -6,6 +6,13 @@
#include <grp.h>
+#include "clinic/grpmodule.c.h"
+/*[clinic input]
+output preset file
+module grp
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=68180a9a9efb8506]*/
+
static PyStructSequence_Field struct_group_type_fields[] = {
{"gr_name", "group name"},
{"gr_passwd", "password"},
@@ -76,14 +83,25 @@
return v;
}
+/*[clinic input]
+grp.getgrgid
+
+ id: object
+
+Return the group database entry for the given numeric group ID.
+
+If id is not valid, raise KeyError.
+[clinic start generated code]*/
+
static PyObject *
-grp_getgrgid(PyObject *self, PyObject *pyo_id)
+grp_getgrgid_impl(PyModuleDef *module, PyObject *id)
+/*[clinic end generated code: output=8a11f5fdeb8c78a0 input=15fa0e2ccf5cda25]*/
{
PyObject *py_int_id;
gid_t gid;
struct group *p;
- py_int_id = PyNumber_Long(pyo_id);
+ py_int_id = PyNumber_Long(id);
if (!py_int_id)
return NULL;
if (!_Py_Gid_Converter(py_int_id, &gid)) {
@@ -103,22 +121,31 @@
return mkgrent(p);
}
+/*[clinic input]
+grp.getgrnam
+
+ name: unicode
+
+Return the group database entry for the given group name.
+
+If name is not valid, raise KeyError.
+[clinic start generated code]*/
+
static PyObject *
-grp_getgrnam(PyObject *self, PyObject *args)
+grp_getgrnam_impl(PyModuleDef *module, PyObject *name)
+/*[clinic end generated code: output=cd47511f4854da8e input=08ded29affa3c863]*/
{
- char *name;
+ char *name_chars;
struct group *p;
- PyObject *arg, *bytes, *retval = NULL;
+ PyObject *bytes, *retval = NULL;
- if (!PyArg_ParseTuple(args, "U:getgrnam", &arg))
+ if ((bytes = PyUnicode_EncodeFSDefault(name)) == NULL)
return NULL;
- if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
- return NULL;
- if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
+ if (PyBytes_AsStringAndSize(bytes, &name_chars, NULL) == -1)
goto out;
- if ((p = getgrnam(name)) == NULL) {
- PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name);
+ if ((p = getgrnam(name_chars)) == NULL) {
+ PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name_chars);
goto out;
}
retval = mkgrent(p);
@@ -127,8 +154,18 @@
return retval;
}
+/*[clinic input]
+grp.getgrall
+
+Return a list of all available group entries, in arbitrary order.
+
+An entry whose name starts with '+' or '-' represents an instruction
+to use YP/NIS and may not be accessible via getgrnam or getgrgid.
+[clinic start generated code]*/
+
static PyObject *
-grp_getgrall(PyObject *self, PyObject *ignore)
+grp_getgrall_impl(PyModuleDef *module)
+/*[clinic end generated code: output=add9037a20c202de input=d7df76c825c367df]*/
{
PyObject *d;
struct group *p;
@@ -151,20 +188,10 @@
}
static PyMethodDef grp_methods[] = {
- {"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(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_NOARGS,
- "getgrall() -> list of tuples\n\
-Return a list of all available group entries, in arbitrary order.\n\
-An entry whose name starts with '+' or '-' represents an instruction\n\
-to use YP/NIS and may not be accessible via getgrnam or getgrgid."},
- {NULL, NULL} /* sentinel */
+ GRP_GETGRGID_METHODDEF
+ GRP_GETGRNAM_METHODDEF
+ GRP_GETGRALL_METHODDEF
+ {NULL, NULL}
};
PyDoc_STRVAR(grp__doc__,
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list