Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Modules/pwdmodule.c

    r2 r388  
    44#include "Python.h"
    55#include "structseq.h"
    6 
    7 #include <sys/types.h>
     6#include "posixmodule.h"
     7
    88#include <pwd.h>
    99
    1010static PyStructSequence_Field struct_pwd_type_fields[] = {
    11         {"pw_name", "user name"},
    12         {"pw_passwd", "password"},
    13         {"pw_uid", "user id"},
    14         {"pw_gid", "group id"},
    15         {"pw_gecos", "real name"},
    16         {"pw_dir", "home directory"},
    17         {"pw_shell", "shell program"},
    18         {0}
     11    {"pw_name", "user name"},
     12    {"pw_passwd", "password"},
     13    {"pw_uid", "user id"},
     14    {"pw_gid", "group id"},
     15    {"pw_gecos", "real name"},
     16    {"pw_dir", "home directory"},
     17    {"pw_shell", "shell program"},
     18    {0}
    1919};
    2020
     
    2626
    2727static PyStructSequence_Desc struct_pwd_type_desc = {
    28         "pwd.struct_passwd",
    29         struct_passwd__doc__,
    30         struct_pwd_type_fields,
    31         7,
     28    "pwd.struct_passwd",
     29    struct_passwd__doc__,
     30    struct_pwd_type_fields,
     31    7,
    3232};
    3333
     
    4242exception is raised if the entry asked for cannot be found.");
    4343
    44      
     44
    4545static int initialized;
    4646static PyTypeObject StructPwdType;
     
    5050{
    5151  if (val)
    52           PyStructSequence_SET_ITEM(v, i, PyString_FromString(val));
     52      PyStructSequence_SET_ITEM(v, i, PyString_FromString(val));
    5353  else {
    54           PyStructSequence_SET_ITEM(v, i, Py_None);
    55           Py_INCREF(Py_None);
     54      PyStructSequence_SET_ITEM(v, i, Py_None);
     55      Py_INCREF(Py_None);
    5656  }
    5757}
     
    6060mkpwent(struct passwd *p)
    6161{
    62         int setIndex = 0;
    63         PyObject *v = PyStructSequence_New(&StructPwdType);
    64         if (v == NULL)
    65                 return NULL;
     62    int setIndex = 0;
     63    PyObject *v = PyStructSequence_New(&StructPwdType);
     64    if (v == NULL)
     65        return NULL;
    6666
    6767#define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val))
    6868#define SETS(i,val) sets(v, i, val)
    6969
    70         SETS(setIndex++, p->pw_name);
     70    SETS(setIndex++, p->pw_name);
    7171#ifdef __VMS
    72         SETS(setIndex++, "");
     72    SETS(setIndex++, "");
    7373#else
    74         SETS(setIndex++, p->pw_passwd);
    75 #endif
    76         SETI(setIndex++, p->pw_uid);
    77         SETI(setIndex++, p->pw_gid);
     74    SETS(setIndex++, p->pw_passwd);
     75#endif
     76    PyStructSequence_SET_ITEM(v, setIndex++, _PyInt_FromUid(p->pw_uid));
     77    PyStructSequence_SET_ITEM(v, setIndex++, _PyInt_FromGid(p->pw_gid));
    7878#ifdef __VMS
    79         SETS(setIndex++, "");
     79    SETS(setIndex++, "");
    8080#else
    81         SETS(setIndex++, p->pw_gecos);
    82 #endif
    83         SETS(setIndex++, p->pw_dir);
    84         SETS(setIndex++, p->pw_shell);
     81    SETS(setIndex++, p->pw_gecos);
     82#endif
     83    SETS(setIndex++, p->pw_dir);
     84    SETS(setIndex++, p->pw_shell);
    8585
    8686#undef SETS
    8787#undef SETI
    8888
    89         if (PyErr_Occurred()) {
    90                 Py_XDECREF(v);
    91                 return NULL;
    92         }
    93 
    94         return v;
     89    if (PyErr_Occurred()) {
     90        Py_XDECREF(v);
     91        return NULL;
     92    }
     93
     94    return v;
    9595}
    9696
     
    9999                  pw_gid,pw_gecos,pw_dir,pw_shell)\n\
    100100Return the password database entry for the given numeric user ID.\n\
    101 See pwd.__doc__ for more on password database entries.");
     101See help(pwd) for more on password database entries.");
    102102
    103103static PyObject *
    104104pwd_getpwuid(PyObject *self, PyObject *args)
    105105{
    106         unsigned int uid;
    107         struct passwd *p;
    108         if (!PyArg_ParseTuple(args, "I:getpwuid", &uid))
    109                 return NULL;
    110         if ((p = getpwuid(uid)) == NULL) {
    111                 PyErr_Format(PyExc_KeyError,
    112                              "getpwuid(): uid not found: %d", uid);
    113                 return NULL;
    114         }
    115         return mkpwent(p);
     106    uid_t uid;
     107    struct passwd *p;
     108    if (!PyArg_ParseTuple(args, "O&:getpwuid", _Py_Uid_Converter, &uid)) {
     109        if (PyErr_ExceptionMatches(PyExc_OverflowError))
     110            PyErr_Format(PyExc_KeyError,
     111                         "getpwuid(): uid not found");
     112        return NULL;
     113    }
     114    if ((p = getpwuid(uid)) == NULL) {
     115        if (uid < 0)
     116            PyErr_Format(PyExc_KeyError,
     117                         "getpwuid(): uid not found: %ld", (long)uid);
     118        else
     119            PyErr_Format(PyExc_KeyError,
     120                         "getpwuid(): uid not found: %lu", (unsigned long)uid);
     121        return NULL;
     122    }
     123    return mkpwent(p);
    116124}
    117125
     
    120128                    pw_gid,pw_gecos,pw_dir,pw_shell)\n\
    121129Return the password database entry for the given user name.\n\
    122 See pwd.__doc__ for more on password database entries.");
     130See help(pwd) for more on password database entries.");
    123131
    124132static PyObject *
    125133pwd_getpwnam(PyObject *self, PyObject *args)
    126134{
    127         char *name;
    128         struct passwd *p;
    129         if (!PyArg_ParseTuple(args, "s:getpwnam", &name))
    130                 return NULL;
    131         if ((p = getpwnam(name)) == NULL) {
    132                 PyErr_Format(PyExc_KeyError,
    133                              "getpwnam(): name not found: %s", name);
    134                 return NULL;
    135         }
    136         return mkpwent(p);
     135    char *name;
     136    struct passwd *p;
     137    if (!PyArg_ParseTuple(args, "s:getpwnam", &name))
     138        return NULL;
     139    if ((p = getpwnam(name)) == NULL) {
     140        PyErr_Format(PyExc_KeyError,
     141                     "getpwnam(): name not found: %s", name);
     142        return NULL;
     143    }
     144    return mkpwent(p);
    137145}
    138146
     
    142150Return a list of all available password database entries, \
    143151in arbitrary order.\n\
    144 See pwd.__doc__ for more on password database entries.");
     152See help(pwd) for more on password database entries.");
    145153
    146154static PyObject *
    147155pwd_getpwall(PyObject *self)
    148156{
    149         PyObject *d;
    150         struct passwd *p;
    151         if ((d = PyList_New(0)) == NULL)
    152                 return NULL;
     157    PyObject *d;
     158    struct passwd *p;
     159    if ((d = PyList_New(0)) == NULL)
     160        return NULL;
    153161#if defined(PYOS_OS2) && defined(PYCC_GCC)
    154         if ((p = getpwuid(0)) != NULL) {
     162    if ((p = getpwuid(0)) != NULL) {
    155163#else
    156         setpwent();
    157         while ((p = getpwent()) != NULL) {
    158 #endif
    159                 PyObject *v = mkpwent(p);
    160                 if (v == NULL || PyList_Append(d, v) != 0) {
    161                         Py_XDECREF(v);
    162                         Py_DECREF(d);
    163                         endpwent();
    164                         return NULL;
    165                 }
    166                 Py_DECREF(v);
    167         }
    168         endpwent();
    169         return d;
     164    setpwent();
     165    while ((p = getpwent()) != NULL) {
     166#endif
     167        PyObject *v = mkpwent(p);
     168        if (v == NULL || PyList_Append(d, v) != 0) {
     169            Py_XDECREF(v);
     170            Py_DECREF(d);
     171            endpwent();
     172            return NULL;
     173        }
     174        Py_DECREF(v);
     175    }
     176    endpwent();
     177    return d;
    170178}
    171179#endif
    172180
    173181static PyMethodDef pwd_methods[] = {
    174         {"getpwuid",    pwd_getpwuid, METH_VARARGS, pwd_getpwuid__doc__},
    175         {"getpwnam",    pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__},
     182    {"getpwuid",        pwd_getpwuid, METH_VARARGS, pwd_getpwuid__doc__},
     183    {"getpwnam",        pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__},
    176184#ifdef HAVE_GETPWENT
    177         {"getpwall",    (PyCFunction)pwd_getpwall,
    178                 METH_NOARGS,  pwd_getpwall__doc__},
    179 #endif
    180         {NULL,          NULL}           /* sentinel */
     185    {"getpwall",        (PyCFunction)pwd_getpwall,
     186        METH_NOARGS,  pwd_getpwall__doc__},
     187#endif
     188    {NULL,              NULL}           /* sentinel */
    181189};
    182190
     
    184192initpwd(void)
    185193{
    186         PyObject *m;
    187         m = Py_InitModule3("pwd", pwd_methods, pwd__doc__);
    188         if (m == NULL)
    189                 return;
    190 
    191         if (!initialized)
    192                 PyStructSequence_InitType(&StructPwdType,
    193                                           &struct_pwd_type_desc);
    194         Py_INCREF((PyObject *) &StructPwdType);
    195         PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType);
    196         /* And for b/w compatibility (this was defined by mistake): */
    197         Py_INCREF((PyObject *) &StructPwdType);
    198         PyModule_AddObject(m, "struct_pwent", (PyObject *) &StructPwdType);
    199         initialized = 1;
    200 }
     194    PyObject *m;
     195    m = Py_InitModule3("pwd", pwd_methods, pwd__doc__);
     196    if (m == NULL)
     197        return;
     198
     199    if (!initialized)
     200        PyStructSequence_InitType(&StructPwdType,
     201                                  &struct_pwd_type_desc);
     202    Py_INCREF((PyObject *) &StructPwdType);
     203    PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType);
     204    /* And for b/w compatibility (this was defined by mistake): */
     205    Py_INCREF((PyObject *) &StructPwdType);
     206    PyModule_AddObject(m, "struct_pwent", (PyObject *) &StructPwdType);
     207    initialized = 1;
     208}
Note: See TracChangeset for help on using the changeset viewer.