TelegramObject.de_json became classmethod (#737)

Fixes #734
This commit is contained in:
Ihor Polyakov 2017-07-24 02:14:38 +07:00 committed by Noam Meltzer
parent 5a37af6f89
commit 08d298eb60
70 changed files with 343 additions and 295 deletions

View file

@ -37,8 +37,8 @@ class TelegramObject(object):
def __getitem__(self, item):
return self.__dict__[item]
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):

View file

@ -2581,11 +2581,11 @@ class Bot(TelegramObject):
return result
@staticmethod
def de_json(data, bot):
data = super(Bot, Bot).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(Bot, cls).de_json(data, bot)
return Bot(**data)
return cls(**data)
def to_dict(self):
data = {'id': self.id, 'username': self.username, 'first_name': self.username}

View file

@ -46,8 +46,8 @@ class CallbackQuery(TelegramObject):
self.bot = bot
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -60,12 +60,12 @@ class CallbackQuery(TelegramObject):
if not data:
return None
data = super(CallbackQuery, CallbackQuery).de_json(data, bot)
data = super(CallbackQuery, cls).de_json(data, bot)
data['from_user'] = User.de_json(data.get('from'), bot)
data['message'] = Message.de_json(data.get('message'), bot)
return CallbackQuery(bot=bot, **data)
return cls(bot=bot, **data)
def to_dict(self):
"""

View file

@ -78,8 +78,8 @@ class Chat(TelegramObject):
self.bot = bot
self._id_attrs = (self.id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -93,7 +93,7 @@ class Chat(TelegramObject):
data['photo'] = ChatPhoto.de_json(data.get('photo'), bot)
return Chat(bot=bot, **data)
return cls(bot=bot, **data)
def send_action(self, *args, **kwargs):
"""Shortcut for ``bot.send_chat_action(update.message.chat.id, *args, **kwargs)``"""

View file

@ -98,8 +98,8 @@ class ChatMember(TelegramObject):
self._id_attrs = (self.user, self.status)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -111,12 +111,12 @@ class ChatMember(TelegramObject):
if not data:
return None
data = super(ChatMember, ChatMember).de_json(data, bot)
data = super(ChatMember, cls).de_json(data, bot)
data['user'] = User.de_json(data.get('user'), bot)
data['until_date'] = from_timestamp(data.get('until_date', None))
return ChatMember(**data)
return cls(**data)
def to_dict(self):
"""

View file

