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

Skip to content

Commit 3d25e16

Browse files
committed
Issue #20152: Port the pwd module to Argument Clinic.
1 parent 52d67ef commit 3d25e16

1 file changed

Lines changed: 46 additions & 26 deletions

File tree

Modules/pwdmodule.c

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
#include <pwd.h>
88

9+
#include "clinic/pwdmodule.c.h"
10+
/*[clinic input]
11+
output preset file
12+
module pwd
13+
[clinic start generated code]*/
14+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=bbcf68b1f549f917]*/
15+
916
static PyStructSequence_Field struct_pwd_type_fields[] = {
1017
{"pw_name", "user name"},
1118
{"pw_passwd", "password"},
@@ -87,18 +94,25 @@ mkpwent(struct passwd *p)
8794
return v;
8895
}
8996

90-
PyDoc_STRVAR(pwd_getpwuid__doc__,
91-
"getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,\n\
92-
pw_gid,pw_gecos,pw_dir,pw_shell)\n\
93-
Return the password database entry for the given numeric user ID.\n\
94-
See help(pwd) for more on password database entries.");
97+
/*[clinic input]
98+
pwd.getpwuid
99+
100+
uidobj: object
101+
/
102+
103+
Return the password database entry for the given numeric user ID.
104+
105+
See `help(pwd)` for more on password database entries.
106+
[clinic start generated code]*/
95107

96108
static PyObject *
97-
pwd_getpwuid(PyObject *self, PyObject *args)
109+
pwd_getpwuid(PyModuleDef *module, PyObject *uidobj)
110+
/*[clinic end generated code: output=cba29ae4c2bcb8e1 input=ae64d507a1c6d3e8]*/
98111
{
99112
uid_t uid;
100113
struct passwd *p;
101-
if (!PyArg_ParseTuple(args, "O&:getpwuid", _Py_Uid_Converter, &uid)) {
114+
115+
if (!_Py_Uid_Converter(uidobj, &uid)) {
102116
if (PyErr_ExceptionMatches(PyExc_OverflowError))
103117
PyErr_Format(PyExc_KeyError,
104118
"getpwuid(): uid not found");
@@ -116,21 +130,25 @@ pwd_getpwuid(PyObject *self, PyObject *args)
116130
return mkpwent(p);
117131
}
118132

119-
PyDoc_STRVAR(pwd_getpwnam__doc__,
120-
"getpwnam(name) -> (pw_name,pw_passwd,pw_uid,\n\
121-
pw_gid,pw_gecos,pw_dir,pw_shell)\n\
122-
Return the password database entry for the given user name.\n\
123-
See help(pwd) for more on password database entries.");
133+
/*[clinic input]
134+
pwd.getpwnam
135+
136+
arg: unicode
137+
/
138+
139+
Return the password database entry for the given user name.
140+
141+
See `help(pwd)` for more on password database entries.
142+
[clinic start generated code]*/
124143

125144
static PyObject *
126-
pwd_getpwnam(PyObject *self, PyObject *args)
145+
pwd_getpwnam_impl(PyModuleDef *module, PyObject *arg)
146+
/*[clinic end generated code: output=66848d42d386fca3 input=d5f7e700919b02d3]*/
127147
{
128148
char *name;
129149
struct passwd *p;
130-
PyObject *arg, *bytes, *retval = NULL;
150+
PyObject *bytes, *retval = NULL;
131151

132-
if (!PyArg_ParseTuple(args, "U:getpwnam", &arg))
133-
return NULL;
134152
if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
135153
return NULL;
136154
if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
@@ -147,14 +165,17 @@ pwd_getpwnam(PyObject *self, PyObject *args)
147165
}
148166

149167
#ifdef HAVE_GETPWENT
150-
PyDoc_STRVAR(pwd_getpwall__doc__,
151-
"getpwall() -> list_of_entries\n\
152-
Return a list of all available password database entries, \
153-
in arbitrary order.\n\
154-
See help(pwd) for more on password database entries.");
168+
/*[clinic input]
169+
pwd.getpwall
170+
171+
Return a list of all available password database entries, in arbitrary order.
172+
173+
See help(pwd) for more on password database entries.
174+
[clinic start generated code]*/
155175

156176
static PyObject *
157-
pwd_getpwall(PyObject *self)
177+
pwd_getpwall_impl(PyModuleDef *module)
178+
/*[clinic end generated code: output=ab30e37bf26d431d input=d7ecebfd90219b85]*/
158179
{
159180
PyObject *d;
160181
struct passwd *p;
@@ -177,11 +198,10 @@ pwd_getpwall(PyObject *self)
177198
#endif
178199

179200
static PyMethodDef pwd_methods[] = {
180-
{"getpwuid", pwd_getpwuid, METH_VARARGS, pwd_getpwuid__doc__},
181-
{"getpwnam", pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__},
201+
PWD_GETPWUID_METHODDEF
202+
PWD_GETPWNAM_METHODDEF
182203
#ifdef HAVE_GETPWENT
183-
{"getpwall", (PyCFunction)pwd_getpwall,
184-
METH_NOARGS, pwd_getpwall__doc__},
204+
PWD_GETPWALL_METHODDEF
185205
#endif
186206
{NULL, NULL} /* sentinel */
187207
};

0 commit comments

Comments
 (0)