diff options
author | Philip Jenvey <pjenvey@underboss.org> | 2012-06-23 22:54:38 (GMT) |
---|---|---|
committer | Philip Jenvey <pjenvey@underboss.org> | 2012-06-23 22:54:38 (GMT) |
commit | 88bc0d2640a412563b41586d6b6e13b53ce25997 (patch) | |
tree | 38dd40e0ed565c062aa2b364fdbd97e88290827d | |
parent | 66a3a7ed107b8148d21d8d2e5cbf5d3940be8297 (diff) | |
download | cpython-88bc0d2640a412563b41586d6b6e13b53ce25997.zip cpython-88bc0d2640a412563b41586d6b6e13b53ce25997.tar.gz cpython-88bc0d2640a412563b41586d6b6e13b53ce25997.tar.bz2 |
small refactor and PEP8 line width/docstring
-rw-r--r-- | Lib/shutil.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index c41046a..f743d05 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -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. |