base_storage.py 887 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Abstract interface for file storage implementations."""
  2. from abc import ABC, abstractmethod
  3. from collections.abc import Generator
  4. from flask import Flask
  5. class BaseStorage(ABC):
  6. """Interface for file storage.
  7. """
  8. app = None
  9. def __init__(self, app: Flask):
  10. self.app = app
  11. @abstractmethod
  12. def save(self, filename, data):
  13. raise NotImplementedError
  14. @abstractmethod
  15. def load_once(self, filename: str) -> bytes:
  16. raise NotImplementedError
  17. @abstractmethod
  18. def load_stream(self, filename: str) -> Generator:
  19. raise NotImplementedError
  20. @abstractmethod
  21. def download(self, filename, target_filepath):
  22. raise NotImplementedError
  23. @abstractmethod
  24. def exists(self, filename):
  25. raise NotImplementedError
  26. @abstractmethod
  27. def delete(self, filename):
  28. raise NotImplementedError