summaryrefslogtreecommitdiffstats
path: root/Modules/grpmodule.c
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2014-08-22 15:52:46 (GMT)
committerBrett Cannon <brett@python.org>2014-08-22 15:52:46 (GMT)
commit8fb7bb2f2983f0b2b99c1012e6cae8d165115a08 (patch)
treeaf7b514506c5321bdf128b2dabd874da42ed1cce /Modules/grpmodule.c
parentf2de1fc21a34e772ca9bee5b8e2ec3fb8c2ea378 (diff)
downloadcpython-8fb7bb2f2983f0b2b99c1012e6cae8d165115a08.zip
cpython-8fb7bb2f2983f0b2b99c1012e6cae8d165115a08.tar.gz
cpython-8fb7bb2f2983f0b2b99c1012e6cae8d165115a08.tar.bz2
Issue #20152: Convert the grp module to Argument Clinic.
Diffstat (limited to 'Modules/grpmodule.c')
-rw-r--r--Modules/grpmodule.c79
1 files changed, 53 insertions, 26 deletions
diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c
index c8a9372..73289d5 100644
--- 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 @@ mkgrent(struct group *p)
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 @@ grp_getgrgid(PyObject *self, PyObject *pyo_id)
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))
- return NULL;
- if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
+ if ((bytes = PyUnicode_EncodeFSDefault(name)) == 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 @@ out:
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 @@ grp_getgrall(PyObject *self, PyObject *ignore)
}
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__,