Skip to content

Added file_unique_id attrs from API 4.5 and updated tests for it #1695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion telegram/files/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Animation(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique file identifier.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
width (:obj:`int`): Video width as defined by sender.
height (:obj:`int`): Video height as defined by sender.
duration (:obj:`int`): Duration of the video in seconds as defined by sender.
Expand All @@ -38,6 +41,8 @@ class Animation(TelegramObject):

Args:
file_id (:obj:`str`): Unique file identifier.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
width (:obj:`int`): Video width as defined by sender.
height (:obj:`int`): Video height as defined by sender.
duration (:obj:`int`): Duration of the video in seconds as defined by sender.
Expand All @@ -52,6 +57,7 @@ class Animation(TelegramObject):

def __init__(self,
file_id,
file_unique_id,
width,
height,
duration,
Expand All @@ -63,6 +69,7 @@ def __init__(self,
**kwargs):
# Required
self.file_id = str(file_id)
self.file_unique_id = str(file_unique_id)
self.width = int(width)
self.height = int(height)
self.duration = duration
Expand All @@ -73,7 +80,7 @@ def __init__(self,
self.file_size = file_size
self.bot = bot

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_id, self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
9 changes: 8 additions & 1 deletion telegram/files/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Audio(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique identifier for this file.
file_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
duration (:obj:`int`): Duration of the audio in seconds.
performer (:obj:`str`): Optional. Performer of the audio as defined by sender or by audio
tags.
Expand All @@ -38,6 +41,8 @@ class Audio(TelegramObject):

Args:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
duration (:obj:`int`): Duration of the audio in seconds as defined by sender.
performer (:obj:`str`, optional): Performer of the audio as defined by sender or by audio
tags.
Expand All @@ -53,6 +58,7 @@ class Audio(TelegramObject):

def __init__(self,
file_id,
file_unique_id,
duration,
performer=None,
title=None,
Expand All @@ -63,6 +69,7 @@ def __init__(self,
**kwargs):
# Required
self.file_id = str(file_id)
self.file_unique_id = str(file_unique_id)
self.duration = int(duration)
# Optionals
self.performer = performer
Expand All @@ -72,7 +79,7 @@ def __init__(self,
self.thumb = thumb
self.bot = bot

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_id, self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
43 changes: 34 additions & 9 deletions telegram/files/chatphoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,50 @@ class ChatPhoto(TelegramObject):
"""This object represents a chat photo.

Attributes:
small_file_id (:obj:`str`): File identifier of small (160x160) chat photo.
big_file_id (:obj:`str`): File identifier of big (640x640) chat photo.

small_file_id (:obj:`str`): File identifier of small (160x160) chat photo.
This file_id can be used only for photo download and only for as long
as the photo is not changed.
small_file_unique_id (:obj:`str`): Unique file identifier of small (160x160) chat photo,
which is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
big_file_id (:obj:`str`): File identifier of big (640x640) chat photo.
This file_id can be used only for photo download and only for as long as
the photo is not changed.
big_file_unique_id (:obj:`str`): Unique file identifier of big (640x640) chat photo,
which is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
Args:
small_file_id (:obj:`str`): File identifier of small (160x160) chat photo. This file_id can
be used only for photo download and only for as long as the photo is not changed.
big_file_id (:obj:`str`): File identifier of big (640x640) chat photo. This file_id can be
used only for photo download and only for as long as the photo is not changed.
small_file_id (:obj:`str`): Unique file identifier of small (160x160) chat photo. This
file_id can be used only for photo download and only for as long
as the photo is not changed.
small_file_unique_id (:obj:`str`): Unique file identifier of small (160x160) chat photo,
which is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
big_file_id (:obj:`str`): Unique file identifier of big (640x640) chat photo. This file_id
can be used only for photo download and only for as long as the photo is not changed.
big_file_unique_id (:obj:`str`): Unique file identifier of big (640x640) chat photo,
which is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""

def __init__(self, small_file_id, big_file_id, bot=None, **kwargs):
def __init__(self,
small_file_id,
small_file_unique_id,
big_file_id,
big_file_unique_id,
bot=None, **kwargs):
self.small_file_id = small_file_id
self.small_file_unique_id = small_file_unique_id
self.big_file_id = big_file_id
self.big_file_unique_id = big_file_unique_id

self.bot = bot

self._id_attrs = (self.small_file_id, self.big_file_id)
self._id_attrs = (self.small_file_id, self.small_file_unique_id,
self.big_file_id, self.big_file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
11 changes: 9 additions & 2 deletions telegram/files/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ class Document(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique file identifier.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
thumb (:class:`telegram.PhotoSize`): Optional. Document thumbnail.
file_name (:obj:`str`): Original filename.
mime_type (:obj:`str`): Optional. MIME type of the file.
file_size (:obj:`int`): Optional. File size.
bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.

Args:
file_id (:obj:`str`): Unique file identifier
file_id (:obj:`str`): Unique file identifier.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
thumb (:class:`telegram.PhotoSize`, optional): Document thumbnail as defined by sender.
file_name (:obj:`str`, optional): Original filename as defined by sender.
mime_type (:obj:`str`, optional): MIME type of the file as defined by sender.
Expand All @@ -46,6 +51,7 @@ class Document(TelegramObject):

def __init__(self,
file_id,
file_unique_id,
thumb=None,
file_name=None,
mime_type=None,
Expand All @@ -54,14 +60,15 @@ def __init__(self,
**kwargs):
# Required
self.file_id = str(file_id)
self.file_unique_id = str(file_unique_id)
# Optionals
self.thumb = thumb
self.file_name = file_name
self.mime_type = mime_type
self.file_size = file_size
self.bot = bot

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_id, self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
18 changes: 14 additions & 4 deletions telegram/files/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ class File(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
file_size (:obj:`str`): Optional. File size.
file_path (:obj:`str`): Optional. File path. Use :attr:`download` to get the file.

Args:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
file_size (:obj:`int`, optional): Optional. File size, if known.
file_path (:obj:`str`, optional): File path. Use :attr:`download` to get the file.
bot (:obj:`telegram.Bot`, optional): Bot to use with shortcut method.
Expand All @@ -53,18 +58,23 @@ class File(TelegramObject):

"""

def __init__(self, file_id, bot=None, file_size=None, file_path=None, **kwargs):
def __init__(self,
file_id,
file_unique_id,
bot=None,
file_size=None,
file_path=None,
**kwargs):
# Required
self.file_id = str(file_id)

self.file_unique_id = str(file_unique_id)
# Optionals
self.file_size = file_size
self.file_path = file_path

self.bot = bot
self._credentials = None

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_id, self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
17 changes: 15 additions & 2 deletions telegram/files/photosize.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ class PhotoSize(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
width (:obj:`int`): Photo width.
height (:obj:`int`): Photo height.
file_size (:obj:`int`): Optional. File size.
bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.

Args:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
width (:obj:`int`): Photo width.
height (:obj:`int`): Photo height.
file_size (:obj:`int`, optional): File size.
Expand All @@ -41,16 +46,24 @@ class PhotoSize(TelegramObject):

"""

def __init__(self, file_id, width, height, file_size=None, bot=None, **kwargs):
def __init__(self,
file_id,
file_unique_id,
width,
height,
file_size=None,
bot=None,
**kwargs):
# Required
self.file_id = str(file_id)
self.file_unique_id = str(file_unique_id)
self.width = int(width)
self.height = int(height)
# Optionals
self.file_size = file_size
self.bot = bot

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_id, self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
9 changes: 8 additions & 1 deletion telegram/files/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Sticker(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
width (:obj:`int`): Sticker width.
height (:obj:`int`): Sticker height.
is_animated (:obj:`bool`): True, if the sticker is animated.
Expand All @@ -40,6 +43,8 @@ class Sticker(TelegramObject):

Args:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
width (:obj:`int`): Sticker width.
height (:obj:`int`): Sticker height.
is_animated (:obj:`bool`): True, if the sticker is animated.
Expand All @@ -58,6 +63,7 @@ class Sticker(TelegramObject):

def __init__(self,
file_id,
file_unique_id,
width,
height,
is_animated,
Expand All @@ -70,6 +76,7 @@ def __init__(self,
**kwargs):
# Required
self.file_id = str(file_id)
self.file_unique_id = str(file_unique_id)
self.width = int(width)
self.height = int(height)
self.is_animated = is_animated
Expand All @@ -81,7 +88,7 @@ def __init__(self,
self.mask_position = mask_position
self.bot = bot

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_id, self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
9 changes: 8 additions & 1 deletion telegram/files/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Video(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
width (:obj:`int`): Video width as defined by sender.
height (:obj:`int`): Video height as defined by sender.
duration (:obj:`int`): Duration of the video in seconds as defined by sender.
Expand All @@ -36,6 +39,8 @@ class Video(TelegramObject):

Args:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
width (:obj:`int`): Video width as defined by sender.
height (:obj:`int`): Video height as defined by sender.
duration (:obj:`int`): Duration of the video in seconds as defined by sender.
Expand All @@ -49,6 +54,7 @@ class Video(TelegramObject):

def __init__(self,
file_id,
file_unique_id,
width,
height,
duration,
Expand All @@ -59,6 +65,7 @@ def __init__(self,
**kwargs):
# Required
self.file_id = str(file_id)
self.file_unique_id = str(file_unique_id)
self.width = int(width)
self.height = int(height)
self.duration = int(duration)
Expand All @@ -68,7 +75,7 @@ def __init__(self,
self.file_size = file_size
self.bot = bot

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_id, self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
Loading