@ -64,8 +64,8 @@ class ChosenInlineResult(TelegramObject):
self._id_attrs = (self.result_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -77,13 +77,13 @@ class ChosenInlineResult(TelegramObject):
if not data:
return None
data = super(ChosenInlineResult, ChosenInlineResult).de_json(data, bot)
data = super(ChosenInlineResult, cls).de_json(data, bot)
# Required
data['from_user'] = User.de_json(data.pop('from'), bot)
# Optionals
data['location'] = Location.de_json(data.get('location'), bot)
return ChosenInlineResult(**data)
return cls(**data)
def to_dict(self):
"""

View file

@ -62,8 +62,8 @@ class Audio(TelegramObject):
self._id_attrs = (self.file_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -75,4 +75,4 @@ class Audio(TelegramObject):
if not data:
return None
return Audio(**data)
return cls(**data)

View file

@ -39,8 +39,8 @@ class ChatPhoto(TelegramObject):
self.small_file_id = small_file_id
self.big_file_id = big_file_id
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -52,4 +52,4 @@ class ChatPhoto(TelegramObject):
if not data:
return None
return ChatPhoto(bot=bot, **data)
return cls(bot=bot, **data)

View file

@ -49,8 +49,8 @@ class Contact(TelegramObject):
self._id_attrs = (self.phone_number,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -62,4 +62,4 @@ class Contact(TelegramObject):
if not data:
return None
return Contact(**data)
return cls(**data)

View file

@ -60,8 +60,8 @@ class Document(TelegramObject):
self._id_attrs = (self.file_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -73,8 +73,8 @@ class Document(TelegramObject):
if not data:
return None
data = super(Document, Document).de_json(data, bot)
data = super(Document, cls).de_json(data, bot)
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
return Document(**data)
return cls(**data)

View file

@ -53,8 +53,8 @@ class File(TelegramObject):
self._id_attrs = (self.file_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -66,7 +66,7 @@ class File(TelegramObject):
if not data:
return None
return File(bot=bot, **data)
return cls(bot=bot, **data)
def download(self, custom_path=None, out=None, timeout=None):
"""

View file

@ -40,8 +40,8 @@ class Location(TelegramObject):
self._id_attrs = (self.longitude, self.latitude)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -53,4 +53,4 @@ class Location(TelegramObject):
if not data:
return None
return Location(**data)
return cls(**data)

View file

@ -50,8 +50,8 @@ class PhotoSize(TelegramObject):
self._id_attrs = (self.file_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -63,10 +63,10 @@ class PhotoSize(TelegramObject):
if not data:
return None
return PhotoSize(**data)
return cls(**data)
@staticmethod
def de_list(data, bot):
@classmethod
def de_list(cls, data, bot):
"""
Args:
data (list):
@ -80,6 +80,6 @@ class PhotoSize(TelegramObject):
photos = list()
for photo in data:
photos.append(PhotoSize.de_json(photo, bot))
photos.append(cls.de_json(photo, bot))
return photos

View file

@ -74,8 +74,8 @@ class Sticker(TelegramObject):
self._id_attrs = (self.file_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (:obj:`dict`):
@ -87,19 +87,19 @@ class Sticker(TelegramObject):
if not data:
return None
data = super(Sticker, Sticker).de_json(data, bot)
data = super(Sticker, cls).de_json(data, bot)
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
data['mask_position'] = MaskPosition.de_json(data.get('mask_position'), bot)
return Sticker(**data)
return cls(**data)
@staticmethod
def de_list(data, bot):
@classmethod
def de_list(cls, data, bot):
if not data:
return list()
return [Sticker.de_json(d, bot) for d in data]
return [cls.de_json(d, bot) for d in data]
class StickerSet(TelegramObject):
@ -190,9 +190,9 @@ class MaskPosition(TelegramObject):
self.y_shift = y_shift
self.zoom = zoom
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
if data is None:
return None
return MaskPosition(**data)
return cls(**data)

View file

@ -42,13 +42,13 @@ class Venue(TelegramObject):
self._id_attrs = (self.location, self.title)
@staticmethod
def de_json(data, bot):
data = super(Venue, Venue).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(Venue, cls).de_json(data, bot)
if not data:
return None
data['location'] = Location.de_json(data.get('location'), bot)
return Venue(**data)
return cls(**data)

View file

@ -67,8 +67,8 @@ class Video(TelegramObject):
self._id_attrs = (self.file_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -80,8 +80,8 @@ class Video(TelegramObject):
if not data:
return None
data = super(Video, Video).de_json(data, bot)
data = super(Video, cls).de_json(data, bot)
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
return Video(**data)
return cls(**data)

View file

@ -43,8 +43,8 @@ class VideoNote(TelegramObject):
self._id_attrs = (self.file_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -56,8 +56,8 @@ class VideoNote(TelegramObject):
if not data:
return None
data = super(VideoNote, VideoNote).de_json(data, bot)
data = super(VideoNote, cls).de_json(data, bot)
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
return VideoNote(**data)
return cls(**data)

View file

@ -50,8 +50,8 @@ class Voice(TelegramObject):
self._id_attrs = (self.file_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -63,6 +63,6 @@ class Voice(TelegramObject):
if not data:
return None
data = super(Voice, Voice).de_json(data, bot)
data = super(Voice, cls).de_json(data, bot)
return Voice(**data)
return cls(**data)

View file

@ -41,8 +41,8 @@ class ForceReply(ReplyMarkup):
# Optionals
self.selective = bool(selective)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -54,4 +54,4 @@ class ForceReply(ReplyMarkup):
if not data:
return None
return ForceReply(**data)
return cls(**data)

View file

@ -50,21 +50,21 @@ class Animation(TelegramObject):
self._id_attrs = (self.file_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
bot (telegram.Bot):
Returns:
telegram.Game:
telegram.Animation:
"""
if not data:
return None
data = super(Animation, Animation).de_json(data, bot)
data = super(Animation, cls).de_json(data, bot)
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
return Animation(**data)
return cls(**data)

View file

@ -59,8 +59,8 @@ class Game(TelegramObject):
self.text_entities = text_entities
self.animation = animation
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -73,13 +73,13 @@ class Game(TelegramObject):
if not data:
return None
data = super(Game, Game).de_json(data, bot)
data = super(Game, cls).de_json(data, bot)
data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot)
data['animation'] = Animation.de_json(data.get('animation'), bot)
return Game(**data)
return cls(**data)
def to_dict(self):
"""

View file

@ -36,21 +36,21 @@ class GameHighScore(TelegramObject):
self.user = user
self.score = score
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
bot (telegram.Bot):
Returns:
telegram.Game:
telegram.GameHighScore:
"""
if not data:
return None
data = super(GameHighScore, GameHighScore).de_json(data, bot)
data = super(GameHighScore, cls).de_json(data, bot)
data['user'] = User.de_json(data.get('user'), bot)
return GameHighScore(**data)
return cls(**data)

View file

@ -74,8 +74,8 @@ class InlineKeyboardButton(TelegramObject):
self.callback_game = callback_game
self.pay = pay
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -84,20 +84,20 @@ class InlineKeyboardButton(TelegramObject):
Returns:
telegram.InlineKeyboardButton:
"""
data = super(InlineKeyboardButton, InlineKeyboardButton).de_json(data, bot)
data = super(InlineKeyboardButton, cls).de_json(data, bot)
if not data:
return None
return InlineKeyboardButton(**data)
return cls(**data)
@staticmethod
def de_list(data, bot):
@classmethod
def de_list(cls, data, bot):
if not data:
return []
inline_keyboards = list()
for inline_keyboard in data:
inline_keyboards.append(InlineKeyboardButton.de_json(inline_keyboard, bot))
inline_keyboards.append(cls.de_json(inline_keyboard, bot))
return inline_keyboards

View file

@ -38,8 +38,8 @@ class InlineKeyboardMarkup(ReplyMarkup):
# Required
self.inline_keyboard = inline_keyboard
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -49,7 +49,7 @@ class InlineKeyboardMarkup(ReplyMarkup):
telegram.InlineKeyboardMarkup:
"""
data = super(InlineKeyboardMarkup, InlineKeyboardMarkup).de_json(data, bot)
data = super(InlineKeyboardMarkup, cls).de_json(data, bot)
if not data:
return None
@ -59,7 +59,7 @@ class InlineKeyboardMarkup(ReplyMarkup):
for inline_keyboard in data['inline_keyboard']
]
return InlineKeyboardMarkup(**data)
return cls(**data)
def to_dict(self):
data = super(InlineKeyboardMarkup, self).to_dict()

