diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-09-18 08:28:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-18 08:28:51 (GMT) |
commit | 0185f34ddcf07b78feb6ac666fbfd4615d26b028 (patch) | |
tree | a27f02f0095d5a7fb1fcbd539114b3a74fb4fcc7 /Lib/pathlib.py | |
parent | 7bdf28265aa371b39f82dfc6562635801aff15a5 (diff) | |
download | cpython-0185f34ddcf07b78feb6ac666fbfd4615d26b028.zip cpython-0185f34ddcf07b78feb6ac666fbfd4615d26b028.tar.gz cpython-0185f34ddcf07b78feb6ac666fbfd4615d26b028.tar.bz2 |
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.
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r-- | Lib/pathlib.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index c2986bd..89dffa5 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -1331,6 +1331,9 @@ class Path(PurePath): if e.errno not in _IGNORED_ERROS: raise return False + except ValueError: + # Non-encodable path + return False return True def is_dir(self): @@ -1345,6 +1348,9 @@ class Path(PurePath): # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) return False + except ValueError: + # Non-encodable path + return False def is_file(self): """ @@ -1359,6 +1365,9 @@ class Path(PurePath): # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) return False + except ValueError: + # Non-encodable path + return False def is_mount(self): """ @@ -1392,6 +1401,9 @@ class Path(PurePath): raise # Path doesn't exist return False + except ValueError: + # Non-encodable path + return False def is_block_device(self): """ @@ -1405,6 +1417,9 @@ class Path(PurePath): # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) return False + except ValueError: + # Non-encodable path + return False def is_char_device(self): """ @@ -1418,6 +1433,9 @@ class Path(PurePath): # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) return False + except ValueError: + # Non-encodable path + return False def is_fifo(self): """ @@ -1431,6 +1449,9 @@ class Path(PurePath): # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) return False + except ValueError: + # Non-encodable path + return False def is_socket(self): """ @@ -1444,6 +1465,9 @@ class Path(PurePath): # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) return False + except ValueError: + # Non-encodable path + return False def expanduser(self): """ Return a new path with expanded ~ and ~user constructs |