summaryrefslogtreecommitdiffstats
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-12-16 22:39:40 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-12-16 22:39:40 (GMT)
commit1d006a2c0e9831a936033304f31e5abc12f60042 (patch)
treedd864eda4680aea76557ee48b8ab8261d7c06958 /Lib/shutil.py
parent711e27cd503933cfe7a42d931d2b69dc79014ae0 (diff)
downloadcpython-1d006a2c0e9831a936033304f31e5abc12f60042.zip
cpython-1d006a2c0e9831a936033304f31e5abc12f60042.tar.gz
cpython-1d006a2c0e9831a936033304f31e5abc12f60042.tar.bz2
Backout a1a05e2724dd: shutil.which(bytes) is a new feature and my patch does not work on Windows
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py23
1 files changed, 8 insertions, 15 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index c80a5cc..502bb67 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -1065,13 +1065,6 @@ def get_terminal_size(fallback=(80, 24)):
return os.terminal_size((columns, lines))
-# Check that a given file can be accessed with the correct mode.
-# Additionally check that `file` is not a directory, as on Windows
-# directories pass the os.access check.
-def _access_check(fn, mode):
- return (os.path.exists(fn) and os.access(fn, mode)
- and not os.path.isdir(fn))
-
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
"""Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
@@ -1082,6 +1075,13 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
path.
"""
+ # Check that a given file can be accessed with the correct mode.
+ # Additionally check that `file` is not a directory, as on Windows
+ # directories pass the os.access check.
+ def _access_check(fn, mode):
+ return (os.path.exists(fn) and os.access(fn, mode)
+ and not os.path.isdir(fn))
+
# If we're given a path with a directory part, look it up directly rather
# than referring to PATH directories. This includes checking relative to the
# current directory, e.g. ./script
@@ -1094,12 +1094,7 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
path = os.environ.get("PATH", os.defpath)
if not path:
return None
- if isinstance(cmd, bytes):
- path = os.fsencode(path)
- path = path.split(os.fsencode(os.pathsep))
- else:
- path = os.fsdecode(path)
- path = path.split(os.pathsep)
+ path = path.split(os.pathsep)
if sys.platform == "win32":
# The current directory takes precedence on Windows.
@@ -1108,8 +1103,6 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
# PATHEXT is necessary to check on Windows.
pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
- if isinstance(cmd, bytes):
- pathext = map(os.fsencode, pathext)
# See if the given file matches any of the expected path extensions.
# This will allow us to short circuit when given "python.exe".
# If it does match, only test that one, otherwise we have to try