import pathlib import base64 from .attachment_file import attachment_file from .exceptions import resources_directory_not_exists class attachments_manager: def __init__( self, resources: pathlib.Path, init_directory: bool = False ) -> None: if init_directory: resources.mkdir() if not resources.is_dir() or not resources.exists(): raise resources_directory_not_exists(resources) self.__resources = resouces @property def resources(self) -> pathlib.Path: return self.__resources def uploaded(self, content: str, extension: str) -> attachment_file: content_bytes = content.encode("ascii") decoded = base64.b64decode(content_bytes) return attachment_file(decoded, extension, self.__resources)