23
23
path_repr = path_type.__fspath__(path)
24
24
except AttributeError:
25
if hasattr(path_type, '__fspath__'):
25
if hasattr(path_type, "__fspath__"):
28
raise TypeError("expected str, bytes or os.PathLike object, "
29
"not " + path_type.__name__)
28
raise TypeError("expected str, bytes or os.PathLike object, " "not " + path_type.__name__)
30
29
if isinstance(path_repr, (str, bytes)):
33
raise TypeError("expected {}.__fspath__() to return str or bytes, "
34
"not {}".format(path_type.__name__,
35
type(path_repr).__name__))
33
"expected {}.__fspath__() to return str or bytes, "
34
"not {}".format(path_type.__name__, type(path_repr).__name__)
37
37
# Check that a given file can be accessed with the correct mode.
38
38
# Additionally check that `file` is not a directory, as on Windows
39
39
# directories pass the os.access check.
40
40
def _access_check(fn, mode):
41
return (os.path.exists(fn) and os.access(fn, mode) and not os.path.isdir(fn))
41
return os.path.exists(fn) and os.access(fn, mode) and not os.path.isdir(fn)
43
43
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
44
44
"""Given a command, mode, and a PATH string, return the path which