diff -r 30013dbb5bc2 Modules/pwdmodule.c --- a/Modules/pwdmodule.c Fri Jan 17 12:06:28 2014 -0500 +++ b/Modules/pwdmodule.c Fri Jan 17 14:29:06 2014 -0500 @@ -6,6 +6,11 @@ #include +/*[clinic input] +module pwd +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + static PyStructSequence_Field struct_pwd_type_fields[] = { {"pw_name", "user name"}, {"pw_passwd", "password"}, @@ -87,18 +92,34 @@ return v; } +/*[clinic input] +pwd.getpwuid + + uidobj: object + / + +Return the password database entry for the given numeric user ID. + +See help(pwd) for more on password database entries. +[clinic start generated code]*/ + PyDoc_STRVAR(pwd_getpwuid__doc__, -"getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,\n\ - pw_gid,pw_gecos,pw_dir,pw_shell)\n\ -Return the password database entry for the given numeric user ID.\n\ -See help(pwd) for more on password database entries."); +"getpwuid(uidobj)\n" +"Return the password database entry for the given numeric user ID.\n" +"\n" +"See help(pwd) for more on password database entries."); + +#define PWD_GETPWUID_METHODDEF \ + {"getpwuid", (PyCFunction)pwd_getpwuid, METH_O, pwd_getpwuid__doc__}, static PyObject * -pwd_getpwuid(PyObject *self, PyObject *args) +pwd_getpwuid(PyModuleDef *module, PyObject *uidobj) +/*[clinic end generated code: checksum=b54b400bd87c1fdb90d2b6ae5d1c799ec2314bff]*/ { uid_t uid; struct passwd *p; - if (!PyArg_ParseTuple(args, "O&:getpwuid", _Py_Uid_Converter, &uid)) { + + if (!_Py_Uid_Converter(uidobj, &uid)) { if (PyErr_ExceptionMatches(PyExc_OverflowError)) PyErr_Format(PyExc_KeyError, "getpwuid(): uid not found"); @@ -116,21 +137,53 @@ return mkpwent(p); } +/*[clinic input] +pwd.getpwnam + + arg: unicode + / + +Return the password database entry for the given user name. + +See help(pwd) for more on password database entries. +[clinic start generated code]*/ + PyDoc_STRVAR(pwd_getpwnam__doc__, -"getpwnam(name) -> (pw_name,pw_passwd,pw_uid,\n\ - pw_gid,pw_gecos,pw_dir,pw_shell)\n\ -Return the password database entry for the given user name.\n\ -See help(pwd) for more on password database entries."); +"getpwnam(arg)\n" +"Return the password database entry for the given user name.\n" +"\n" +"See help(pwd) for more on password database entries."); + +#define PWD_GETPWNAM_METHODDEF \ + {"getpwnam", (PyCFunction)pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__}, static PyObject * -pwd_getpwnam(PyObject *self, PyObject *args) +pwd_getpwnam_impl(PyModuleDef *module, PyObject *arg); + +static PyObject * +pwd_getpwnam(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *arg; + + if (!PyArg_ParseTuple(args, + "U:getpwnam", + &arg)) + goto exit; + return_value = pwd_getpwnam_impl(module, arg); + +exit: + return return_value; +} + +static PyObject * +pwd_getpwnam_impl(PyModuleDef *module, PyObject *arg) +/*[clinic end generated code: checksum=f4530b6a4564930e0f821eeb26bcc1ab3f4a002d]*/ { char *name; 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) return NULL; if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1) @@ -147,14 +200,39 @@ } #ifdef HAVE_GETPWENT +/*[clinic input] +pwd.getpwall + +Return a list of all available password database entries, in arbitrary order. + +See help(pwd) for more on password database entries. +[clinic start generated code]*/ + PyDoc_STRVAR(pwd_getpwall__doc__, -"getpwall() -> list_of_entries\n\ -Return a list of all available password database entries, \ -in arbitrary order.\n\ -See help(pwd) for more on password database entries."); +"getpwall()\n" +"Return a list of all available password database entries, in arbitrary order.\n" +"\n" +"See help(pwd) for more on password database entries."); + +#define PWD_GETPWALL_METHODDEF \ + {"getpwall", (PyCFunction)pwd_getpwall, METH_NOARGS, pwd_getpwall__doc__}, static PyObject * -pwd_getpwall(PyObject *self) +pwd_getpwall_impl(PyModuleDef *module); + +static PyObject * +pwd_getpwall(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = pwd_getpwall_impl(module); + + return return_value; +} + +static PyObject * +pwd_getpwall_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=8656f6cad166fb0711d54f0c5285fde473d90e38]*/ { PyObject *d; struct passwd *p; @@ -177,11 +255,10 @@ #endif static PyMethodDef pwd_methods[] = { - {"getpwuid", pwd_getpwuid, METH_VARARGS, pwd_getpwuid__doc__}, - {"getpwnam", pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__}, + PWD_GETPWUID_METHODDEF + PWD_GETPWNAM_METHODDEF #ifdef HAVE_GETPWENT - {"getpwall", (PyCFunction)pwd_getpwall, - METH_NOARGS, pwd_getpwall__doc__}, + PWD_GETPWALL_METHODDEF #endif {NULL, NULL} /* sentinel */ };