bpo-33721: Make some os.path functions and pathlib.Path methods be tolerant to invalid paths. (#7695)

Such functions as os.path.exists(), os.path.lexists(), os.path.isdir(),
os.path.isfile(), os.path.islink(), and os.path.ismount() now return False
instead of raising ValueError or its subclasses UnicodeEncodeError
and UnicodeDecodeError for paths that contain characters or bytes
unrepresentative at the OS level.
This commit is contained in:
Serhiy Storchaka 2018-09-18 11:28:51 +03:00 committed by GitHub
parent 7bdf28265a
commit 0185f34ddc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 181 additions and 54 deletions

View file

@ -229,7 +229,7 @@ def islink(path):
"""
try:
st = os.lstat(path)
except (OSError, AttributeError):
except (OSError, ValueError, AttributeError):
return False
return stat.S_ISLNK(st.st_mode)
@ -239,7 +239,7 @@ def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
st = os.lstat(path)
except OSError:
except (OSError, ValueError):
return False
return True
@ -524,7 +524,7 @@ else: # use native Windows method on Windows
"""Return the absolute version of a path."""
try:
return _getfullpathname(path)
except OSError:
except (OSError, ValueError):
return _abspath_fallback(path)
# realpath is a no-op on systems without islink support