| 1234567891011121314151617181920212223242526272829303132333435363738394041 | import base64import pathlibimport asynciofrom .attachment import attachmentfrom .attachment import attachment_proxyfrom .attachment_file import attachment_filefrom .exceptions import resources_directory_not_existsclass 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 = resources    @property    def resources(self) -> pathlib.Path:        return self.__resources    async def __decode(self, content: str) -> bytes:        return await asyncio.to_thread(            base64.b64decode,            content.encode("ascii")        )       async def upload(self, content: str, extension: str) -> attachment_file:        decoded = await self.__decode(content)        file_handler = attachment_file.create(self.resources, extension)        return await file_handler.store(decoded)    def restore(self, file: attachment) -> attachment_file:        return attachment_file(file.resources_path, self.resources) 
 |