View file

@ -58,8 +58,8 @@ class InlineQuery(TelegramObject):
self.bot = bot
self._id_attrs = (self.id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -68,7 +68,7 @@ class InlineQuery(TelegramObject):
Returns:
telegram.InlineQuery:
"""
data = super(InlineQuery, InlineQuery).de_json(data, bot)
data = super(InlineQuery, cls).de_json(data, bot)
if not data:
return None
@ -76,7 +76,7 @@ class InlineQuery(TelegramObject):
data['from_user'] = User.de_json(data.get('from'), bot)
data['location'] = Location.de_json(data.get('location'), bot)
return InlineQuery(bot=bot, **data)
return cls(bot=bot, **data)
def to_dict(self):
"""

View file

@ -42,7 +42,3 @@ class InlineQueryResult(TelegramObject):
self.id = str(id)
self._id_attrs = (self.id,)
@staticmethod
def de_json(data, bot):
return super(InlineQueryResult, InlineQueryResult).de_json(data, bot)

View file

@ -92,12 +92,15 @@ class InlineQueryResultArticle(InlineQueryResult):
if thumb_height:
self.thumb_height = thumb_height
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultArticle, InlineQueryResultArticle).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultArticle, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultArticle(**data)
return cls(**data)

View file

@ -84,12 +84,15 @@ class InlineQueryResultAudio(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultAudio, InlineQueryResultAudio).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultAudio, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultAudio(**data)
return cls(**data)

