Module signals_notebook.utils.fs_handler

Expand source code
from typing import Iterable, List, Optional, Protocol, Union


class FSHandler(Protocol):
    def write(self, path: str, data: Union[bytes, str], base_alias: Optional[Iterable[str]] = None):
        """Write file content into given path."""

    def read(self, path: str) -> bytes:
        """Return file content from given path."""

    def list_subfolders(self, path) -> List[str]:
        """Return subfolders names from given path."""

    @classmethod
    def join_path(cls, *paths: str) -> str:
        """Concatenate file paths."""

Classes

class FSHandler (*args, **kwargs)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
Expand source code
class FSHandler(Protocol):
    def write(self, path: str, data: Union[bytes, str], base_alias: Optional[Iterable[str]] = None):
        """Write file content into given path."""

    def read(self, path: str) -> bytes:
        """Return file content from given path."""

    def list_subfolders(self, path) -> List[str]:
        """Return subfolders names from given path."""

    @classmethod
    def join_path(cls, *paths: str) -> str:
        """Concatenate file paths."""

Ancestors

  • typing.Protocol
  • typing.Generic

Static methods

def join_path(*paths: str) ‑> str

Concatenate file paths.

Expand source code
@classmethod
def join_path(cls, *paths: str) -> str:
    """Concatenate file paths."""

Methods

def list_subfolders(self, path) ‑> List[str]

Return subfolders names from given path.

Expand source code
def list_subfolders(self, path) -> List[str]:
    """Return subfolders names from given path."""
def read(self, path: str) ‑> bytes

Return file content from given path.

Expand source code
def read(self, path: str) -> bytes:
    """Return file content from given path."""
def write(self, path: str, data: Union[bytes, str], base_alias: Optional[Iterable[str]] = None)

Write file content into given path.

Expand source code
def write(self, path: str, data: Union[bytes, str], base_alias: Optional[Iterable[str]] = None):
    """Write file content into given path."""