Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
fffb96ba
Kaydet (Commit)
fffb96ba
authored
Ara 16, 2013
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #18283: shutil.which() now supports bytes argument, not only text argument.
üst
a4275b27
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
10 deletions
+32
-10
shutil.rst
Doc/library/shutil.rst
+4
-0
shutil.py
Lib/shutil.py
+15
-8
test_shutil.py
Lib/test/test_shutil.py
+11
-2
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/shutil.rst
Dosyayı görüntüle @
fffb96ba
...
...
@@ -352,6 +352,10 @@ Directory and files operations
.. 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
...
...
Lib/shutil.py
Dosyayı görüntüle @
fffb96ba
...
...
@@ -1065,6 +1065,13 @@ def get_terminal_size(fallback=(80, 24)):
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
):
"""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
...
...
@@ -1075,13 +1082,6 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
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
# than referring to PATH directories. This includes checking relative to the
# current directory, e.g. ./script
...
...
@@ -1094,7 +1094,12 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
path
=
os
.
environ
.
get
(
"PATH"
,
os
.
defpath
)
if
not
path
:
return
None
path
=
path
.
split
(
os
.
pathsep
)
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
)
if
sys
.
platform
==
"win32"
:
# The current directory takes precedence on Windows.
...
...
@@ -1103,6 +1108,8 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
# PATHEXT is necessary to check on Windows.
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.
# This will allow us to short circuit when given "python.exe".
# If it does match, only test that one, otherwise we have to try
...
...
Lib/test/test_shutil.py
Dosyayı görüntüle @
fffb96ba
...
...
@@ -1326,6 +1326,7 @@ class TestWhich(unittest.TestCase):
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
)
self
.
env_path
=
self
.
dir
def
test_basic
(
self
):
# Given an EXE in a directory, it should be returned.
...
...
@@ -1394,7 +1395,7 @@ class TestWhich(unittest.TestCase):
def
test_environ_path
(
self
):
with
support
.
EnvironmentVarGuard
()
as
env
:
env
[
'PATH'
]
=
self
.
dir
env
[
'PATH'
]
=
self
.
env_path
rv
=
shutil
.
which
(
self
.
file
)
self
.
assertEqual
(
rv
,
self
.
temp_file
.
name
)
...
...
@@ -1402,7 +1403,7 @@ class TestWhich(unittest.TestCase):
base_dir
=
os
.
path
.
dirname
(
self
.
dir
)
with
support
.
change_cwd
(
path
=
self
.
dir
),
\
support
.
EnvironmentVarGuard
()
as
env
:
env
[
'PATH'
]
=
self
.
dir
env
[
'PATH'
]
=
self
.
env_path
rv
=
shutil
.
which
(
self
.
file
,
path
=
''
)
self
.
assertIsNone
(
rv
)
...
...
@@ -1413,6 +1414,14 @@ class TestWhich(unittest.TestCase):
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
):
def
setUp
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
fffb96ba
...
...
@@ -44,6 +44,8 @@ Core and Builtins
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
parent is created with the default permissions, ignoring the mode argument
(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