Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

base_storage.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """Abstract interface for file storage implementations."""
  2. from abc import ABC, abstractmethod
  3. from collections.abc import Generator
  4. class BaseStorage(ABC):
  5. """Interface for file storage."""
  6. @abstractmethod
  7. def save(self, filename, data):
  8. raise NotImplementedError
  9. @abstractmethod
  10. def load_once(self, filename: str) -> bytes:
  11. raise NotImplementedError
  12. @abstractmethod
  13. def load_stream(self, filename: str) -> Generator:
  14. raise NotImplementedError
  15. @abstractmethod
  16. def download(self, filename, target_filepath):
  17. raise NotImplementedError
  18. @abstractmethod
  19. def exists(self, filename):
  20. raise NotImplementedError
  21. @abstractmethod
  22. def delete(self, filename):
  23. raise NotImplementedError
  24. def scan(self, path, files=True, directories=False) -> list[str]:
  25. """
  26. Scan files and directories in the given path.
  27. This method is implemented only in some storage backends.
  28. If a storage backend doesn't support scanning, it will raise NotImplementedError.
  29. """
  30. raise NotImplementedError("This storage backend doesn't support scanning")