gh-117114: Make os.path.isdevdrive available on all platforms (GH-117115)

This commit is contained in:
Nice Zombies 2024-03-25 23:55:11 +01:00 committed by GitHub
parent c2276176d5
commit 0821923aa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 39 additions and 57 deletions

View file

@ -7,8 +7,8 @@ import os
import stat
__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
'getsize', 'isdir', 'isfile', 'islink', 'samefile', 'sameopenfile',
'samestat']
'getsize', 'isdevdrive', 'isdir', 'isfile', 'isjunction', 'islink',
'lexists', 'samefile', 'sameopenfile', 'samestat']
# Does a path exist?
@ -22,6 +22,15 @@ def exists(path):
return True
# Being true for dangling symbolic links is also useful.
def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
os.lstat(path)
except (OSError, ValueError):
return False
return True
# This follows symbolic links, so both islink() and isdir() can be true
# for the same path on systems that support symlinks
def isfile(path):
@ -57,6 +66,21 @@ def islink(path):
return stat.S_ISLNK(st.st_mode)
# Is a path a junction?
def isjunction(path):
"""Test whether a path is a junction
Junctions are not supported on the current platform"""
os.fspath(path)
return False
def isdevdrive(path):
"""Determines whether the specified path is on a Windows Dev Drive.
Dev Drives are not supported on the current platform"""
os.fspath(path)
return False
def getsize(filename):
"""Return the size of a file, reported by os.stat()."""
return os.stat(filename).st_size