View file

@ -69,12 +69,15 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultCachedAudio, InlineQueryResultCachedAudio).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultCachedAudio, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultCachedAudio(**data)
return cls(**data)

View file

@ -73,13 +73,15 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultCachedDocument,
InlineQueryResultCachedDocument).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultCachedDocument, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultCachedDocument(**data)
return cls(**data)

View file

@ -69,12 +69,15 @@ class InlineQueryResultCachedGif(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultCachedGif, InlineQueryResultCachedGif).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultCachedGif, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultCachedGif(**data)
return cls(**data)

View file

@ -70,13 +70,15 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultCachedMpeg4Gif,
InlineQueryResultCachedMpeg4Gif).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultCachedMpeg4Gif, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultCachedMpeg4Gif(**data)
return cls(**data)

View file

@ -73,12 +73,15 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultCachedPhoto, InlineQueryResultCachedPhoto).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultCachedPhoto, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultCachedPhoto(**data)
return cls(**data)

View file

@ -58,13 +58,15 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultCachedSticker,
InlineQueryResultCachedSticker).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultCachedSticker, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultCachedSticker(**data)
return cls(**data)

View file

@ -72,12 +72,15 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultCachedVideo, InlineQueryResultCachedVideo).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultCachedVideo, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultCachedVideo(**data)
return cls(**data)

View file

@ -67,12 +67,15 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultCachedVoice, InlineQueryResultCachedVoice).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultCachedVoice, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultCachedVoice(**data)
return cls(**data)

View file

@ -82,12 +82,15 @@ class InlineQueryResultContact(InlineQueryResult):
if thumb_height:
self.thumb_height = thumb_height
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultContact, InlineQueryResultContact).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultContact, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultContact(**data)
return cls(**data)

View file

@ -92,12 +92,15 @@ class InlineQueryResultDocument(InlineQueryResult):
if thumb_height:
self.thumb_height = thumb_height
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultDocument, InlineQueryResultDocument).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultDocument, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultDocument(**data)
return cls(**data)

View file

@ -33,10 +33,13 @@ class InlineQueryResultGame(InlineQueryResult):
if reply_markup:
self.reply_markup = reply_markup
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultGame, InlineQueryResultGame).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultGame, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
return InlineQueryResultGame(**data)
return cls(**data)

View file

@ -89,12 +89,15 @@ class InlineQueryResultGif(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultGif, InlineQueryResultGif).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultGif, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultGif(**data)
return cls(**data)

View file

@ -82,12 +82,15 @@ class InlineQueryResultLocation(InlineQueryResult):
if thumb_height:
self.thumb_height = thumb_height
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultLocation, InlineQueryResultLocation).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultLocation, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultLocation(**data)
return cls(**data)

View file

@ -90,12 +90,15 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultMpeg4Gif, InlineQueryResultMpeg4Gif).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultMpeg4Gif, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultMpeg4Gif(**data)
return cls(**data)

View file

@ -75,12 +75,15 @@ class InlineQueryResultPhoto(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultPhoto, InlineQueryResultPhoto).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultPhoto, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultPhoto(**data)
return cls(**data)

View file

@ -59,12 +59,15 @@ class InlineQueryResultVenue(InlineQueryResult):
if thumb_height:
self.thumb_height = thumb_height
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultVenue, InlineQueryResultVenue).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultVenue, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultVenue(**data)
return cls(**data)

View file

@ -62,12 +62,15 @@ class InlineQueryResultVideo(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultVideo, InlineQueryResultVideo).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultVideo, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultVideo(**data)
return cls(**data)

View file

@ -49,12 +49,15 @@ class InlineQueryResultVoice(InlineQueryResult):
if input_message_content:
self.input_message_content = input_message_content
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultVoice, InlineQueryResultVoice).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InlineQueryResultVoice, cls).de_json(data, bot)
if not data:
return None
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'), bot)
return InlineQueryResultVoice(**data)
return cls(**data)

