From 2140f572e83666b9a507342908b9e72fac264f3b Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Wed, 21 Nov 2018 18:29:19 -0300 Subject: [PATCH] images: add dummy IconManager gif handling --- litecord/images.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/litecord/images.py b/litecord/images.py index 9035578..d651253 100644 --- a/litecord/images.py +++ b/litecord/images.py @@ -228,6 +228,11 @@ class IconManager: return await self.generic_get( 'guild', guild_id, icon_hash, **kwargs) + async def _put_gif(self, scope: str, key, + raw_data: bytes, **kwargs) -> Icon: + """Insert a gif icon""" + raise NotImplementedError + async def put(self, scope: str, key: str, b64_data: str, **kwargs) -> Icon: """Insert an icon.""" @@ -235,6 +240,8 @@ class IconManager: return _invalid(kwargs) mime, raw_data = parse_data_uri(b64_data) + + # TODO: filter mimes data_fd = BytesIO(raw_data) # get an extension for the given data uri @@ -243,6 +250,11 @@ class IconManager: if 'bsize' in kwargs and len(raw_data) > kwargs['bsize']: return _invalid(kwargs) + # size management is different for gif files + # as they're composed of multiple frames. + if mime == 'image/gif': + return await self._put_gif(scope, key, raw_data, **kwargs) + if 'size' in kwargs: image = Image.open(data_fd)