cpython: 7b51568cfbae (original) (raw)

Mercurial > cpython

changeset 81669:7b51568cfbae

Issue #16957: shutil.which() no longer searches a bare file name in the current directory on Unix and no longer searches a relative file path with a directory part in PATH directories. Patch by Thomas Kluyver. [#16957]

Serhiy Storchaka storchaka@gmail.com
date Wed, 23 Jan 2013 10:45:33 +0200
parents 9a0cd5363c2a(current diff)f18d11ab53a0(diff)
children 02e7da4c4fe3
files Lib/shutil.py Lib/test/test_shutil.py Misc/NEWS
diffstat 3 files changed, 40 insertions(+), 12 deletions(-)[+] [-] Lib/shutil.py 11 Lib/test/test_shutil.py 37 Misc/NEWS 4

line wrap: on

line diff

--- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1076,10 +1076,13 @@ def which(cmd, mode=os.F_OK | os.X_OK, p return (os.path.exists(fn) and os.access(fn, mode) and not os.path.isdir(fn))

path = (path or os.environ.get("PATH", os.defpath)).split(os.pathsep)

--- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1296,11 +1296,36 @@ class TestWhich(unittest.TestCase): rv = shutil.which(self.file, path=self.dir) self.assertEqual(rv, self.temp_file.name)

+

+

def test_non_matching_mode(self): # Set the file read-only and ask for writeable files. @@ -1308,15 +1333,11 @@ class TestWhich(unittest.TestCase): rv = shutil.which(self.file, path=self.dir, mode=os.W_OK) self.assertIsNone(rv)

def test_nonexistent_file(self): # Return None when no matching executable file is found on the path.

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -220,6 +220,10 @@ Core and Builtins Library ------- +- Issue #16957: shutil.which() no longer searches a bare file name in the