New submission from James Skinner: When using the Path class in Lib/pathlib.py under Windows, calling p.owner() or p.group() fails with an ImportError due to importing the pwd and grp modules respectively, as neither of those exist. The documentation doesn't mention this behaviour.
The precedent for handling this is set by os.stat(), which simply sets the st_uid and st_gid fields to 0 under Windows, and this behaviour underlies p.stat(). Therefore both p.owner() and p.group() should return 0 under Windows as well. >>> p = Path("foo.py") >>> p.stat() os.stat_result(st_mode=33206, st_ino=434125405408, st_dev=318314347, st_nlink=1, st_uid=0, st_gid=0, st_size=40, st_atime=1392076800, st_mtime=1392084010, st_ctime=1392083969) >>> p.owner() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\Python34\Lib\pathlib.py", line 1051, in owner import pwd ImportError: No module named 'pwd' >>> p.group() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\Python34\Lib\pathlib.py", line 1058, in group import grp ImportError: No module named 'grp' After the patch, the behaviour is: >>> p = Path("foo.py") >>> p.stat() os.stat_result(st_mode=33206, st_ino=434125405408, st_dev=318314347, st_nlink=1, st_uid=0, st_gid=0, st_size=40, st_atime=1392076800, st_mtime=1392084010, st_ctime=1392083969) >>> p.owner() 0 >>> p.group() 0 >>> p.owner() == p.stat().st_uid True >>> p.group() == p.stat().st_gid True The supplied patch just creates overriden versions of owner() and group() that return 0 under the WindowsPath class. ---------- components: Library (Lib) files: win_owner_group_error_fix.patch keywords: patch messages: 210896 nosy: spiralx priority: normal severity: normal status: open title: pathlib.owner() and pathlib.group() raise ImportError on Windows versions: Python 3.4 Added file: http://bugs.python.org/file34033/win_owner_group_error_fix.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20589> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com