FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-39901: Move `pathlib.Path.owner()` and `group()` implementations into the path accessor by barneygale · Pull Request #18844 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
26 changes: 16 additions & 10 deletions Lib/pathlib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,20 @@ def symlink(a, b, target_is_directory):
def readlink(self, path):
return os.readlink(path)

def owner(self, path):
try:
import pwd
return pwd.getpwuid(self.stat(path).st_uid).pw_name
except ImportError:
raise NotImplementedError("Path.owner() is unsupported on this system")

def group(self, path):
try:
import grp
return grp.getgrgid(self.stat(path).st_gid).gr_name
except ImportError:
raise NotImplementedError("Path.group() is unsupported on this system")


_normal_accessor = _NormalAccessor()

Expand Down Expand Up @@ -1209,15 +1223,13 @@ def owner(self):
"""
Return the login name of the file owner.
"""
import pwd
return pwd.getpwuid(self.stat().st_uid).pw_name
return self._accessor.owner(self)

def group(self):
"""
Return the group name of the file gid.
"""
import grp
return grp.getgrgid(self.stat().st_gid).gr_name
return self._accessor.group(self)

def open(self, mode='r', buffering=-1, encoding=None,
errors=None, newline=None):
Expand Down Expand Up @@ -1575,11 +1587,5 @@ class WindowsPath(Path, PureWindowsPath):
"""
__slots__ = ()

def owner(self):
raise NotImplementedError("Path.owner() is unsupported on this system")

def group(self):
raise NotImplementedError("Path.group() is unsupported on this system")

def is_mount(self):
raise NotImplementedError("Path.is_mount() is unsupported on this system")

Back | FazBrowse Home | New Git URL