Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 20cf6dd

Browse files
committed
Issue #20152: Port the spwd module to Argument Clinic.
1 parent 04bb443 commit 20cf6dd

2 files changed

Lines changed: 100 additions & 17 deletions

File tree

Modules/clinic/spwdmodule.c.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*[clinic input]
2+
preserve
3+
[clinic start generated code]*/
4+
5+
#if defined(HAVE_GETSPNAM)
6+
7+
PyDoc_STRVAR(spwd_getspnam__doc__,
8+
"getspnam($module, arg, /)\n"
9+
"--\n"
10+
"\n"
11+
"Return the shadow password database entry for the given user name.\n"
12+
"\n"
13+
"See `help(spwd)` for more on shadow password database entries.");
14+
15+
#define SPWD_GETSPNAM_METHODDEF \
16+
{"getspnam", (PyCFunction)spwd_getspnam, METH_VARARGS, spwd_getspnam__doc__},
17+
18+
static PyObject *
19+
spwd_getspnam_impl(PyModuleDef *module, PyObject *arg);
20+
21+
static PyObject *
22+
spwd_getspnam(PyModuleDef *module, PyObject *args)
23+
{
24+
PyObject *return_value = NULL;
25+
PyObject *arg;
26+
27+
if (!PyArg_ParseTuple(args,
28+
"U:getspnam",
29+
&arg))
30+
goto exit;
31+
return_value = spwd_getspnam_impl(module, arg);
32+
33+
exit:
34+
return return_value;
35+
}
36+
37+
#endif /* defined(HAVE_GETSPNAM) */
38+
39+
#ifndef SPWD_GETSPNAM_METHODDEF
40+
#define SPWD_GETSPNAM_METHODDEF
41+
#endif /* !defined(SPWD_GETSPNAM_METHODDEF) */
42+
43+
#if defined(HAVE_GETSPENT)
44+
45+
PyDoc_STRVAR(spwd_getspall__doc__,
46+
"getspall($module, /)\n"
47+
"--\n"
48+
"\n"
49+
"Return a list of all available shadow password database entries, in arbitrary order.\n"
50+
"\n"
51+
"See `help(spwd)` for more on shadow password database entries.");
52+
53+
#define SPWD_GETSPALL_METHODDEF \
54+
{"getspall", (PyCFunction)spwd_getspall, METH_NOARGS, spwd_getspall__doc__},
55+
56+
static PyObject *
57+
spwd_getspall_impl(PyModuleDef *module);
58+
59+
static PyObject *
60+
spwd_getspall(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
61+
{
62+
return spwd_getspall_impl(module);
63+
}
64+
65+
#endif /* defined(HAVE_GETSPENT) */
66+
67+
#ifndef SPWD_GETSPALL_METHODDEF
68+
#define SPWD_GETSPALL_METHODDEF
69+
#endif /* !defined(SPWD_GETSPALL_METHODDEF) */
70+
/*[clinic end generated code: output=41fec4a15b0cd2a0 input=a9049054013a1b77]*/

Modules/spwdmodule.c

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
#include <shadow.h>
1111
#endif
1212

13+
/*[clinic input]
14+
output preset file
15+
module spwd
16+
[clinic start generated code]*/
17+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b3464a3667278fae]*/
1318

1419
PyDoc_STRVAR(spwd__doc__,
1520
"This module provides access to the Unix shadow password database.\n\
@@ -107,20 +112,25 @@ static PyObject *mkspent(struct spwd *p)
107112

108113
#ifdef HAVE_GETSPNAM
109114

110-
PyDoc_STRVAR(spwd_getspnam__doc__,
111-
"getspnam(name) -> (sp_namp, sp_pwdp, sp_lstchg, sp_min, sp_max,\n\
112-
sp_warn, sp_inact, sp_expire, sp_flag)\n\
113-
Return the shadow password database entry for the given user name.\n\
114-
See spwd.__doc__ for more on shadow password database entries.");
115+
/*[clinic input]
116+
spwd.getspnam
115117
116-
static PyObject* spwd_getspnam(PyObject *self, PyObject *args)
118+
arg: unicode
119+
/
120+
121+
Return the shadow password database entry for the given user name.
122+
123+
See `help(spwd)` for more on shadow password database entries.
124+
[clinic start generated code]*/
125+
126+
static PyObject *
127+
spwd_getspnam_impl(PyModuleDef *module, PyObject *arg)
128+
/*[clinic end generated code: output=9f6bbe51a4eb3b21 input=dd89429e6167a00f]*/
117129
{
118130
char *name;
119131
struct spwd *p;
120-
PyObject *arg, *bytes, *retval = NULL;
132+
PyObject *bytes, *retval = NULL;
121133

122-
if (!PyArg_ParseTuple(args, "U:getspnam", &arg))
123-
return NULL;
124134
if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
125135
return NULL;
126136
if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
@@ -139,14 +149,17 @@ static PyObject* spwd_getspnam(PyObject *self, PyObject *args)
139149

140150
#ifdef HAVE_GETSPENT
141151

142-
PyDoc_STRVAR(spwd_getspall__doc__,
143-
"getspall() -> list_of_entries\n\
144-
Return a list of all available shadow password database entries, \
145-
in arbitrary order.\n\
146-
See spwd.__doc__ for more on shadow password database entries.");
152+
/*[clinic input]
153+
spwd.getspall
154+
155+
Return a list of all available shadow password database entries, in arbitrary order.
156+
157+
See `help(spwd)` for more on shadow password database entries.
158+
[clinic start generated code]*/
147159

148160
static PyObject *
149-
spwd_getspall(PyObject *self, PyObject *args)
161+
spwd_getspall_impl(PyModuleDef *module)
162+
/*[clinic end generated code: output=b12d8ec7bdb29612 input=b2c84b7857d622bd]*/
150163
{
151164
PyObject *d;
152165
struct spwd *p;
@@ -171,10 +184,10 @@ spwd_getspall(PyObject *self, PyObject *args)
171184

172185
static PyMethodDef spwd_methods[] = {
173186
#ifdef HAVE_GETSPNAM
174-
{"getspnam", spwd_getspnam, METH_VARARGS, spwd_getspnam__doc__},
187+
SPWD_GETSPNAM_METHODDEF
175188
#endif
176189
#ifdef HAVE_GETSPENT
177-
{"getspall", spwd_getspall, METH_NOARGS, spwd_getspall__doc__},
190+
SPWD_GETSPALL_METHODDEF
178191
#endif
179192
{NULL, NULL} /* sentinel */
180193
};

0 commit comments

Comments
 (0)