mirror of
https://github.com/python/cpython.git
synced 2025-09-08 18:01:44 +00:00
Replace pathlib._abc.PathModuleBase.splitroot()
with splitdrive()
(#114065)
This allows users of the `pathlib-abc` PyPI package to use `posixpath` or `ntpath` as a path module in versions of Python lacking `os.path.splitroot()` (3.11 and before).
This commit is contained in:
parent
ca6cf56330
commit
4de4e654e5
2 changed files with 9 additions and 11 deletions
|
@ -165,12 +165,11 @@ class PathModuleBase:
|
||||||
"""
|
"""
|
||||||
self._unsupported('split()')
|
self._unsupported('split()')
|
||||||
|
|
||||||
def splitroot(self, path):
|
def splitdrive(self, path):
|
||||||
"""Split the pathname path into a 3-item tuple (drive, root, tail),
|
"""Split the path into a 2-item tuple (drive, tail), where *drive* is
|
||||||
where *drive* is a device name or mount point, *root* is a string of
|
a device name or mount point, and *tail* is everything after the
|
||||||
separators after the drive, and *tail* is everything after the root.
|
drive. Either part may be empty."""
|
||||||
Any part may be empty."""
|
self._unsupported('splitdrive()')
|
||||||
self._unsupported('splitroot()')
|
|
||||||
|
|
||||||
def normcase(self, path):
|
def normcase(self, path):
|
||||||
"""Normalize the case of the path."""
|
"""Normalize the case of the path."""
|
||||||
|
@ -227,18 +226,17 @@ class PurePathBase:
|
||||||
@property
|
@property
|
||||||
def drive(self):
|
def drive(self):
|
||||||
"""The drive prefix (letter or UNC path), if any."""
|
"""The drive prefix (letter or UNC path), if any."""
|
||||||
return self.pathmod.splitroot(self._raw_path)[0]
|
return self.pathmod.splitdrive(self.anchor)[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def root(self):
|
def root(self):
|
||||||
"""The root of the path, if any."""
|
"""The root of the path, if any."""
|
||||||
return self.pathmod.splitroot(self._raw_path)[1]
|
return self.pathmod.splitdrive(self.anchor)[1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def anchor(self):
|
def anchor(self):
|
||||||
"""The concatenation of the drive and root, or ''."""
|
"""The concatenation of the drive and root, or ''."""
|
||||||
drive, root, _ = self.pathmod.splitroot(self._raw_path)
|
return self._stack[0]
|
||||||
return drive + root
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
|
|
@ -27,7 +27,7 @@ class PathModuleBaseTest(unittest.TestCase):
|
||||||
m.sep
|
m.sep
|
||||||
self.assertRaises(e, m.join, 'foo')
|
self.assertRaises(e, m.join, 'foo')
|
||||||
self.assertRaises(e, m.split, 'foo')
|
self.assertRaises(e, m.split, 'foo')
|
||||||
self.assertRaises(e, m.splitroot, 'foo')
|
self.assertRaises(e, m.splitdrive, 'foo')
|
||||||
self.assertRaises(e, m.normcase, 'foo')
|
self.assertRaises(e, m.normcase, 'foo')
|
||||||
self.assertRaises(e, m.isabs, 'foo')
|
self.assertRaises(e, m.isabs, 'foo')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue