aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/posixpath.py
diff options
context:
space:
mode:
authorNice Zombies <nineteendo19d0@gmail.com>2024-05-24 20:04:17 +0200
committerGitHub <noreply@github.com>2024-05-24 19:04:17 +0100
commit96b392df303b2cfaea823afcb462c0b455704ce8 (patch)
tree70a9efffceeb22ccf24dd2afb1c3edeada732c96 /Lib/posixpath.py
parentf0ed1863bd7a0b9d021fb59e156663a7ec553f0e (diff)
downloadcpython-96b392df303b2cfaea823afcb462c0b455704ce8.tar.gz
cpython-96b392df303b2cfaea823afcb462c0b455704ce8.zip
gh-118263: Add additional arguments to path_t (Argument Clinic type) in posixmodule (GH-118355)
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r--Lib/posixpath.py41
1 files changed, 5 insertions, 36 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index c04c628de55..47b2aa572e5 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -135,18 +135,12 @@ def splitdrive(p):
try:
- from posix import _path_splitroot_ex
+ from posix import _path_splitroot_ex as splitroot
except ImportError:
def splitroot(p):
- """Split a pathname into drive, root and tail. On Posix, drive is always
- empty; the root may be empty, a single slash, or two slashes. The tail
- contains anything after the root. For example:
-
- splitroot('foo/bar') == ('', '', 'foo/bar')
- splitroot('/foo/bar') == ('', '/', 'foo/bar')
- splitroot('//foo/bar') == ('', '//', 'foo/bar')
- splitroot('///foo/bar') == ('', '/', '//foo/bar')
- """
+ """Split a pathname into drive, root and tail.
+
+ The tail contains anything after the root."""
p = os.fspath(p)
if isinstance(p, bytes):
sep = b'/'
@@ -164,23 +158,6 @@ except ImportError:
# Precisely two leading slashes, e.g.: '//foo'. Implementation defined per POSIX, see
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
return empty, p[:2], p[2:]
-else:
- def splitroot(p):
- """Split a pathname into drive, root and tail. On Posix, drive is always
- empty; the root may be empty, a single slash, or two slashes. The tail
- contains anything after the root. For example:
-
- splitroot('foo/bar') == ('', '', 'foo/bar')
- splitroot('/foo/bar') == ('', '/', 'foo/bar')
- splitroot('//foo/bar') == ('', '//', 'foo/bar')
- splitroot('///foo/bar') == ('', '/', '//foo/bar')
- """
- p = os.fspath(p)
- if isinstance(p, bytes):
- # Optimisation: the drive is always empty
- _, root, tail = _path_splitroot_ex(os.fsdecode(p))
- return b'', os.fsencode(root), os.fsencode(tail)
- return _path_splitroot_ex(p)
# Return the tail (basename) part of a path, same as split(path)[1].
@@ -363,7 +340,7 @@ def expandvars(path):
# if it contains symbolic links!
try:
- from posix import _path_normpath
+ from posix import _path_normpath as normpath
except ImportError:
def normpath(path):
@@ -394,14 +371,6 @@ except ImportError:
path = initial_slashes + sep.join(comps)
return path or dot
-else:
- def normpath(path):
- """Normalize path, eliminating double slashes, etc."""
- path = os.fspath(path)
- if isinstance(path, bytes):
- return os.fsencode(_path_normpath(os.fsdecode(path))) or b"."
- return _path_normpath(path) or "."
-
def abspath(path):
"""Return an absolute path."""