diff -r f2d955afad8a Doc/library/spwd.rst --- a/Doc/library/spwd.rst Sat Aug 17 21:43:47 2013 +0200 +++ b/Doc/library/spwd.rst Sun Aug 18 22:55:25 2013 +0800 @@ -19,9 +19,9 @@ +-------+---------------+---------------------------------+ | Index | Attribute | Meaning | +=======+===============+=================================+ -| 0 | ``sp_nam`` | Login name | +| 0 | ``sp_namp`` | Login name | +-------+---------------+---------------------------------+ -| 1 | ``sp_pwd`` | Encrypted password | +| 1 | ``sp_pwdp`` | Encrypted password | +-------+---------------+---------------------------------+ | 2 | ``sp_lstchg`` | Date of last change | +-------+---------------+---------------------------------+ @@ -36,15 +36,15 @@ +-------+---------------+---------------------------------+ | 6 | ``sp_inact`` | Number of days after password | | | | expires until account is | -| | | blocked | +| | | disabled | +-------+---------------+---------------------------------+ | 7 | ``sp_expire`` | Number of days since 1970-01-01 | -| | | until account is disabled | +| | | when account expires | +-------+---------------+---------------------------------+ | 8 | ``sp_flag`` | Reserved | +-------+---------------+---------------------------------+ -The sp_nam and sp_pwd items are strings, all others are integers. +The sp_namp and sp_pwdp items are strings, all others are integers. :exc:`KeyError` is raised if the entry asked for cannot be found. The following functions are defined: diff -r f2d955afad8a Lib/spwd.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/spwd.py Sun Aug 18 22:55:25 2013 +0800 @@ -0,0 +1,95 @@ +try: + import _spwd +except ImportError: + raise ImportError("No module named 'spwd'") +import warnings + + +class struct_spwd(object): + def __init__(self, struct): + self.wrapped_struct = struct + self.__doc__ = self.wrapped_struct.__doc__ + + def __add__(self, struct): + return self.wrapped_struct.__add__(struct) + + def __delattr__(self, attr): + return self.wrapped_struct.__delattr__(attr) + + def __dir__(self): + return dir(self.wrapped_struct) + + def __eq__(self, struct): + return self.wrapped_struct == struct + + def __ge__(self, struct): + return self.wrapped_struct >= struct + + def __getitem__(self, index): + return self.wrapped_struct[index] + + def __gt__(self, struct): + return self.wrapped_struct > struct + + def __hash__(self): + return hash(self.wrapped_struct) + + def __le__(self, struct): + return self.wrapped_struct <= struct + + def __len__(self): + return len(self.wrapped_struct) + + def __lt__(self, struct): + return self.wrapped_struct < struct + + def __mul__(self, number): + return self.wrapped_struct.__mul__(number) + + def __reduce__(self): + return self.wrapped_struct.__reduce__() + + def __reduce_ex__(self): + return self.wrapped_struct.__reduce_ex__() + + def __repr__(self): + return self.wrapped_struct.__repr__() + + def __rmul__(self, number): + return self.wrapped_struct.__rmul__(number) + + def __sizeof__(self): + return self.wrapped_struct.__sizeof__() + + def __getattr__(self, name): + if name=='sp_nam': + warnings.warn('The `sp_nam` attribute of struct_spwd is ' + 'deprecated and will be removed in Python 3.6', + DeprecationWarning) + return self.wrapped_struct.sp_namp + elif name=='sp_pwd': + warnings.warn('The `sp_pwd` attribute of struct_spwd is ' + 'deprecated and will be removed in Python 3.6', + DeprecationWarning) + return self.wrapped_struct.sp_pwdp + else: + return getattr(self.wrapped_struct, name) + +__all__ = ['getspnam', 'getspall'] + +def getspnam(name): + return struct_spwd(_spwd.getspnam(name)) + +def getspall(): + return list(map(struct_spwd, _spwd.getspall())) + +def test(): + import sys + if sys.argv[1:]: + print(getspnam(sys.argv[1])) + else: + for struct in getspall(): + print(struct) + +if __name__ == '__main__': + test() diff -r f2d955afad8a Modules/spwdmodule.c --- a/Modules/spwdmodule.c Sat Aug 17 21:43:47 2013 +0200 +++ b/Modules/spwdmodule.c Sun Aug 18 22:55:25 2013 +0800 @@ -26,14 +26,14 @@ #if defined(HAVE_GETSPNAM) || defined(HAVE_GETSPENT) static PyStructSequence_Field struct_spwd_type_fields[] = { - {"sp_nam", "login name"}, - {"sp_pwd", "encrypted password"}, + {"sp_namp", "login name"}, + {"sp_pwdp", "encrypted password"}, {"sp_lstchg", "date of last change"}, {"sp_min", "min #days between changes"}, {"sp_max", "max #days between changes"}, {"sp_warn", "#days before pw expires to warn user about it"}, - {"sp_inact", "#days after pw expires until account is blocked"}, - {"sp_expire", "#days since 1970-01-01 until account is disabled"}, + {"sp_inact", "#days after pw expires until account is disabled"}, + {"sp_expire", "#days since 1970-01-01 when account expires"}, {"sp_flag", "reserved"}, {0} }; @@ -41,7 +41,7 @@ PyDoc_STRVAR(struct_spwd__doc__, "spwd.struct_spwd: Results from getsp*() routines.\n\n\ This object may be accessed either as a 9-tuple of\n\ - (sp_nam,sp_pwd,sp_lstchg,sp_min,sp_max,sp_warn,sp_inact,sp_expire,sp_flag)\n\ + (sp_namp,sp_pwdp,sp_lstchg,sp_min,sp_max,sp_warn,sp_inact,sp_expire,sp_flag)\n\ or via the object attributes as named in the above tuple."); static PyStructSequence_Desc struct_spwd_type_desc = { @@ -179,7 +179,7 @@ static struct PyModuleDef spwdmodule = { PyModuleDef_HEAD_INIT, - "spwd", + "_spwd", spwd__doc__, -1, spwd_methods, @@ -190,7 +190,7 @@ }; PyMODINIT_FUNC -PyInit_spwd(void) +PyInit__spwd(void) { PyObject *m; m=PyModule_Create(&spwdmodule); diff -r f2d955afad8a setup.py --- a/setup.py Sat Aug 17 21:43:47 2013 +0200 +++ b/setup.py Sun Aug 18 22:55:25 2013 +0800 @@ -614,9 +614,9 @@ # spwd, shadow passwords if (config_h_vars.get('HAVE_GETSPNAM', False) or config_h_vars.get('HAVE_GETSPENT', False)): - exts.append( Extension('spwd', ['spwdmodule.c']) ) + exts.append( Extension('_spwd', ['spwdmodule.c']) ) else: - missing.append('spwd') + missing.append('_spwd') # select(2); not on ancient System V exts.append( Extension('select', ['selectmodule.c']) )