Author spiralx
Recipients spiralx
Date 2014-02-11.03:25:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1392089109.39.0.748049843739.issue20589@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-02-11 03:25:09spiralxsetrecipients: + spiralx
2014-02-11 03:25:09spiralxsetmessageid: <1392089109.39.0.748049843739.issue20589@psf.upfronthosting.co.za>
2014-02-11 03:25:09spiralxlinkissue20589 messages
2014-02-11 03:25:07spiralxcreate