mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-14 10:53:23 +00:00
Optimize deserializer
This commit is contained in:
parent
579b294d26
commit
6f40b9c0cf
4 changed files with 8 additions and 9 deletions
|
|
@ -89,8 +89,7 @@ class Deserializable:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def deserialize(cls, obj):
|
def deserialize(cls, obj):
|
||||||
|
if isinstance(obj, list):
|
||||||
|
return deserialize_array(cls, obj)
|
||||||
return deserialize(cls, obj)
|
return deserialize(cls, obj)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def deserialize_array(cls, objs):
|
|
||||||
return deserialize_array(cls, objs)
|
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ class Game(Deserializable):
|
||||||
|
|
||||||
title = raw_data.get('title')
|
title = raw_data.get('title')
|
||||||
description = raw_data.get('description')
|
description = raw_data.get('description')
|
||||||
photo = PhotoSize.deserialize_array(raw_data.get('photo'))
|
photo = PhotoSize.deserialize(raw_data.get('photo'))
|
||||||
text = raw_data.get('text')
|
text = raw_data.get('text')
|
||||||
text_entities = MessageEntity.deserialize_array(raw_data.get('text_entities'))
|
text_entities = MessageEntity.deserialize(raw_data.get('text_entities'))
|
||||||
animation = Animation.deserialize(raw_data.get('animation'))
|
animation = Animation.deserialize(raw_data.get('animation'))
|
||||||
|
|
||||||
return Game(title, description, photo, text, text_entities, animation)
|
return Game(title, description, photo, text, text_entities, animation)
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class Message(Deserializable):
|
||||||
reply_to_message = Message.deserialize(raw_data.get('reply_to_message', {}))
|
reply_to_message = Message.deserialize(raw_data.get('reply_to_message', {}))
|
||||||
edit_date = cls._parse_date(raw_data.get('edit_date', 0))
|
edit_date = cls._parse_date(raw_data.get('edit_date', 0))
|
||||||
text = raw_data.get('text')
|
text = raw_data.get('text')
|
||||||
entities = MessageEntity.deserialize_array(raw_data.get('entities'))
|
entities = MessageEntity.deserialize(raw_data.get('entities'))
|
||||||
audio = Audio.deserialize(raw_data.get('audio'))
|
audio = Audio.deserialize(raw_data.get('audio'))
|
||||||
document = Document.deserialize(raw_data.get('document'))
|
document = Document.deserialize(raw_data.get('document'))
|
||||||
game = Game.deserialize(raw_data.get('game'))
|
game = Game.deserialize(raw_data.get('game'))
|
||||||
|
|
@ -95,7 +95,7 @@ class Message(Deserializable):
|
||||||
video = Video.deserialize(raw_data.get('video'))
|
video = Video.deserialize(raw_data.get('video'))
|
||||||
voice = Voice.deserialize(raw_data.get('voice'))
|
voice = Voice.deserialize(raw_data.get('voice'))
|
||||||
video_note = VideoNote.deserialize(raw_data.get('video_note'))
|
video_note = VideoNote.deserialize(raw_data.get('video_note'))
|
||||||
new_chat_members = User.deserialize_array(raw_data.get('new_chat_members'))
|
new_chat_members = User.deserialize(raw_data.get('new_chat_members'))
|
||||||
caption = raw_data.get('caption')
|
caption = raw_data.get('caption')
|
||||||
contact = Contact.deserialize(raw_data.get('contact'))
|
contact = Contact.deserialize(raw_data.get('contact'))
|
||||||
location = Location.deserialize(raw_data.get('location'))
|
location = Location.deserialize(raw_data.get('location'))
|
||||||
|
|
@ -103,7 +103,7 @@ class Message(Deserializable):
|
||||||
left_chat_member = User.deserialize(raw_data.get('left_chat_member'))
|
left_chat_member = User.deserialize(raw_data.get('left_chat_member'))
|
||||||
new_chat_title = raw_data.get('new_chat_title')
|
new_chat_title = raw_data.get('new_chat_title')
|
||||||
new_chat_photo = raw_data.get('new_chat_photo')
|
new_chat_photo = raw_data.get('new_chat_photo')
|
||||||
delete_chat_photo = PhotoSize.deserialize_array(raw_data.get('delete_chat_photo'))
|
delete_chat_photo = PhotoSize.deserialize(raw_data.get('delete_chat_photo'))
|
||||||
group_chat_created = raw_data.get('group_chat_created')
|
group_chat_created = raw_data.get('group_chat_created')
|
||||||
supergroup_chat_created = raw_data.get('supergroup_chat_created')
|
supergroup_chat_created = raw_data.get('supergroup_chat_created')
|
||||||
channel_chat_created = raw_data.get('channel_chat_created')
|
channel_chat_created = raw_data.get('channel_chat_created')
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,6 @@ class UserProfilePhotos(Deserializable):
|
||||||
raw_data = cls.check_json(raw_data)
|
raw_data = cls.check_json(raw_data)
|
||||||
|
|
||||||
total_count = raw_data.get('total_count')
|
total_count = raw_data.get('total_count')
|
||||||
photos = PhotoSize.deserialize_array(raw_data.get('photos'))
|
photos = PhotoSize.deserialize(raw_data.get('photos'))
|
||||||
|
|
||||||
return UserProfilePhotos(total_count, photos)
|
return UserProfilePhotos(total_count, photos)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue