@@ -447,6 +447,20 @@ def symlink(a, b, target_is_directory):
447
447
def readlink (self , path ):
448
448
return os .readlink (path )
449
449
450
+ def owner (self , path ):
451
+ try :
452
+ import pwd
453
+ return pwd .getpwuid (self .stat (path ).st_uid ).pw_name
454
+ except ImportError :
455
+ raise NotImplementedError ("Path.owner() is unsupported on this system" )
456
+
457
+ def group (self , path ):
458
+ try :
459
+ import grp
460
+ return grp .getgrgid (self .stat (path ).st_gid ).gr_name
461
+ except ImportError :
462
+ raise NotImplementedError ("Path.group() is unsupported on this system" )
463
+
450
464
451
465
_normal_accessor = _NormalAccessor ()
452
466
@@ -1202,15 +1216,13 @@ def owner(self):
1202
1216
"""
1203
1217
Return the login name of the file owner.
1204
1218
"""
1205
- import pwd
1206
- return pwd .getpwuid (self .stat ().st_uid ).pw_name
1219
+ return self ._accessor .owner (self )
1207
1220
1208
1221
def group (self ):
1209
1222
"""
1210
1223
Return the group name of the file gid.
1211
1224
"""
1212
- import grp
1213
- return grp .getgrgid (self .stat ().st_gid ).gr_name
1225
+ return self ._accessor .group (self )
1214
1226
1215
1227
def open (self , mode = 'r' , buffering = - 1 , encoding = None ,
1216
1228
errors = None , newline = None ):
@@ -1544,11 +1556,5 @@ class WindowsPath(Path, PureWindowsPath):
1544
1556
"""
1545
1557
__slots__ = ()
1546
1558
1547
- def owner (self ):
1548
- raise NotImplementedError ("Path.owner() is unsupported on this system" )
1549
-
1550
- def group (self ):
1551
- raise NotImplementedError ("Path.group() is unsupported on this system" )
1552
-
1553
1559
def is_mount (self ):
1554
1560
raise NotImplementedError ("Path.is_mount() is unsupported on this system" )
0 commit comments