From 19d7180c139272b2aa983cbc8af0d1a5545f333b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sat, 21 Dec 2013 23:26:57 +0100 Subject: [PATCH] add ICapImage and BaseImage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BaseImage was extracted from the gallery capability and refactored to inherit from BaseFile. As I did not look further into the gallery capability, I left the original BaseImage there. I'm aware that it's not an healthy situation, but it seems to be used only by modules using ICapGallery and hopefully should not have any consequences for now Signed-off-by: Pierre Mazière --- weboob/capabilities/image.py | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 weboob/capabilities/image.py diff --git a/weboob/capabilities/image.py b/weboob/capabilities/image.py new file mode 100644 index 00000000..986329fa --- /dev/null +++ b/weboob/capabilities/image.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2011 Romain Bignon, Christophe Benz, Noé Rubinstein +# Copyright(C) 2013 Pierre Mazière +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + +from .base import NotLoaded, Field, BytesField +from .file import ICapFile, BaseFile + +__all__ = ['BaseImage', 'ICapImage'] + +class _BaseImage(BaseFile): + """ + Fake class to allow the inclusion of a BaseImage property within + the real BaseImage class + """ + pass + +class BaseImage(_BaseImage): + """ + Represents an image file. + """ + nsfw = Field('Is this Not Safe For Work', bool, default=False) + thumbnail = Field('Thumbnail of the image', _BaseImage) + data = BytesField('Data of image') + + def __str__(self): + return self.url + + def __repr__(self): + return '' % self.url + + def __iscomplete__(self): + return self.data is not NotLoaded + +class ICapImage(ICapFile): + """ + Image file provider + """ + def search_image(self, pattern, sortby=ICapFile.SEARCH_RELEVANCE, nsfw=False): + """ + search for an image file + + :param pattern: pattern to search on + :type pattern: str + :param sortby: sort by ...(use SEARCH_* constants) + :param nsfw: include non-suitable for work images if True + :type nsfw: bool + :rtype: iter[:class:`BaseImage`] + """ + return self.search_file(pattern, sortby) + + def get_image(self, id): + """ + Get an image file from an ID. + + :param id: image file ID + :type id: str + :rtype: :class:`BaseImage`] + """ + return self.get_file(id) +