| 480 | yield from select_recursive_step(stack, match_pos) |
| 481 | |
| 482 | def select_recursive_step(stack, match_pos): |
| 483 | path = stack.pop() |
| 484 | try: |
| 485 | entries = self.scandir(path) |
| 486 | except OSError: |
| 487 | pass |
| 488 | else: |
| 489 | for entry, _entry_name, entry_path in entries: |
| 490 | is_dir = False |
| 491 | try: |
| 492 | if entry.is_dir(follow_symlinks=follow_symlinks): |
| 493 | is_dir = True |
| 494 | except OSError: |
| 495 | pass |
| 496 | |
| 497 | if is_dir or not dir_only: |
| 498 | entry_path_str = str(entry_path) |
| 499 | if dir_only: |
| 500 | entry_path = self.concat_path(entry_path, self.sep) |
| 501 | if match is None or match(entry_path_str, match_pos): |
| 502 | if dir_only: |
| 503 | yield from select_next(entry_path, exists=True) |
| 504 | else: |
| 505 | # Optimization: directly yield the path if this is |
| 506 | # last pattern part. |
| 507 | yield entry_path |
| 508 | if is_dir: |
| 509 | stack.append(entry_path) |
| 510 | |
| 511 | return select_recursive |
| 512 | |