LoL.py
Table Of Contents
LoL.py
Table Of Contents

Source code for lol.media

import io

import aiofiles


[docs]class Image: """Adds functionality for images in the module. Attributes: client (:class:`Client`): The client responsible for the image's creation and future requests. url (:class:`str`): The URL/location of the image which is used when reading and saving. It is also for use when you only needed the URL of the image. Parameters: client (:class:`Client`): The client responsible for the image's creation and future requests. url (:class:`str`): The URL/location of the image which is used when reading and saving. """ def __init__(self, client, url): self.client = client self.url = url def __repr__(self): return f"<lol.asset.Image url={self.url}>"
[docs] async def read(self): """Read this image as :class:`bytes`. Returns: bytes: The bytes of the image. """ return await self.client.request("GET", self.url, "", token=False)
[docs] async def save(self, b): """Save this image. Parameters: b (Union[BinaryIO, :class:`os.PathLike`]): The BinaryIO or :class:`os.PathLike` to save to. """ if isinstance(b, io.IOBase) and getattr(b, "writable", bool)(): ret = b.write(await self.read()) b.seek(0) else: async with aiofiles.open(b, "wb") as f: ret = await f.write(await self.read()) return ret