View file

@ -32,6 +32,6 @@ class InputContactMessageContent(InputMessageContent):
# Optionals
self.last_name = last_name
@staticmethod
def de_json(data, bot):
return InputContactMessageContent(**data)
@classmethod
def de_json(cls, data, bot):
return cls(**data)

View file

@ -30,6 +30,6 @@ class InputLocationMessageContent(InputMessageContent):
self.latitude = latitude
self.longitude = longitude
@staticmethod
def de_json(data, bot):
return InputLocationMessageContent(**data)
@classmethod
def de_json(cls, data, bot):
return cls(**data)

View file

@ -25,9 +25,9 @@ from telegram import TelegramObject
class InputMessageContent(TelegramObject):
"""Base class for Telegram InputMessageContent Objects"""
@staticmethod
def de_json(data, bot):
data = super(InputMessageContent, InputMessageContent).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(InputMessageContent, cls).de_json(data, bot)
if not data:
return None

View file

@ -32,6 +32,6 @@ class InputTextMessageContent(InputMessageContent):
self.parse_mode = parse_mode
self.disable_web_page_preview = disable_web_page_preview
@staticmethod
def de_json(data, bot):
return InputTextMessageContent(**data)
@classmethod
def de_json(cls, data, bot):
return cls(**data)

View file

@ -34,6 +34,6 @@ class InputVenueMessageContent(InputMessageContent):
# Optionals
self.foursquare_id = foursquare_id
@staticmethod
def de_json(data, bot):
return InputVenueMessageContent(**data)
@classmethod
def de_json(cls, data, bot):
return cls(**data)

View file

@ -40,20 +40,20 @@ class KeyboardButton(TelegramObject):
self.request_contact = request_contact
self.request_location = request_location
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
if not data:
return None
return KeyboardButton(**data)
return cls(**data)
@staticmethod
def de_list(data, bot):
@classmethod
def de_list(cls, data, bot):
if not data:
return []
keyboards = list()
for keyboard in data:
keyboards.append(KeyboardButton.de_json(keyboard, bot))
keyboards.append(cls.de_json(keyboard, bot))
return keyboards

View file

@ -197,8 +197,8 @@ class Message(TelegramObject):
"""int: Short for :attr:`Message.chat.id`"""
return self.chat.id
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -210,7 +210,7 @@ class Message(TelegramObject):
if not data:
return None
data = super(Message, Message).de_json(data, bot)
data = super(Message, cls).de_json(data, bot)
data['from_user'] = User.de_json(data.get('from'), bot)
data['date'] = from_timestamp(data['date'])
@ -240,7 +240,7 @@ class Message(TelegramObject):
data['invoice'] = Invoice.de_json(data.get('invoice'), bot)
data['successful_payment'] = SuccessfulPayment.de_json(data.get('successful_payment'), bot)
return Message(bot=bot, **data)
return cls(bot=bot, **data)
def __getitem__(self, item):
if item in self.__dict__.keys():

View file

@ -43,16 +43,19 @@ class MessageEntity(TelegramObject):
self.url = url
self.user = user
@staticmethod
def de_json(data, bot):
data = super(MessageEntity, MessageEntity).de_json(data, bot)
@classmethod
def de_json(cls, data, bot):
data = super(MessageEntity, cls).de_json(data, bot)
if not data:
return None
data['user'] = User.de_json(data.get('user'), bot)
return MessageEntity(**data)
return cls(**data)
@staticmethod
def de_list(data, bot):
@classmethod
def de_list(cls, data, bot):
"""
Args:
data (list):
@ -65,7 +68,7 @@ class MessageEntity(TelegramObject):
entities = list()
for entity in data:
entities.append(MessageEntity.de_json(entity, bot))
entities.append(cls.de_json(entity, bot))
return entities

View file

@ -42,8 +42,8 @@ class Invoice(TelegramObject):
self.currency = currency
self.total_amount = total_amount
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -55,4 +55,4 @@ class Invoice(TelegramObject):
if not data:
return None
return Invoice(**data)
return cls(**data)

View file

@ -34,8 +34,8 @@ class LabeledPrice(TelegramObject):
self.label = label
self.amount = amount
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -48,10 +48,10 @@ class LabeledPrice(TelegramObject):
if not data:
return None
return LabeledPrice(**data)
return cls(**data)
@staticmethod
def de_list(data, bot):
@classmethod
def de_list(cls, data, bot):
"""
Args:
data (list):
@ -65,6 +65,6 @@ class LabeledPrice(TelegramObject):
labeled_prices = list()
for labeled_price in data:
labeled_prices.append(LabeledPrice.de_json(labeled_price, bot))
labeled_prices.append(cls.de_json(labeled_price, bot))
return labeled_prices

