gh-118507 : Refactor nt._path_is* to improve applicability for other cases (GH-118755)

This commit is contained in:
Nice Zombies 2024-05-21 22:36:36 +02:00 committed by GitHub
parent de8f530841
commit b64182550f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 528 additions and 440 deletions

View file

@ -288,21 +288,6 @@ def dirname(p):
return split(p)[0]
# Is a path a junction?
if hasattr(os.stat_result, 'st_reparse_tag'):
def isjunction(path):
"""Test whether a path is a junction"""
try:
st = os.lstat(path)
except (OSError, ValueError, AttributeError):
return False
return st.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT
else:
# Use genericpath.isjunction as imported above
pass
# Is a path a mount point?
# Any drive letter root (eg c:\)
# Any share UNC (eg \\server\share)
@ -911,13 +896,15 @@ def commonpath(paths):
try:
# The isdir(), isfile(), islink() and exists() implementations in
# genericpath use os.stat(). This is overkill on Windows. Use simpler
# The isdir(), isfile(), islink(), exists() and lexists() implementations
# in genericpath use os.stat(). This is overkill on Windows. Use simpler
# builtin functions if they are available.
from nt import _path_isdir as isdir
from nt import _path_isfile as isfile
from nt import _path_islink as islink
from nt import _path_isjunction as isjunction
from nt import _path_exists as exists
from nt import _path_lexists as lexists
except ImportError:
# Use genericpath.* as imported above
pass