From: <nr...@us...> - 2008-07-28 22:56:57
|
Revision: 5015 http://jython.svn.sourceforge.net/jython/?rev=5015&view=rev Author: nriley Date: 2008-07-28 22:56:55 +0000 (Mon, 28 Jul 2008) Log Message: ----------- pwd, grp; test_posix no longer skipped Modified Paths: -------------- branches/asm/Lib/test/regrtest.py Added Paths: ----------- branches/asm/Lib/grp.py branches/asm/Lib/pwd.py Added: branches/asm/Lib/grp.py =================================================================== --- branches/asm/Lib/grp.py (rev 0) +++ branches/asm/Lib/grp.py 2008-07-28 22:56:55 UTC (rev 5015) @@ -0,0 +1,77 @@ +""" +"Access to the Unix group database. + +Group entries are reported as 4-tuples containing the following fields +from the group database, in order: + + name - name of the group + passwd - group password (encrypted); often empty + gid - numeric ID of the group + mem - list of members + +The gid is an integer, name and password are strings. (Note that most +users are not explicitly listed as members of the groups they are in +according to the password database. Check both databases to get +complete membership information.) +""" + +__all__ = ['getgrgid', 'getgrnam', 'getgrall'] + +from os import _posix +from java.lang import NullPointerException + +class struct_group(tuple): + """ + grp.struct_group: Results from getgr*() routines. + + This object may be accessed either as a tuple of + (gr_name,gr_passwd,gr_gid,gr_mem) + or via the object attributes as named in the above tuple. + """ + + attrs = ['gr_name', 'gr_passwd', 'gr_gid', 'gr_mem'] + + def __new__(cls, grp): + return tuple.__new__(cls, (grp.gr_name, grp.gr_passwd, grp.gr_gid, + list(grp.getMembers()))) + + def __getattr__(self, attr): + try: + return self[self.attrs.index(attr)] + except ValueError: + raise AttributeError + +def getgrgid(uid): + """ + getgrgid(id) -> tuple + Return the group database entry for the given numeric group ID. If + id is not valid, raise KeyError."}, + """ + try: + return struct_group(_posix.getgrgid(uid)) + except NullPointerException: + raise KeyError, uid + +def getgrnam(name): + """ + getgrnam(name) -> tuple + Return the group database entry for the given group name. If + name is not valid, raise KeyError. + """ + try: + return struct_group(_posix.getgrnam(name)) + except NullPointerException: + raise KeyError, name + +def getgrall(): + """ + getgrall() -> list of tuples + Return a list of all available group database entries, + in arbitrary order. + """ + groups = [] + try: + while True: + groups.append(struct_group(_posix.getgrent())) + except NullPointerException: + return groups Added: branches/asm/Lib/pwd.py =================================================================== --- branches/asm/Lib/pwd.py (rev 0) +++ branches/asm/Lib/pwd.py 2008-07-28 22:56:55 UTC (rev 5015) @@ -0,0 +1,73 @@ +""" +This module provides access to the Unix password database. + +Password database entries are reported as 7-tuples containing the +following items from the password database (see `<pwd.h>'), in order: +pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell. The +uid and gid items are integers, all others are strings. An exception +is raised if the entry asked for cannot be found. +""" + +__all__ = ['getpwuid', 'getpwnam', 'getpwall'] + +from os import _posix +from java.lang import NullPointerException + +class struct_passwd(tuple): + """ + pwd.struct_passwd: Results from getpw*() routines. + + This object may be accessed either as a tuple of + (pw_name,pw_passwd,pw_uid,pw_gid,pw_gecos,pw_dir,pw_shell) + or via the object attributes as named in the above tuple. + """ + + attrs = ['pw_name', 'pw_passwd', 'pw_uid', 'pw_gid', 'pw_gecos', + 'pw_dir', 'pw_shell'] + + def __new__(cls, pwd): + return tuple.__new__(cls, (getattr(pwd, attr) for attr in cls.attrs)) + + def __getattr__(self, attr): + try: + return self[self.attrs.index(attr)] + except ValueError: + raise AttributeError + +def getpwuid(uid): + """ + getpwuid(uid) -> (pw_name,pw_passwd,pw_uid, + pw_gid,pw_gecos,pw_dir,pw_shell) + Return the password database entry for the given numeric user ID. + See pwd.__doc__ for more on password database entries. + """ + try: + return struct_passwd(_posix.getpwuid(uid)) + except NullPointerException: + raise KeyError, uid + +def getpwnam(name): + """ + getpwnam(name) -> (pw_name,pw_passwd,pw_uid, + pw_gid,pw_gecos,pw_dir,pw_shell) + Return the password database entry for the given user name. + See pwd.__doc__ for more on password database entries. + """ + try: + return struct_passwd(_posix.getpwnam(name)) + except NullPointerException: + raise KeyError, name + +def getpwall(): + """ + getpwall() -> list_of_entries + Return a list of all available password database entries, + in arbitrary order. + See pwd.__doc__ for more on password database entries. + """ + entries = [] + try: + while True: + entries.append(struct_passwd(_posix.getpwent())) + except NullPointerException: + return entries Modified: branches/asm/Lib/test/regrtest.py =================================================================== --- branches/asm/Lib/test/regrtest.py 2008-07-28 22:55:35 UTC (rev 5014) +++ branches/asm/Lib/test/regrtest.py 2008-07-28 22:56:55 UTC (rev 5015) @@ -1406,7 +1406,6 @@ test_gdbm test_getargs2 test_gl - test_grp test_hotshot test_imageop test_imgfile @@ -1430,7 +1429,6 @@ test_poll test_profile test_pty - test_pwd test_pyexpat test_resource test_rgbimg This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |