Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
014791f8
Commit
014791f8
authored
Jan 21, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16993: shutil.which() now preserves the case of the path and extension
on Windows.
parent
85da624e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
9 deletions
+15
-9
Doc/library/shutil.rst
Doc/library/shutil.rst
+1
-1
Lib/shutil.py
Lib/shutil.py
+7
-5
Lib/test/test_shutil.py
Lib/test/test_shutil.py
+4
-3
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/shutil.rst
View file @
014791f8
...
...
@@ -335,7 +335,7 @@ Directory and files operations
directories. For example, on Windows::
>>> shutil.which("python")
'
c:\\p
ython33\\python.exe'
'
C:\\P
ython33\\python.exe'
.. versionadded:: 3.3
...
...
Lib/shutil.py
View file @
014791f8
...
...
@@ -1093,10 +1093,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.
...
...
@@ -1104,9 +1106,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
)
norm
dir
=
os
.
path
.
normcase
(
dir
)
if
not
norm
dir
in
seen
:
seen
.
add
(
norm
dir
)
for
thefile
in
files
:
name
=
os
.
path
.
join
(
dir
,
thefile
)
if
_access_check
(
name
,
mode
):
...
...
Lib/test/test_shutil.py
View file @
014791f8
...
...
@@ -1269,12 +1269,13 @@ class TestShutil(unittest.TestCase):
class
TestWhich
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
temp_dir
=
tempfile
.
mkdtemp
()
self
.
temp_dir
=
tempfile
.
mkdtemp
(
prefix
=
"Tmp"
)
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
temp_dir
,
True
)
# Give the temp_file an ".exe" suffix for all.
# It's needed on Windows and not harmful on other platforms.
self
.
temp_file
=
tempfile
.
NamedTemporaryFile
(
dir
=
self
.
temp_dir
,
suffix
=
".exe"
)
prefix
=
"Tmp"
,
suffix
=
".Exe"
)
os
.
chmod
(
self
.
temp_file
.
name
,
stat
.
S_IXUSR
)
self
.
addCleanup
(
self
.
temp_file
.
close
)
self
.
dir
,
self
.
file
=
os
.
path
.
split
(
self
.
temp_file
.
name
)
...
...
@@ -1317,7 +1318,7 @@ class TestWhich(unittest.TestCase):
# Ask for the file without the ".exe" extension, then ensure that
# it gets found properly with the extension.
rv
=
shutil
.
which
(
self
.
temp_file
.
name
[:
-
4
],
path
=
self
.
dir
)
self
.
assertEqual
(
self
.
temp_file
.
name
,
rv
)
self
.
assertEqual
(
rv
,
self
.
temp_file
.
name
[:
-
4
]
+
".exe"
)
class
TestMove
(
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
014791f8
...
...
@@ -150,6 +150,9 @@ Core and Builtins
Library
-------
-
Issue
#
16993
:
shutil
.
which
()
now
preserves
the
case
of
the
path
and
extension
on
Windows
.
-
Issue
#
16992
:
On
Windows
in
signal
.
set_wakeup_fd
,
validate
the
file
descriptor
argument
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment