aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/posixpath.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committerDaniil Cherednik <dcherednik@ydb.tech>2024-02-14 14:26:16 +0000
commit31f2a419764a8ba77c2a970cfc80056c6cd06756 (patch)
treec1995d239eba8571cefc640f6648e1d5dd4ce9e2 /contrib/tools/python3/src/Lib/posixpath.py
parentfe2ef02b38d9c85d80060963b265a1df9f38c3bb (diff)
downloadydb-31f2a419764a8ba77c2a970cfc80056c6cd06756.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Lib/posixpath.py')
-rw-r--r--contrib/tools/python3/src/Lib/posixpath.py61
1 files changed, 40 insertions, 21 deletions
diff --git a/contrib/tools/python3/src/Lib/posixpath.py b/contrib/tools/python3/src/Lib/posixpath.py
index 5b4d78bca0..e4f155e41a 100644
--- a/contrib/tools/python3/src/Lib/posixpath.py
+++ b/contrib/tools/python3/src/Lib/posixpath.py
@@ -28,14 +28,14 @@ import stat
import genericpath
from genericpath import *
-__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
+__all__ = ["normcase","isabs","join","splitdrive","splitroot","split","splitext",
"basename","dirname","commonprefix","getsize","getmtime",
"getatime","getctime","islink","exists","lexists","isdir","isfile",
"ismount", "expanduser","expandvars","normpath","abspath",
"samefile","sameopenfile","samestat",
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
"devnull","realpath","supports_unicode_filenames","relpath",
- "commonpath"]
+ "commonpath", "isjunction"]
def _get_sep(path):
@@ -135,6 +135,35 @@ def splitdrive(p):
return p[:0], p
+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):
+ sep = b'/'
+ empty = b''
+ else:
+ sep = '/'
+ empty = ''
+ if p[:1] != sep:
+ # Relative path, e.g.: 'foo'
+ return empty, empty, p
+ elif p[1:2] != sep or p[2:3] == sep:
+ # Absolute path, e.g.: '/foo', '///foo', '////foo', etc.
+ return empty, sep, p[1:]
+ else:
+ # 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:]
+
+
# Return the tail (basename) part of a path, same as split(path)[1].
def basename(p):
@@ -158,16 +187,14 @@ def dirname(p):
return head
-# Is a path a symbolic link?
-# This will always return false on systems where os.lstat doesn't exist.
+# Is a path a junction?
+
+def isjunction(path):
+ """Test whether a path is a junction
+ Junctions are not a part of posix semantics"""
+ os.fspath(path)
+ return False
-def islink(path):
- """Test whether a path is a symbolic link"""
- try:
- st = os.lstat(path)
- except (OSError, ValueError, AttributeError):
- return False
- return stat.S_ISLNK(st.st_mode)
# Being true for dangling symbolic links is also useful.
@@ -362,13 +389,7 @@ except ImportError:
dotdot = '..'
if path == empty:
return dot
- initial_slashes = path.startswith(sep)
- # POSIX allows one or two initial slashes, but treats three or more
- # as single slash.
- # (see https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13)
- if (initial_slashes and
- path.startswith(sep*2) and not path.startswith(sep*3)):
- initial_slashes = 2
+ _, initial_slashes, path = splitroot(path)
comps = path.split(sep)
new_comps = []
for comp in comps:
@@ -380,9 +401,7 @@ except ImportError:
elif new_comps:
new_comps.pop()
comps = new_comps
- path = sep.join(comps)
- if initial_slashes:
- path = sep*initial_slashes + path
+ path = initial_slashes + sep.join(comps)
return path or dot
else: