async def _iterate_directories( self, parent_path: 'AsyncPath', is_dir: CoroutineMethod, scandir: CoroutineMethod) -> AsyncIterable['AsyncPath']: yield parent_path try: async for entry in scandir(parent_path): entry_is_dir: bool = False try: entry_is_dir = await entry.is_dir() except OSError as e: if not _ignore_error(e): raise if entry_is_dir and not await entry.is_symlink(): path = parent_path._make_child_relpath(entry.name) async for p in self._iterate_directories( path, is_dir, scandir): yield p except PermissionError: return
async def _select_from( self, parent_path: 'AsyncPath', is_dir: CoroutineMethod, exists: CoroutineMethod, scandir: CoroutineMethod) -> AsyncIterable['AsyncPath']: try: async for entry in scandir(parent_path): if self.dironly: try: # "entry.is_dir()" can raise PermissionError # in some cases (see bpo-38894), which is not # among the errors ignored by _ignore_error() if not await entry.is_dir(): continue except OSError as e: if not _ignore_error(e): raise continue name = entry.name if self.match(name): path = parent_path._make_child_relpath(name) async for p in self.successor._select_from( path, is_dir, exists, scandir): yield p except PermissionError: return
def __stat_raw(cls, path: Path) -> Optional[os.stat_result]: try: return path.lstat() except OSError as e: if hasattr(pathlib, "_ignore_error") and not pathlib._ignore_error(e): raise return None
async def is_socket(self) -> bool: """ Whether this path is a socket. """ try: stat = await self.stat() return S_ISSOCK(stat.st_mode) except OSError as e: if not _ignore_error(e): raise # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) return False except ValueError: # Non-encodable path return False
async def is_symlink(self) -> bool: """ Whether this path is a symbolic link. """ try: lstat = await self.lstat() return S_ISLNK(lstat.st_mode) except OSError as e: if not _ignore_error(e): raise # Path doesn't exist return False except ValueError: # Non-encodable path return False
async def exists(self) -> bool: """ Whether this path exists. """ try: await self.stat() except OSError as e: if not _ignore_error(e): raise return False except ValueError: # Non-encodable path return False return True
async def is_file(self) -> bool: """ Whether this path is a regular file (also True for symlinks pointing to regular files). """ try: stat = await self.stat() return S_ISREG(stat.st_mode) except OSError as e: if not _ignore_error(e): raise # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) return False except ValueError: # Non-encodable path return False
def update_event(self, inp=-1): self.set_output_val(0, pathlib._ignore_error(self.input(0)))