import re from dataclasses import dataclass from typing import Iterator from webdav3.exceptions import RemoteResourceNotFound from .. import CLIENT @dataclass(frozen=True) class FileNameLister: remote_path: str re: re.Pattern[str] def __call__(self) -> Iterator[str]: try: file_names = CLIENT.list(self.remote_path) return ( name for name in file_names if self.re.search(name) ) except RemoteResourceNotFound: return iter(()) @dataclass(frozen=True) class FilePrefixFinder: lister: FileNameLister def __call__(self, prefix: str) -> Iterator[str]: return ( file_name for file_name in self.lister() if file_name.lower().startswith(prefix.lower()) )