1#!/usr/bin/env python
2#
3# A library that provides a Python interface to the Telegram Bot API
4# Copyright (C) 2015-2020
5# Leandro Toledo de Souza <devs@python-telegram-bot.org>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Lesser Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU Lesser Public License for more details.
16#
17# You should have received a copy of the GNU Lesser Public License
18# along with this program.  If not, see [http://www.gnu.org/licenses/].
19"""This module contains an object that represents a Telegram ChatPhoto."""
20from typing import TYPE_CHECKING, Any
21
22from telegram import TelegramObject
23
24if TYPE_CHECKING:
25    from telegram import Bot, File
26
27
28class ChatPhoto(TelegramObject):
29    """This object represents a chat photo.
30
31    Objects of this class are comparable in terms of equality. Two objects of this class are
32    considered equal, if their :attr:`small_file_unique_id` and :attr:`big_file_unique_id` are
33    equal.
34
35    Attributes:
36        small_file_id (:obj:`str`): File identifier of small (160x160) chat photo.
37            This file_id can be used only for photo download and only for as long
38            as the photo is not changed.
39        small_file_unique_id (:obj:`str`): Unique file identifier of small (160x160) chat photo,
40            which is supposed to be the same over time and for different bots.
41            Can't be used to download or reuse the file.
42        big_file_id (:obj:`str`): File identifier of big (640x640) chat photo.
43            This file_id can be used only for photo download and only for as long as
44            the photo is not changed.
45        big_file_unique_id (:obj:`str`): Unique file identifier of big (640x640) chat photo,
46            which is supposed to be the same over time and for different bots.
47            Can't be used to download or reuse the file.
48    Args:
49        small_file_id (:obj:`str`): Unique file identifier of small (160x160) chat photo. This
50            file_id can be used only for photo download and only for as long
51            as the photo is not changed.
52        small_file_unique_id (:obj:`str`): Unique file identifier of small (160x160) chat photo,
53            which is supposed to be the same over time and for different bots.
54            Can't be used to download or reuse the file.
55        big_file_id (:obj:`str`): Unique file identifier of big (640x640) chat photo. This file_id
56            can be used only for photo download and only for as long as the photo is not changed.
57        big_file_unique_id (:obj:`str`): Unique file identifier of big (640x640) chat photo,
58            which is supposed to be the same over time and for different bots.
59            Can't be used to download or reuse the file.
60        bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods
61        **kwargs (:obj:`dict`): Arbitrary keyword arguments.
62
63    """
64
65    def __init__(
66        self,
67        small_file_id: str,
68        small_file_unique_id: str,
69        big_file_id: str,
70        big_file_unique_id: str,
71        bot: 'Bot' = None,
72        **_kwargs: Any,
73    ):
74        self.small_file_id = small_file_id
75        self.small_file_unique_id = small_file_unique_id
76        self.big_file_id = big_file_id
77        self.big_file_unique_id = big_file_unique_id
78
79        self.bot = bot
80
81        self._id_attrs = (
82            self.small_file_unique_id,
83            self.big_file_unique_id,
84        )
85
86    def get_small_file(self, timeout: int = None, **kwargs: Any) -> 'File':
87        """Convenience wrapper over :attr:`telegram.Bot.get_file` for getting the
88        small (160x160) chat photo
89
90        Args:
91            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
92                the read timeout from the server (instead of the one specified during creation of
93                the connection pool).
94            api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the
95                Telegram API.
96
97        Returns:
98            :class:`telegram.File`
99
100        Raises:
101            :class:`telegram.TelegramError`
102
103        """
104        return self.bot.get_file(self.small_file_id, timeout=timeout, **kwargs)
105
106    def get_big_file(self, timeout: int = None, **kwargs: Any) -> 'File':
107        """Convenience wrapper over :attr:`telegram.Bot.get_file` for getting the
108        big (640x640) chat photo
109
110        Args:
111            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
112                the read timeout from the server (instead of the one specified during creation of
113                the connection pool).
114            api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the
115                Telegram API.
116
117        Returns:
118            :class:`telegram.File`
119
120        Raises:
121            :class:`telegram.TelegramError`
122
123        """
124        return self.bot.get_file(self.big_file_id, timeout=timeout, **kwargs)
125