Protocols

Protocol definitions for extensible file system providers.

FileSystemProvider Protocol

Abstract interface for interactive file system navigation. Unlike DiscoveryProvider (which is for batch scanning), this protocol focuses on navigating directories one at a time.


source

FileSystemProvider


def FileSystemProvider(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

Protocol for file system access backends.

# Test that protocol is runtime checkable
class MockFileSystemProvider:
    """Mock provider for testing protocol."""
    
    @property
    def name(self) -> str:
        return "mock"
    
    @property
    def root_path(self) -> str:
        return "/"
    
    @property
    def path_separator(self) -> str:
        return "/"
    
    def list_directory(self, path: str) -> DirectoryListing:
        return DirectoryListing(path=path, items=[])
    
    async def list_directory_async(self, path: str) -> DirectoryListing:
        return DirectoryListing(path=path, items=[])
    
    def get_file_info(self, path: str) -> Optional[FileInfo]:
        return None
    
    def get_parent_path(self, path: str) -> Optional[str]:
        return None
    
    def join_path(self, base: str, *parts: str) -> str:
        return base + "/" + "/".join(parts)
    
    def normalize_path(self, path: str) -> str:
        return path
    
    def is_valid_path(self, path: str) -> Tuple[bool, Optional[str]]:
        return (True, None)
    
    def path_exists(self, path: str) -> bool:
        return True
    
    def is_directory(self, path: str) -> bool:
        return True


# Protocol check works
mock = MockFileSystemProvider()
assert isinstance(mock, FileSystemProvider)

# Non-implementing class fails check
class NotAProvider:
    pass

assert not isinstance(NotAProvider(), FileSystemProvider)

print("FileSystemProvider protocol tests passed!")
FileSystemProvider protocol tests passed!