View file

@ -39,8 +39,8 @@ class OrderInfo(TelegramObject):
self.email = email
self.shipping_address = shipping_address
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -50,10 +50,10 @@ class OrderInfo(TelegramObject):
telegram.OrderInfo:
"""
if not data:
return OrderInfo()
return cls()
data = super(OrderInfo, OrderInfo).de_json(data, bot)
data = super(OrderInfo, cls).de_json(data, bot)
data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)
return OrderInfo(**data)
return cls(**data)

View file

@ -62,8 +62,8 @@ class PreCheckoutQuery(TelegramObject):
self._id_attrs = (self.id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -75,12 +75,12 @@ class PreCheckoutQuery(TelegramObject):
if not data:
return None
data = super(PreCheckoutQuery, PreCheckoutQuery).de_json(data, bot)
data = super(PreCheckoutQuery, cls).de_json(data, bot)
data['from_user'] = User.de_json(data.pop('from'), bot)
data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)
return PreCheckoutQuery(**data)
return cls(**data)
def to_dict(self):
"""

View file

@ -46,8 +46,8 @@ class ShippingAddress(TelegramObject):
self._id_attrs = (self.country_code, self.state, self.city, self.street_line1,
self.street_line2, self.post_code)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -59,4 +59,4 @@ class ShippingAddress(TelegramObject):
if not data:
return None
return ShippingAddress(**data)
return cls(**data)

View file

@ -42,8 +42,8 @@ class ShippingOption(TelegramObject):
self._id_attrs = (self.id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -55,11 +55,11 @@ class ShippingOption(TelegramObject):
if not data:
return None
data = super(ShippingOption, ShippingOption).de_json(data, bot)
data = super(ShippingOption, cls).de_json(data, bot)
data['prices'] = LabeledPrice.de_list(data.get('prices'), bot)
return ShippingOption(**data)
return cls(**data)
def to_dict(self):
"""

View file

@ -47,8 +47,8 @@ class ShippingQuery(TelegramObject):
self._id_attrs = (self.id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -60,12 +60,12 @@ class ShippingQuery(TelegramObject):
if not data:
return None
data = super(ShippingQuery, ShippingQuery).de_json(data, bot)
data = super(ShippingQuery, cls).de_json(data, bot)
data['from_user'] = User.de_json(data.pop('from'), bot)
data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)
return ShippingQuery(**data)
return cls(**data)
def to_dict(self):
"""

View file

@ -58,8 +58,8 @@ class SuccessfulPayment(TelegramObject):
self._id_attrs = (self.telegram_payment_charge_id, self.provider_payment_charge_id)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -71,7 +71,7 @@ class SuccessfulPayment(TelegramObject):
if not data:
return None
data = super(SuccessfulPayment, SuccessfulPayment).de_json(data, bot)
data = super(SuccessfulPayment, cls).de_json(data, bot)
data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot)
return SuccessfulPayment(**data)
return cls(**data)

View file

@ -54,8 +54,8 @@ class ReplyKeyboardMarkup(ReplyMarkup):
self.one_time_keyboard = bool(one_time_keyboard)
self.selective = bool(selective)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -67,11 +67,11 @@ class ReplyKeyboardMarkup(ReplyMarkup):
if not data:
return None
data = super(ReplyKeyboardMarkup, ReplyKeyboardMarkup).de_json(data, bot)
data = super(ReplyKeyboardMarkup, cls).de_json(data, bot)
data['keyboard'] = [KeyboardButton.de_list(keyboard, bot) for keyboard in data['keyboard']]
return ReplyKeyboardMarkup(**data)
return cls(**data)
def to_dict(self):
data = super(ReplyKeyboardMarkup, self).to_dict()

