| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import base64
- import asyncio
- class container_blob:
- def __init__(self, content: bytes | str) -> None:
- self.__content = content
- @property
- def content(self) -> bytes | str:
- return self.__content
- def result(self) -> bytes | str:
- return self.__content
- class decoded(container_blob):
- def __init__(self, content: bytes | str) -> None:
- if type(content) is str:
- content = content.encode("UTF-8")
- super().__init__(content)
- @staticmethod
- def __encode(content: bytes) -> container_blob:
- coded = base64.b64encode(content)
- coded = coded.decode("ascii")
- return encoded(coded)
- async def encode(self) -> container_blob:
- return await asyncio.to_thread(
- self.__class__.__encode,
- self.content
- )
- def __str__(self) -> str:
- return self.content.decode("UTF-8")
- def __bytes__(self) -> bytes:
- return self.content
- class encoded(container_blob):
- def __init__(self, content: str) -> None:
- super().__init__(content)
- @staticmethod
- def __decode(content: str) -> container_blob:
- content = content.encode("ascii")
- coded = base64.b64decode(content)
- return decoded(coded)
- async def decode(self) -> container_blob:
- return await asyncio.to_thread(
- self.__class__.__decode,
- self.content
- )
- def __str__(self) -> str:
- return self.content
|