Author: Matti Picus <matti.pi...@gmail.com> Branch: py3.6 Changeset: r98205:95e1a6902283 Date: 2019-12-01 21:53 +0200 http://bitbucket.org/pypy/pypy/changeset/95e1a6902283/
Log: test, add posix.getgrouplist (part of issue 2375) diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py --- a/pypy/module/posix/interp_posix.py +++ b/pypy/module/posix/interp_posix.py @@ -1813,6 +1813,23 @@ except OSError as e: raise wrap_oserror(space, e, eintr_retry=False) +@unwrap_spec(username='text', gid=c_gid_t) +def getgrouplist(space, username, gid): + """ + getgrouplist(user, group) -> list of groups to which a user belongs + + Returns a list of groups to which a user belongs. + + user: username to lookup + group: base group id of the user + """ + try: + groups = rposix.getgrouplist(username, gid) + return space.newlist([space.newint(g) for g in groups]) + except OSError as e: + raise wrap_oserror(space, e) + + def getpgrp(space): """ getpgrp() -> pgrp diff --git a/pypy/module/posix/moduledef.py b/pypy/module/posix/moduledef.py --- a/pypy/module/posix/moduledef.py +++ b/pypy/module/posix/moduledef.py @@ -207,6 +207,7 @@ interpleveldefs['sync'] = 'interp_posix.sync' interpleveldefs['get_blocking'] = 'interp_posix.get_blocking' interpleveldefs['set_blocking'] = 'interp_posix.set_blocking' + interpleveldefs['getgrouplist'] = 'interp_posix.getgrouplist' if hasattr(rposix, 'getpriority'): interpleveldefs['getpriority'] = 'interp_posix.getpriority' diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py --- a/pypy/module/posix/test/test_posix2.py +++ b/pypy/module/posix/test/test_posix2.py @@ -1369,7 +1369,6 @@ raises(OSError, posix.get_blocking, 1234567) raises(OSError, posix.set_blocking, 1234567, True) - if sys.platform != 'win32': def test_sendfile(self): import _socket, posix s1, s2 = _socket.socketpair() @@ -1393,6 +1392,13 @@ fd = posix.open(memoryview(pdir), posix.O_RDONLY) posix.close(fd) + def test_getgrouplist(self): + import posix, getpass + gid = posix.getgid() + user = getpass.getuser() + groups = posix.getgrouplist(user, gid) + assert gid in groups + if sys.platform.startswith('linux'): def test_sendfile_no_offset(self): import _socket, posix _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit