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
00231d06
Commit
00231d06
authored
Jun 23, 2012
by
Philip Jenvey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small refactor and PEP8 line width/docstring
parent
7930c240
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
Lib/shutil.py
Lib/shutil.py
+13
-9
No files found.
Lib/shutil.py
View file @
00231d06
...
...
@@ -1037,17 +1037,20 @@ def get_terminal_size(fallback=(80, 24)):
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 file.
`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result of
os.environ.get("PATH"), or can be overridden with a custom search path."""
conforms to the given mode on the PATH, or None if there is no such
file.
`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
of os.environ.get("PATH"), or can be overridden with a custom search
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
):
if
(
os
.
path
.
exists
(
fn
)
and
os
.
access
(
fn
,
mode
)
and
not
os
.
path
.
isdir
(
fn
)):
return
True
return
False
return
(
os
.
path
.
exists
(
fn
)
and
os
.
access
(
fn
,
mode
)
and
not
os
.
path
.
isdir
(
fn
))
# Short circuit. If we're given a full path which matches the mode
# and it exists, we're done here.
...
...
@@ -1066,8 +1069,9 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
# 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
+
ext
.
lower
()
for
ext
in
pathext
]
if
not
matches
else
[
cmd
]
# 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
]
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.
...
...
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