cpython: 8a3b0c1fb3d3 (original) (raw)
Mercurial > cpython
changeset 99799:8a3b0c1fb3d3 3.5
Add another try/except PermissionError to avoid depending on listdir order. Fix issues #24120 and #26012. (Merge 3.4->3.5) [#24120]
Guido van Rossum guido@python.org | |
---|---|
date | Thu, 07 Jan 2016 10:57:37 -0800 |
parents | 97ce60e8958c(current diff)4043e08e6e52(diff) |
children | 398cb8c183da 9ead69bd94f1 |
files | Lib/pathlib.py Lib/test/test_pathlib.py |
diffstat | 2 files changed, 16 insertions(+), 13 deletions(-)[+] [-] Lib/pathlib.py 13 Lib/test/test_pathlib.py 16 |
line wrap: on
line diff
--- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -539,11 +539,14 @@ class _RecursiveWildcardSelector(_Select def _iterate_directories(self, parent_path, is_dir, listdir): yield parent_path
for name in listdir(parent_path):[](#l1.7)
path = parent_path._make_child_relpath(name)[](#l1.8)
if is_dir(path) and not path.is_symlink():[](#l1.9)
for p in self._iterate_directories(path, is_dir, listdir):[](#l1.10)
yield p[](#l1.11)
try:[](#l1.12)
for name in listdir(parent_path):[](#l1.13)
path = parent_path._make_child_relpath(name)[](#l1.14)
if is_dir(path) and not path.is_symlink():[](#l1.15)
for p in self._iterate_directories(path, is_dir, listdir):[](#l1.16)
yield p[](#l1.17)
except PermissionError:[](#l1.18)
return[](#l1.19)
def _select_from(self, parent_path, is_dir, exists, listdir): try:
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1236,7 +1236,7 @@ class _BasePathTest(object):
# | |-- dirD
# | | -- fileD[](#l2.5) # |
-- fileC
@@ -1453,13 +1453,13 @@ class _BasePathTest(object): p = P(BASE) it = p.rglob("fileA") self.assertIsInstance(it, collections.Iterator)
# XXX cannot test because of symlink loops in the test setup[](#l2.16)
#_check(it, ["fileA"])[](#l2.17)
#_check(p.rglob("fileB"), ["dirB/fileB"])[](#l2.18)
#_check(p.rglob("*/fileA"), [""])[](#l2.19)
#_check(p.rglob("*/fileB"), ["dirB/fileB"])[](#l2.20)
#_check(p.rglob("file*"), ["fileA", "dirB/fileB"])[](#l2.21)
# No symlink loops here[](#l2.22)
_check(it, ["fileA"])[](#l2.23)
_check(p.rglob("fileB"), ["dirB/fileB"])[](#l2.24)
_check(p.rglob("*/fileA"), [])[](#l2.25)
_check(p.rglob("*/fileB"), ["dirB/fileB", "dirB/linkD/fileB",[](#l2.26)
"linkB/fileB", "dirA/linkC/fileB"])[](#l2.27)
_check(p.rglob("file*"), ["fileA", "dirB/fileB",[](#l2.28)
"dirC/fileC", "dirC/dirD/fileD"])[](#l2.29) p = P(BASE, "dirC")[](#l2.30) _check(p.rglob("file*"), ["dirC/fileC", "dirC/dirD/fileD"])[](#l2.31) _check(p.rglob("*/*"), ["dirC/dirD/fileD"])[](#l2.32)