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
79ad8970
Kaydet (Commit)
79ad8970
authored
Şub 08, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #25911: Restored support of bytes paths in os.walk() on Windows.
üst
192697e3
5f6a0b4e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
10 deletions
+41
-10
os.py
Lib/os.py
+22
-5
test_os.py
Lib/test/test_os.py
+17
-5
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/os.py
Dosyayı görüntüle @
79ad8970
...
...
@@ -363,9 +363,12 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
# minor reason when (say) a thousand readable directories are still
# left to visit. That logic is copied here.
try
:
# Note that scandir is global in this module due
# to earlier import-*.
scandir_it
=
scandir
(
top
)
if
name
==
'nt'
and
isinstance
(
top
,
bytes
):
scandir_it
=
_dummy_scandir
(
top
)
else
:
# Note that scandir is global in this module due
# to earlier import-*.
scandir_it
=
scandir
(
top
)
except
OSError
as
error
:
if
onerror
is
not
None
:
onerror
(
error
)
...
...
@@ -418,8 +421,8 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
# Recurse into sub-directories
islink
,
join
=
path
.
islink
,
path
.
join
for
name
in
dirs
:
new_path
=
join
(
top
,
name
)
for
dir
name
in
dirs
:
new_path
=
join
(
top
,
dir
name
)
# Issue #23605: os.path.islink() is used instead of caching
# entry.is_symlink() result during the loop on os.scandir() because
# the caller can replace the directory entry during the "yield"
...
...
@@ -430,6 +433,20 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
# Yield after recursion if going bottom up
yield
top
,
dirs
,
nondirs
class
_DummyDirEntry
:
def
__init__
(
self
,
dir
,
name
):
self
.
name
=
name
self
.
path
=
path
.
join
(
dir
,
name
)
def
is_dir
(
self
):
return
path
.
isdir
(
self
.
path
)
def
is_symlink
(
self
):
return
path
.
islink
(
self
.
path
)
def
_dummy_scandir
(
dir
):
# listdir-based implementation for bytes patches on Windows
for
name
in
listdir
(
dir
):
yield
_DummyDirEntry
(
dir
,
name
)
__all__
.
append
(
"walk"
)
if
{
open
,
stat
}
<=
supports_dir_fd
and
{
listdir
,
stat
}
<=
supports_fd
:
...
...
Lib/test/test_os.py
Dosyayı görüntüle @
79ad8970
...
...
@@ -790,10 +790,10 @@ class WalkTests(unittest.TestCase):
# Wrapper to hide minor differences between os.walk and os.fwalk
# to tests both functions with the same code base
def
walk
(
self
,
directory
,
**
kwargs
):
def
walk
(
self
,
top
,
**
kwargs
):
if
'follow_symlinks'
in
kwargs
:
kwargs
[
'followlinks'
]
=
kwargs
.
pop
(
'follow_symlinks'
)
return
os
.
walk
(
directory
,
**
kwargs
)
return
os
.
walk
(
top
,
**
kwargs
)
def
setUp
(
self
):
join
=
os
.
path
.
join
...
...
@@ -944,11 +944,10 @@ class WalkTests(unittest.TestCase):
class
FwalkTests
(
WalkTests
):
"""Tests for os.fwalk()."""
def
walk
(
self
,
directory
,
**
kwargs
):
for
root
,
dirs
,
files
,
root_fd
in
os
.
fwalk
(
directory
,
**
kwargs
):
def
walk
(
self
,
top
,
**
kwargs
):
for
root
,
dirs
,
files
,
root_fd
in
os
.
fwalk
(
top
,
**
kwargs
):
yield
(
root
,
dirs
,
files
)
def
_compare_to_walk
(
self
,
walk_kwargs
,
fwalk_kwargs
):
"""
compare with walk() results.
...
...
@@ -1019,6 +1018,19 @@ class FwalkTests(WalkTests):
os
.
unlink
(
name
,
dir_fd
=
rootfd
)
os
.
rmdir
(
support
.
TESTFN
)
class
BytesWalkTests
(
WalkTests
):
"""Tests for os.walk() with bytes."""
def
walk
(
self
,
top
,
**
kwargs
):
if
'follow_symlinks'
in
kwargs
:
kwargs
[
'followlinks'
]
=
kwargs
.
pop
(
'follow_symlinks'
)
for
broot
,
bdirs
,
bfiles
in
os
.
walk
(
os
.
fsencode
(
top
),
**
kwargs
):
root
=
os
.
fsdecode
(
broot
)
dirs
=
list
(
map
(
os
.
fsdecode
,
bdirs
))
files
=
list
(
map
(
os
.
fsdecode
,
bfiles
))
yield
(
root
,
dirs
,
files
)
bdirs
[:]
=
list
(
map
(
os
.
fsencode
,
dirs
))
bfiles
[:]
=
list
(
map
(
os
.
fsencode
,
files
))
class
MakedirTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
79ad8970
...
...
@@ -170,6 +170,8 @@ Core and Builtins
Library
-------
-
Issue
#
25911
:
Restored
support
of
bytes
paths
in
os
.
walk
()
on
Windows
.
-
Issue
#
26045
:
Add
UTF
-
8
suggestion
to
error
message
when
posting
a
non
-
Latin
-
1
string
with
http
.
client
.
...
...
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