summaryrefslogtreecommitdiffstats
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-21 13:01:34 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-21 13:01:34 (GMT)
commit5b987c2e68947732b673d6c8d6117011730d28f0 (patch)
tree09c808b4bd0c31d47f3785cd35e0f167340b0217 /Lib/shutil.py
parent5a95977c71d19d6aed32b0a4721d5e9ef4888efe (diff)
parent014791f8484036b1c0040ea0de7a6a4c05f0aeed (diff)
downloadcpython-5b987c2e68947732b673d6c8d6117011730d28f0.zip
cpython-5b987c2e68947732b673d6c8d6117011730d28f0.tar.gz
cpython-5b987c2e68947732b673d6c8d6117011730d28f0.tar.bz2
Issue #16993: shutil.which() now preserves the case of the path and extension
on Windows.
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index b1e3017..31969ff 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -1092,10 +1092,12 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
# See if the given file matches any of the expected path extensions.
# This will allow us to short circuit when given "python.exe".
- matches = [cmd for ext in pathext if cmd.lower().endswith(ext.lower())]
# If it does match, only test that one, otherwise we have to try
# others.
- files = [cmd] if matches else [cmd + ext.lower() for ext in pathext]
+ if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
+ files = [cmd]
+ else:
+ files = [cmd + ext for ext in pathext]
else:
# On other platforms you don't have things like PATHEXT to tell you
# what file suffixes are executable, so just pass on cmd as-is.
@@ -1103,9 +1105,9 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
seen = set()
for dir in path:
- dir = os.path.normcase(dir)
- if not dir in seen:
- seen.add(dir)
+ normdir = os.path.normcase(dir)
+ if not normdir in seen:
+ seen.add(normdir)
for thefile in files:
name = os.path.join(dir, thefile)
if _access_check(name, mode):