Skip to content
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
4 changes: 2 additions & 2 deletions telegram/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def __str__(self):
def __getitem__(self, item):
return self.__dict__[item]

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand Down
8 changes: 4 additions & 4 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2581,11 +2581,11 @@ def delete_sticker_from_set(self, sticker, timeout=None, **kwargs):

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}
Expand Down
8 changes: 4 additions & 4 deletions telegram/callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def __init__(self,

self.bot = bot

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -60,12 +60,12 @@ def de_json(data, bot):
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):
"""
Expand Down
6 changes: 3 additions & 3 deletions telegram/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def __init__(self,
self.bot = bot
self._id_attrs = (self.id,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -93,7 +93,7 @@ def de_json(data, bot):

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)``"""
Expand Down
8 changes: 4 additions & 4 deletions telegram/chatmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def __init__(self, user, status, until_date=None, can_be_edited=None,

self._id_attrs = (self.user, self.status)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -111,12 +111,12 @@ def de_json(data, bot):
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):
"""
Expand Down
8 changes: 4 additions & 4 deletions telegram/choseninlineresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def __init__(self,

self._id_attrs = (self.result_id,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -77,13 +77,13 @@ def de_json(data, bot):
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):
"""
Expand Down
6 changes: 3 additions & 3 deletions telegram/files/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def __init__(self,

self._id_attrs = (self.file_id,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -75,4 +75,4 @@ def de_json(data, bot):
if not data:
return None

return Audio(**data)
return cls(**data)
6 changes: 3 additions & 3 deletions telegram/files/chatphoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def __init__(self, small_file_id, big_file_id, bot=None, **kwargs):
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):
Expand All @@ -52,4 +52,4 @@ def de_json(data, bot):
if not data:
return None

return ChatPhoto(bot=bot, **data)
return cls(bot=bot, **data)
6 changes: 3 additions & 3 deletions telegram/files/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def __init__(self, phone_number, first_name, last_name=None, user_id=None, **kwa

self._id_attrs = (self.phone_number,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -62,4 +62,4 @@ def de_json(data, bot):
if not data:
return None

return Contact(**data)
return cls(**data)
8 changes: 4 additions & 4 deletions telegram/files/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def __init__(self,

self._id_attrs = (self.file_id,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -73,8 +73,8 @@ def de_json(data, bot):
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)
6 changes: 3 additions & 3 deletions telegram/files/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def __init__(self, file_id, bot, file_size=None, file_path=None, **kwargs):

self._id_attrs = (self.file_id,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -66,7 +66,7 @@ def de_json(data, bot):
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):
"""
Expand Down
6 changes: 3 additions & 3 deletions telegram/files/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def __init__(self, longitude, latitude, **kwargs):

self._id_attrs = (self.longitude, self.latitude)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -53,4 +53,4 @@ def de_json(data, bot):
if not data:
return None

return Location(**data)
return cls(**data)
12 changes: 6 additions & 6 deletions telegram/files/photosize.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def __init__(self, file_id, width, height, file_size=None, **kwargs):

self._id_attrs = (self.file_id,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -63,10 +63,10 @@ def de_json(data, bot):
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):
Expand All @@ -80,6 +80,6 @@ def de_list(data, bot):

photos = list()
for photo in data:
photos.append(PhotoSize.de_json(photo, bot))
photos.append(cls.de_json(photo, bot))

return photos
20 changes: 10 additions & 10 deletions telegram/files/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def __init__(self,

self._id_attrs = (self.file_id,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (:obj:`dict`):
Expand All @@ -87,19 +87,19 @@ def de_json(data, bot):
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):
Expand Down Expand Up @@ -190,9 +190,9 @@ def __init__(self, point, x_shift, y_shift, zoom, **kwargs):
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)
8 changes: 4 additions & 4 deletions telegram/files/venue.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def __init__(self, location, title, address, foursquare_id=None, **kwargs):

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)
8 changes: 4 additions & 4 deletions telegram/files/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def __init__(self,

self._id_attrs = (self.file_id,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -80,8 +80,8 @@ def de_json(data, bot):
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)
8 changes: 4 additions & 4 deletions telegram/files/videonote.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def __init__(self, file_id, length, duration, thumb=None, file_size=None, **kwar

self._id_attrs = (self.file_id,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -56,8 +56,8 @@ def de_json(data, bot):
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)
8 changes: 4 additions & 4 deletions telegram/files/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def __init__(self, file_id, duration, mime_type=None, file_size=None, **kwargs):

self._id_attrs = (self.file_id,)

@staticmethod
def de_json(data, bot):
@classmethod
def de_json(cls, data, bot):
"""
Args:
data (dict):
Expand All @@ -63,6 +63,6 @@ def de_json(data, bot):
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)
Loading