| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | import pathlib import aiofilesfrom .attachment import attachmentfrom .attachment import attachment_proxyfrom .aleatory_file_name import aleatory_file_nameclass attachment_file:    @classmethod    def create(cls, directory: pathlib.Path, extension: str) -> object:        while True:            new_name = aleatory_file_name.path(extension)            new_path = directory / new_name            if not new_path.exists() and not new_path.is_file():                return cls(new_name, directory)        def __init__(        self,         file_name: pathlib.Path,         directory: pathlib.Path    ) -> None:        self.__file_name = file_name        self.__directory = directory        self.__file_path = directory / file_name    @property    def path(self) -> pathlib.Path:        return self.__file_path    @property    def directory(self) -> pathlib.Path:        return self.__directory    @property    def name(self) -> str:        return str(self.__file_name)    @property    def relative_path(self) -> pathlib.Path:        return self.__file_name    async def store(self, content: bytes) -> attachment_proxy:        async with aiofiles.open(self.path, "wb") as handler:            await handler.write(content)        return attachment_proxy.create(self.name)    async def load(self) -> bytes:        async with aiofiles.open(self.path, "rb") as handler:            return await handler.read()                
 |