View file

@ -46,8 +46,8 @@ class ReplyKeyboardRemove(ReplyMarkup):
# Optionals
self.selective = bool(selective)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -60,7 +60,7 @@ class ReplyKeyboardRemove(ReplyMarkup):
if not data:
return None
return ReplyKeyboardRemove(**data)
return cls(**data)
class ReplyKeyboardHide(object):

View file

@ -23,12 +23,4 @@ from telegram import TelegramObject
class ReplyMarkup(TelegramObject):
"""Base class for Telegram ReplyMarkup Objects"""
@staticmethod
def de_json(data, bot):
data = super(ReplyMarkup, ReplyMarkup).de_json(data, bot)
if not data:
return None
return data
pass

View file

@ -89,8 +89,8 @@ class Update(TelegramObject):
self._id_attrs = (self.update_id,)
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -102,7 +102,7 @@ class Update(TelegramObject):
if not data:
return None
data = super(Update, Update).de_json(data, bot)
data = super(Update, cls).de_json(data, bot)
data['message'] = Message.de_json(data.get('message'), bot)
data['edited_message'] = Message.de_json(data.get('edited_message'), bot)
@ -115,7 +115,7 @@ class Update(TelegramObject):
data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
data['edited_channel_post'] = Message.de_json(data.get('edited_channel_post'), bot)
return Update(**data)
return cls(**data)
@property
def effective_user(self):

View file

@ -77,8 +77,8 @@ class User(TelegramObject):
return '%s %s' % (self.first_name, self.last_name)
return self.first_name
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -90,9 +90,9 @@ class User(TelegramObject):
if not data:
return None
data = super(User, User).de_json(data, bot)
data = super(User, cls).de_json(data, bot)
return User(bot=bot, **data)
return cls(bot=bot, **data)
def get_profile_photos(self, *args, **kwargs):
"""
@ -100,8 +100,8 @@ class User(TelegramObject):
"""
return self.bot.get_user_profile_photos(self.id, *args, **kwargs)
@staticmethod
def de_list(data, bot):
@classmethod
def de_list(cls, data, bot):
"""
Args:
data (list):
@ -115,6 +115,6 @@ class User(TelegramObject):
users = list()
for user in data:
users.append(User.de_json(user, bot))
users.append(cls.de_json(user, bot))
return users

View file

@ -39,8 +39,8 @@ class UserProfilePhotos(TelegramObject):
self.total_count = int(total_count)
self.photos = photos
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -52,11 +52,11 @@ class UserProfilePhotos(TelegramObject):
if not data:
return None
data = super(UserProfilePhotos, UserProfilePhotos).de_json(data, bot)
data = super(UserProfilePhotos, cls).de_json(data, bot)
data['photos'] = [PhotoSize.de_list(photo, bot) for photo in data['photos']]
return UserProfilePhotos(**data)
return cls(**data)
def to_dict(self):
"""

View file

@ -58,8 +58,8 @@ class WebhookInfo(TelegramObject):
self.max_connections = max_connections
self.allowed_updates = allowed_updates
@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
@ -72,4 +72,4 @@ class WebhookInfo(TelegramObject):
if not data:
return None
return WebhookInfo(**data)
return cls(**data)

View file

@ -68,11 +68,11 @@ class AnimationTest(BaseTest, unittest.TestCase):
animation = telegram.Animation.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_dict(animation.to_dict()))
self.assertEqual(animation['file_id'], self.animation_file_id)
self.assertEqual(animation['thumb'], self.thumb)
self.assertEqual(animation['file_name'], self.file_name)
self.assertEqual(animation['mime_type'], self.mime_type)
self.assertEqual(animation['file_size'], self.file_size)
self.assertEqual(animation.file_id, self.animation_file_id)
self.assertEqual(animation.thumb, self.thumb)
self.assertEqual(animation.file_name, self.file_name)
self.assertEqual(animation.mime_type, self.mime_type)
self.assertEqual(animation.file_size, self.file_size)
def test_equality(self):
a = telegram.Animation(self.animation_file_id)