mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #20152: Port the pwd module to Argument Clinic.
This commit is contained in:
parent
52d67ef358
commit
3d25e16760
1 changed files with 46 additions and 26 deletions
|
@ -6,6 +6,13 @@
|
||||||
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
|
#include "clinic/pwdmodule.c.h"
|
||||||
|
/*[clinic input]
|
||||||
|
output preset file
|
||||||
|
module pwd
|
||||||
|
[clinic start generated code]*/
|
||||||
|
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=bbcf68b1f549f917]*/
|
||||||
|
|
||||||
static PyStructSequence_Field struct_pwd_type_fields[] = {
|
static PyStructSequence_Field struct_pwd_type_fields[] = {
|
||||||
{"pw_name", "user name"},
|
{"pw_name", "user name"},
|
||||||
{"pw_passwd", "password"},
|
{"pw_passwd", "password"},
|
||||||
|
@ -87,18 +94,25 @@ mkpwent(struct passwd *p)
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(pwd_getpwuid__doc__,
|
/*[clinic input]
|
||||||
"getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,\n\
|
pwd.getpwuid
|
||||||
pw_gid,pw_gecos,pw_dir,pw_shell)\n\
|
|
||||||
Return the password database entry for the given numeric user ID.\n\
|
uidobj: object
|
||||||
See help(pwd) for more on password database entries.");
|
/
|
||||||
|
|
||||||
|
Return the password database entry for the given numeric user ID.
|
||||||
|
|
||||||
|
See `help(pwd)` for more on password database entries.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
pwd_getpwuid(PyObject *self, PyObject *args)
|
pwd_getpwuid(PyModuleDef *module, PyObject *uidobj)
|
||||||
|
/*[clinic end generated code: output=cba29ae4c2bcb8e1 input=ae64d507a1c6d3e8]*/
|
||||||
{
|
{
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
struct passwd *p;
|
struct passwd *p;
|
||||||
if (!PyArg_ParseTuple(args, "O&:getpwuid", _Py_Uid_Converter, &uid)) {
|
|
||||||
|
if (!_Py_Uid_Converter(uidobj, &uid)) {
|
||||||
if (PyErr_ExceptionMatches(PyExc_OverflowError))
|
if (PyErr_ExceptionMatches(PyExc_OverflowError))
|
||||||
PyErr_Format(PyExc_KeyError,
|
PyErr_Format(PyExc_KeyError,
|
||||||
"getpwuid(): uid not found");
|
"getpwuid(): uid not found");
|
||||||
|
@ -116,21 +130,25 @@ pwd_getpwuid(PyObject *self, PyObject *args)
|
||||||
return mkpwent(p);
|
return mkpwent(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(pwd_getpwnam__doc__,
|
/*[clinic input]
|
||||||
"getpwnam(name) -> (pw_name,pw_passwd,pw_uid,\n\
|
pwd.getpwnam
|
||||||
pw_gid,pw_gecos,pw_dir,pw_shell)\n\
|
|
||||||
Return the password database entry for the given user name.\n\
|
arg: unicode
|
||||||
See help(pwd) for more on password database entries.");
|
/
|
||||||
|
|
||||||
|
Return the password database entry for the given user name.
|
||||||
|
|
||||||
|
See `help(pwd)` for more on password database entries.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
pwd_getpwnam(PyObject *self, PyObject *args)
|
pwd_getpwnam_impl(PyModuleDef *module, PyObject *arg)
|
||||||
|
/*[clinic end generated code: output=66848d42d386fca3 input=d5f7e700919b02d3]*/
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
struct passwd *p;
|
struct passwd *p;
|
||||||
PyObject *arg, *bytes, *retval = NULL;
|
PyObject *bytes, *retval = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "U:getpwnam", &arg))
|
|
||||||
return NULL;
|
|
||||||
if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
|
if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
|
if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
|
||||||
|
@ -147,14 +165,17 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_GETPWENT
|
#ifdef HAVE_GETPWENT
|
||||||
PyDoc_STRVAR(pwd_getpwall__doc__,
|
/*[clinic input]
|
||||||
"getpwall() -> list_of_entries\n\
|
pwd.getpwall
|
||||||
Return a list of all available password database entries, \
|
|
||||||
in arbitrary order.\n\
|
Return a list of all available password database entries, in arbitrary order.
|
||||||
See help(pwd) for more on password database entries.");
|
|
||||||
|
See help(pwd) for more on password database entries.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
pwd_getpwall(PyObject *self)
|
pwd_getpwall_impl(PyModuleDef *module)
|
||||||
|
/*[clinic end generated code: output=ab30e37bf26d431d input=d7ecebfd90219b85]*/
|
||||||
{
|
{
|
||||||
PyObject *d;
|
PyObject *d;
|
||||||
struct passwd *p;
|
struct passwd *p;
|
||||||
|
@ -177,11 +198,10 @@ pwd_getpwall(PyObject *self)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PyMethodDef pwd_methods[] = {
|
static PyMethodDef pwd_methods[] = {
|
||||||
{"getpwuid", pwd_getpwuid, METH_VARARGS, pwd_getpwuid__doc__},
|
PWD_GETPWUID_METHODDEF
|
||||||
{"getpwnam", pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__},
|
PWD_GETPWNAM_METHODDEF
|
||||||
#ifdef HAVE_GETPWENT
|
#ifdef HAVE_GETPWENT
|
||||||
{"getpwall", (PyCFunction)pwd_getpwall,
|
PWD_GETPWALL_METHODDEF
|
||||||
METH_NOARGS, pwd_getpwall__doc__},
|
|
||||||
#endif
|
#endif
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue