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
c0060ca1
Commit
c0060ca1
authored
Dec 16, 2013
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backout a1a05e2724dd: shutil.which(bytes) is a new feature and my patch does not work on Windows
parent
f81d153a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
32 deletions
+10
-32
Doc/library/shutil.rst
Doc/library/shutil.rst
+0
-4
Lib/shutil.py
Lib/shutil.py
+8
-15
Lib/test/test_shutil.py
Lib/test/test_shutil.py
+2
-11
Misc/NEWS
Misc/NEWS
+0
-2
No files found.
Doc/library/shutil.rst
View file @
c0060ca1
...
@@ -352,10 +352,6 @@ Directory and files operations
...
@@ -352,10 +352,6 @@ Directory and files operations
.. versionadded:: 3.3
.. versionadded:: 3.3
.. versionchanged:: 3.4
The :class:`bytes` type is now accepted. If *cmd* type is :class:`bytes`,
the result type is also :class:`bytes`.
.. exception:: Error
.. exception:: Error
...
...
Lib/shutil.py
View file @
c0060ca1
...
@@ -1065,13 +1065,6 @@ def get_terminal_size(fallback=(80, 24)):
...
@@ -1065,13 +1065,6 @@ def get_terminal_size(fallback=(80, 24)):
return
os
.
terminal_size
((
columns
,
lines
))
return
os
.
terminal_size
((
columns
,
lines
))
# 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
):
return
(
os
.
path
.
exists
(
fn
)
and
os
.
access
(
fn
,
mode
)
and
not
os
.
path
.
isdir
(
fn
))
def
which
(
cmd
,
mode
=
os
.
F_OK
|
os
.
X_OK
,
path
=
None
):
def
which
(
cmd
,
mode
=
os
.
F_OK
|
os
.
X_OK
,
path
=
None
):
"""Given a command, mode, and a PATH string, return the path which
"""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
conforms to the given mode on the PATH, or None if there is no such
...
@@ -1082,6 +1075,13 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
...
@@ -1082,6 +1075,13 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
path.
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
):
return
(
os
.
path
.
exists
(
fn
)
and
os
.
access
(
fn
,
mode
)
and
not
os
.
path
.
isdir
(
fn
))
# If we're given a path with a directory part, look it up directly rather
# If we're given a path with a directory part, look it up directly rather
# than referring to PATH directories. This includes checking relative to the
# than referring to PATH directories. This includes checking relative to the
# current directory, e.g. ./script
# current directory, e.g. ./script
...
@@ -1094,11 +1094,6 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
...
@@ -1094,11 +1094,6 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
path
=
os
.
environ
.
get
(
"PATH"
,
os
.
defpath
)
path
=
os
.
environ
.
get
(
"PATH"
,
os
.
defpath
)
if
not
path
:
if
not
path
:
return
None
return
None
if
isinstance
(
cmd
,
bytes
):
path
=
os
.
fsencode
(
path
)
path
=
path
.
split
(
os
.
fsencode
(
os
.
pathsep
))
else
:
path
=
os
.
fsdecode
(
path
)
path
=
path
.
split
(
os
.
pathsep
)
path
=
path
.
split
(
os
.
pathsep
)
if
sys
.
platform
==
"win32"
:
if
sys
.
platform
==
"win32"
:
...
@@ -1108,8 +1103,6 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
...
@@ -1108,8 +1103,6 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
# PATHEXT is necessary to check on Windows.
# PATHEXT is necessary to check on Windows.
pathext
=
os
.
environ
.
get
(
"PATHEXT"
,
""
).
split
(
os
.
pathsep
)
pathext
=
os
.
environ
.
get
(
"PATHEXT"
,
""
).
split
(
os
.
pathsep
)
if
isinstance
(
cmd
,
bytes
):
pathext
=
map
(
os
.
fsencode
,
pathext
)
# See if the given file matches any of the expected path extensions.
# See if the given file matches any of the expected path extensions.
# This will allow us to short circuit when given "python.exe".
# This will allow us to short circuit when given "python.exe".
# If it does match, only test that one, otherwise we have to try
# If it does match, only test that one, otherwise we have to try
...
...
Lib/test/test_shutil.py
View file @
c0060ca1
...
@@ -1326,7 +1326,6 @@ class TestWhich(unittest.TestCase):
...
@@ -1326,7 +1326,6 @@ class TestWhich(unittest.TestCase):
os
.
chmod
(
self
.
temp_file
.
name
,
stat
.
S_IXUSR
)
os
.
chmod
(
self
.
temp_file
.
name
,
stat
.
S_IXUSR
)
self
.
addCleanup
(
self
.
temp_file
.
close
)
self
.
addCleanup
(
self
.
temp_file
.
close
)
self
.
dir
,
self
.
file
=
os
.
path
.
split
(
self
.
temp_file
.
name
)
self
.
dir
,
self
.
file
=
os
.
path
.
split
(
self
.
temp_file
.
name
)
self
.
env_path
=
self
.
dir
def
test_basic
(
self
):
def
test_basic
(
self
):
# Given an EXE in a directory, it should be returned.
# Given an EXE in a directory, it should be returned.
...
@@ -1395,7 +1394,7 @@ class TestWhich(unittest.TestCase):
...
@@ -1395,7 +1394,7 @@ class TestWhich(unittest.TestCase):
def
test_environ_path
(
self
):
def
test_environ_path
(
self
):
with
support
.
EnvironmentVarGuard
()
as
env
:
with
support
.
EnvironmentVarGuard
()
as
env
:
env
[
'PATH'
]
=
self
.
env_path
env
[
'PATH'
]
=
self
.
dir
rv
=
shutil
.
which
(
self
.
file
)
rv
=
shutil
.
which
(
self
.
file
)
self
.
assertEqual
(
rv
,
self
.
temp_file
.
name
)
self
.
assertEqual
(
rv
,
self
.
temp_file
.
name
)
...
@@ -1403,7 +1402,7 @@ class TestWhich(unittest.TestCase):
...
@@ -1403,7 +1402,7 @@ class TestWhich(unittest.TestCase):
base_dir
=
os
.
path
.
dirname
(
self
.
dir
)
base_dir
=
os
.
path
.
dirname
(
self
.
dir
)
with
support
.
change_cwd
(
path
=
self
.
dir
),
\
with
support
.
change_cwd
(
path
=
self
.
dir
),
\
support
.
EnvironmentVarGuard
()
as
env
:
support
.
EnvironmentVarGuard
()
as
env
:
env
[
'PATH'
]
=
self
.
env_path
env
[
'PATH'
]
=
self
.
dir
rv
=
shutil
.
which
(
self
.
file
,
path
=
''
)
rv
=
shutil
.
which
(
self
.
file
,
path
=
''
)
self
.
assertIsNone
(
rv
)
self
.
assertIsNone
(
rv
)
...
@@ -1414,14 +1413,6 @@ class TestWhich(unittest.TestCase):
...
@@ -1414,14 +1413,6 @@ class TestWhich(unittest.TestCase):
self
.
assertIsNone
(
rv
)
self
.
assertIsNone
(
rv
)
class
TestWhichBytes
(
TestWhich
):
def
setUp
(
self
):
TestWhich
.
setUp
(
self
)
self
.
dir
=
os
.
fsencode
(
self
.
dir
)
self
.
file
=
os
.
fsencode
(
self
.
file
)
self
.
temp_file
.
name
=
os
.
fsencode
(
self
.
temp_file
.
name
)
class
TestMove
(
unittest
.
TestCase
):
class
TestMove
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
Misc/NEWS
View file @
c0060ca1
...
@@ -44,8 +44,6 @@ Core and Builtins
...
@@ -44,8 +44,6 @@ Core and Builtins
Library
Library
-------
-------
- Issue #18283: shutil.which() now supports bytes argument, not only text argument.
- Issue #19921: When Path.mkdir() is called with parents=True, any missing
- Issue #19921: When Path.mkdir() is called with parents=True, any missing
parent is created with the default permissions, ignoring the mode argument
parent is created with the default permissions, ignoring the mode argument
(mimicking the POSIX "mkdir -p" command).
(mimicking the POSIX "mkdir -p" command).
...
...
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