diff options
author | Guido van Rossum <guido@python.org> | 2016-01-06 17:51:42 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2016-01-06 17:51:42 (GMT) |
commit | d54377d2cabe6a2057468136ba1f29f48d1b47b7 (patch) | |
tree | 8e421e052ef92c518e846cef2eae96be57972197 /Lib/pathlib.py | |
parent | f34c3fe20c6e996b44014bf3e4e1fecc3739551c (diff) | |
parent | 6c2d33a258bb62bc74be4d848968c99c6fbfbba4 (diff) | |
download | cpython-d54377d2cabe6a2057468136ba1f29f48d1b47b7.zip cpython-d54377d2cabe6a2057468136ba1f29f48d1b47b7.tar.gz cpython-d54377d2cabe6a2057468136ba1f29f48d1b47b7.tar.bz2 |
Issue #24120: Ignore PermissionError in pathlib.Path.[r]glob(). Ulrich Petri. (Merge 3.4->3.5)
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r-- | Lib/pathlib.py | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 1b5d2a9..1ab656c 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -499,12 +499,15 @@ class _PreciseSelector(_Selector): _Selector.__init__(self, child_parts) def _select_from(self, parent_path, is_dir, exists, listdir): - if not is_dir(parent_path): + try: + if not is_dir(parent_path): + return + path = parent_path._make_child_relpath(self.name) + if exists(path): + for p in self.successor._select_from(path, is_dir, exists, listdir): + yield p + except PermissionError: return - path = parent_path._make_child_relpath(self.name) - if exists(path): - for p in self.successor._select_from(path, is_dir, exists, listdir): - yield p class _WildcardSelector(_Selector): @@ -514,15 +517,19 @@ class _WildcardSelector(_Selector): _Selector.__init__(self, child_parts) def _select_from(self, parent_path, is_dir, exists, listdir): - if not is_dir(parent_path): + try: + if not is_dir(parent_path): + return + cf = parent_path._flavour.casefold + for name in listdir(parent_path): + casefolded = cf(name) + if self.pat.match(casefolded): + path = parent_path._make_child_relpath(name) + for p in self.successor._select_from(path, is_dir, exists, listdir): + yield p + except PermissionError: return - cf = parent_path._flavour.casefold - for name in listdir(parent_path): - casefolded = cf(name) - if self.pat.match(casefolded): - path = parent_path._make_child_relpath(name) - for p in self.successor._select_from(path, is_dir, exists, listdir): - yield p + class _RecursiveWildcardSelector(_Selector): @@ -539,19 +546,22 @@ class _RecursiveWildcardSelector(_Selector): yield p def _select_from(self, parent_path, is_dir, exists, listdir): - if not is_dir(parent_path): + try: + if not is_dir(parent_path): + return + with _cached(listdir) as listdir: + yielded = set() + try: + successor_select = self.successor._select_from + for starting_point in self._iterate_directories(parent_path, is_dir, listdir): + for p in successor_select(starting_point, is_dir, exists, listdir): + if p not in yielded: + yield p + yielded.add(p) + finally: + yielded.clear() + except PermissionError: return - with _cached(listdir) as listdir: - yielded = set() - try: - successor_select = self.successor._select_from - for starting_point in self._iterate_directories(parent_path, is_dir, listdir): - for p in successor_select(starting_point, is_dir, exists, listdir): - if p not in yielded: - yield p - yielded.add(p) - finally: - yielded.clear() # |