Yield myself, then each of my children, and each of those children's children in turn. The optional argument C{descend} is a predicate that takes a FilePath, and determines whether or not that FilePath is traversed/descended into. It will be called with eac
(
self: _Self,
descend: Callable[[_Self], bool] | None = None,
)
| 466 | return result |
| 467 | |
| 468 | def walk( |
| 469 | self: _Self, |
| 470 | descend: Callable[[_Self], bool] | None = None, |
| 471 | ) -> Iterable[_Self]: |
| 472 | """ |
| 473 | Yield myself, then each of my children, and each of those children's |
| 474 | children in turn. |
| 475 | |
| 476 | The optional argument C{descend} is a predicate that takes a FilePath, |
| 477 | and determines whether or not that FilePath is traversed/descended |
| 478 | into. It will be called with each path for which C{isdir} returns |
| 479 | C{True}. If C{descend} is not specified, all directories will be |
| 480 | traversed (including symbolic links which refer to directories). |
| 481 | |
| 482 | @param descend: A one-argument callable that will return True for |
| 483 | FilePaths that should be traversed, False otherwise. |
| 484 | |
| 485 | @return: a generator yielding FilePath-like objects. |
| 486 | """ |
| 487 | yield self |
| 488 | if self.isdir(): |
| 489 | for c in self.children(): |
| 490 | # we should first see if it's what we want, then we |
| 491 | # can walk through the directory |
| 492 | if descend is None or descend(c): |
| 493 | for subc in c.walk(descend): |
| 494 | if os.path.realpath(self.path).startswith( |
| 495 | os.path.realpath(subc.path) |
| 496 | ): |
| 497 | raise LinkError("Cycle in file graph.") |
| 498 | yield subc |
| 499 | else: |
| 500 | yield c |
| 501 | |
| 502 | def sibling(self: _Self, path: OtherAnyStr) -> AbstractFilePath[OtherAnyStr]: |
| 503 | """ |