From 0d6af5bc8de20e9dbfb3c168926ff2c2288bd907 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Fri, 26 May 2017 03:51:21 +0300 Subject: [PATCH] Rename data -> raw_data --- aiogram/types/__init__.py | 24 +++++--- aiogram/types/audio.py | 23 ++++---- aiogram/types/callback_query.py | 24 ++++---- aiogram/types/chat.py | 26 ++++---- aiogram/types/contact.py | 19 +++--- aiogram/types/document.py | 21 ++++--- aiogram/types/file.py | 17 +++--- aiogram/types/location.py | 13 ++-- aiogram/types/message.py | 88 ++++++++++++++-------------- aiogram/types/message_entity.py | 22 ++++--- aiogram/types/photo_size.py | 12 ++-- aiogram/types/sticker.py | 23 ++++---- aiogram/types/update.py | 32 +++++----- aiogram/types/user.py | 24 ++++---- aiogram/types/user_profile_photos.py | 15 +++-- aiogram/types/venue.py | 19 +++--- aiogram/types/video.py | 25 ++++---- aiogram/types/video_note.py | 21 ++++--- aiogram/types/voice.py | 19 +++--- 19 files changed, 227 insertions(+), 240 deletions(-) diff --git a/aiogram/types/__init__.py b/aiogram/types/__init__.py index 6e630934..dad21861 100644 --- a/aiogram/types/__init__.py +++ b/aiogram/types/__init__.py @@ -19,10 +19,18 @@ class Deserializable: """ def to_json(self): - return getattr(self, 'data', {}) + result = {} + for item in self.__slots__ or list(self.__dict__.keys()): + attr = getattr(self, item) + if not attr: + continue + if hasattr(attr, 'to_json'): + attr = getattr(attr, 'to_json')() + result[item] = attr + return result @classmethod - def de_json(cls, data): + def de_json(cls, raw_data): """ Returns an instance of this class from the given json dict or string. @@ -32,18 +40,18 @@ class Deserializable: raise NotImplementedError @staticmethod - def check_json(data) -> dict: + def check_json(raw_data) -> dict: """ Checks whether json_type is a dict or a string. If it is already a dict, it is returned as-is. If it is not, it is converted to a dict by means of json.loads(json_type) - :param data: + :param raw_data: :return: """ - if isinstance(data, dict): - return data - elif isinstance(data, str): - return json.loads(data) + if isinstance(raw_data, dict): + return raw_data + elif isinstance(raw_data, str): + return json.loads(raw_data) else: raise ValueError("data should be a json dict or string.") diff --git a/aiogram/types/audio.py b/aiogram/types/audio.py index b5260132..7d22881b 100644 --- a/aiogram/types/audio.py +++ b/aiogram/types/audio.py @@ -2,10 +2,9 @@ from . import Deserializable class Audio(Deserializable): - __slots__ = ('data', 'file_id', 'duration', 'performer', 'title', 'mime_type', 'file_size') + __slots__ = ('file_id', 'duration', 'performer', 'title', 'mime_type', 'file_size') - def __init__(self, data, file_id, duration, performer, title, mime_type, file_size): - self.data = data + def __init__(self, file_id, duration, performer, title, mime_type, file_size): self.file_id = file_id self.duration = duration self.performer = performer @@ -14,14 +13,14 @@ class Audio(Deserializable): self.file_size = file_size @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - file_id = data.get('file_id') - duration = data.get('duration') - performer = data.get('performer') - title = data.get('title') - mime_type = data.get('mime_type') - file_size = data.get('file_size') + file_id = raw_data.get('file_id') + duration = raw_data.get('duration') + performer = raw_data.get('performer') + title = raw_data.get('title') + mime_type = raw_data.get('mime_type') + file_size = raw_data.get('file_size') - return Audio(data, file_id, duration, performer, title, mime_type, file_size) + return Audio(file_id, duration, performer, title, mime_type, file_size) diff --git a/aiogram/types/callback_query.py b/aiogram/types/callback_query.py index c37ebbaf..a7db0d17 100644 --- a/aiogram/types/callback_query.py +++ b/aiogram/types/callback_query.py @@ -2,9 +2,9 @@ from . import Deserializable class CallbackQuery(Deserializable): - __slots__ = ('data', 'id', 'from', 'message', 'inline_message_id', 'chat_instance', 'data', 'game_short_name') + __slots__ = ('id', 'from', 'message', 'inline_message_id', 'chat_instance', 'data', 'game_short_name') - def __init__(self, data, id, from_user, message, inline_message_id, chat_instance, data, game_short_name): + def __init__(self, id, from_user, message, inline_message_id, chat_instance, data, game_short_name): self.data = data self.id = id self.from_user = from_user @@ -15,15 +15,15 @@ class CallbackQuery(Deserializable): self.game_short_name = game_short_name @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - id = data.get('id') - from_user = data.get('from') - message = data.get('message') - inline_message_id = data.get('inline_message_id') - chat_instance = data.get('chat_instance') - data = data.get('data') - game_short_name = data.get('game_short_name') + id = raw_data.get('id') + from_user = raw_data.get('from') + message = raw_data.get('message') + inline_message_id = raw_data.get('inline_message_id') + chat_instance = raw_data.get('chat_instance') + data = raw_data.get('data') + game_short_name = raw_data.get('game_short_name') - return CallbackQuery(data, id, from_user, message, inline_message_id, chat_instance, data, game_short_name) + return CallbackQuery(id, from_user, message, inline_message_id, chat_instance, data, game_short_name) diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index dc7d3cc4..00ad5af3 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -4,9 +4,7 @@ from . import Deserializable class Chat(Deserializable): __slots__ = ('id', 'type', 'title', 'username', 'first_name', 'last_name', 'all_members_are_administrators') - def __init__(self, data, id, type, title, username, first_name, last_name, all_members_are_administrators): - self.data = data - + def __init__(self, id, type, title, username, first_name, last_name, all_members_are_administrators): self.id: int = id self.type: str = type self.title: str = title @@ -16,7 +14,7 @@ class Chat(Deserializable): self.all_members_are_administrators: bool = all_members_are_administrators @classmethod - def de_json(cls, data) -> 'Chat': + def de_json(cls, raw_data) -> 'Chat': """ id Integer Unique identifier for this chat. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. type String Type of chat, can be either “private”, “group”, “supergroup” or “channel” @@ -25,20 +23,20 @@ class Chat(Deserializable): first_name String Optional. First name of the other party in a private chat last_name String Optional. Last name of the other party in a private chat all_members_are_administrators Boolean Optional. True if a group has ‘All Members Are Admins’ enabled. - :param data: + :param raw_data: :return: """ - data = cls.check_json(data) + raw_data = cls.check_json(raw_data) - id: int = data.get('id') - type: str = data.get('type') - title: str = data.get('title') - username: str = data.get('username') - first_name: str = data.get('first_name') - last_name: str = data.get('last_name') - all_members_are_administrators: bool = data.get('all_members_are_administrators', False) + id: int = raw_data.get('id') + type: str = raw_data.get('type') + title: str = raw_data.get('title') + username: str = raw_data.get('username') + first_name: str = raw_data.get('first_name') + last_name: str = raw_data.get('last_name') + all_members_are_administrators: bool = raw_data.get('all_members_are_administrators', False) - return Chat(data, id, type, title, username, first_name, last_name, all_members_are_administrators) + return Chat(id, type, title, username, first_name, last_name, all_members_are_administrators) @property def full_name(self): diff --git a/aiogram/types/contact.py b/aiogram/types/contact.py index 6639f5eb..6895b978 100644 --- a/aiogram/types/contact.py +++ b/aiogram/types/contact.py @@ -2,22 +2,21 @@ from . import Deserializable class Contact(Deserializable): - __slots__ = ('data', 'phone_number', 'first_name', 'last_name', 'user_id') + __slots__ = ('phone_number', 'first_name', 'last_name', 'user_id') - def __init__(self, data, phone_number, first_name, last_name, user_id): - self.data = data + def __init__(self, phone_number, first_name, last_name, user_id): self.phone_number = phone_number self.first_name = first_name self.last_name = last_name self.user_id = user_id @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - phone_number = data.get('phone_number') - first_name = data.get('first_name') - last_name = data.get('last_name') - user_id = data.get('user_id') + phone_number = raw_data.get('phone_number') + first_name = raw_data.get('first_name') + last_name = raw_data.get('last_name') + user_id = raw_data.get('user_id') - return Contact(data, phone_number, first_name, last_name, user_id) + return Contact(phone_number, first_name, last_name, user_id) diff --git a/aiogram/types/document.py b/aiogram/types/document.py index 807dac3f..a7126fe2 100644 --- a/aiogram/types/document.py +++ b/aiogram/types/document.py @@ -2,10 +2,9 @@ from . import Deserializable class Document(Deserializable): - __slots__ = ('data', 'file_id', 'thumb', 'file_name', 'mime_type', 'file_size') + __slots__ = ('file_id', 'thumb', 'file_name', 'mime_type', 'file_size') - def __init__(self, data, file_id, thumb, file_name, mime_type, file_size): - self.data = data + def __init__(self, file_id, thumb, file_name, mime_type, file_size): self.file_id = file_id self.thumb = thumb self.file_name = file_name @@ -13,13 +12,13 @@ class Document(Deserializable): self.file_size = file_size @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - file_id = data.get('file_id') - thumb = data.get('thumb') - file_name = data.get('file_name') - mime_type = data.get('mime_type') - file_size = data.get('file_size') + file_id = raw_data.get('file_id') + thumb = raw_data.get('thumb') + file_name = raw_data.get('file_name') + mime_type = raw_data.get('mime_type') + file_size = raw_data.get('file_size') - return Document(data, file_id, thumb, file_name, mime_type, file_size) + return Document(file_id, thumb, file_name, mime_type, file_size) diff --git a/aiogram/types/file.py b/aiogram/types/file.py index 8f478b50..e276c01a 100644 --- a/aiogram/types/file.py +++ b/aiogram/types/file.py @@ -2,20 +2,19 @@ from . import Deserializable class File(Deserializable): - __slots__ = ('data', 'file_id', 'file_size', 'file_path') + __slots__ = ('file_id', 'file_size', 'file_path') - def __init__(self, data, file_id, file_size, file_path): - self.data = data + def __init__(self, file_id, file_size, file_path): self.file_id = file_id self.file_size = file_size self.file_path = file_path @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - file_id = data.get('file_id') - file_size = data.get('file_size') - file_path = data.get('file_path') + file_id = raw_data.get('file_id') + file_size = raw_data.get('file_size') + file_path = raw_data.get('file_path') - return File(data, file_id, file_size, file_path) + return File(file_id, file_size, file_path) diff --git a/aiogram/types/location.py b/aiogram/types/location.py index c2cf1e3f..3cb80766 100644 --- a/aiogram/types/location.py +++ b/aiogram/types/location.py @@ -2,18 +2,17 @@ from . import Deserializable class Location(Deserializable): - __slots__ = ('data', 'longitude', 'latitude') + __slots__ = ('longitude', 'latitude') def __init__(self, data, longitude, latitude): - self.data = data self.longitude = longitude self.latitude = latitude @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - longitude = data.get('longitude') - latitude = data.get('latitude') + longitude = raw_data.get('longitude') + latitude = raw_data.get('latitude') - return Location(data, longitude, latitude) + return Location(longitude, latitude) diff --git a/aiogram/types/message.py b/aiogram/types/message.py index 2fe658f4..4588e4f2 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -8,21 +8,19 @@ from .user import User class Message(Deserializable): __slots__ = ( - 'data', 'message_id', 'from', 'date', 'chat', 'forward_from', 'forward_from_chat', 'forward_from_message_id', + 'message_id', 'from', 'date', 'chat', 'forward_from', 'forward_from_chat', 'forward_from_message_id', 'forward_date', 'reply_to_message', 'edit_date', 'text', 'entities', 'audio', 'document', 'game', 'photo', 'sticker', 'video', 'voice', 'video_note', 'new_chat_members', 'caption', 'contact', 'location', 'venue', 'new_chat_member', 'left_chat_member', 'new_chat_title', 'new_chat_photo', 'delete_chat_photo', 'group_chat_created', 'supergroup_chat_created', 'channel_chat_created', 'migrate_to_chat_id', 'migrate_from_chat_id', 'pinned_message', 'invoice', 'successful_payment', 'content_type') - def __init__(self, data, message_id, from_user, date, chat, forward_from, forward_from_chat, + def __init__(self, message_id, from_user, date, chat, forward_from, forward_from_chat, forward_from_message_id, forward_date, reply_to_message, edit_date, text, entities, audio, document, game, photo, sticker, video, voice, video_note, new_chat_members, caption, contact, location, venue, new_chat_member, left_chat_member, new_chat_title, new_chat_photo, delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created, migrate_to_chat_id, migrate_from_chat_id, pinned_message, invoice, successful_payment, content_type): - self.data = data - self.message_id: int = message_id self.from_user: User = from_user self.date: datetime.datetime = date @@ -86,48 +84,48 @@ class Message(Deserializable): return [MessageEntity.de_json(entity) for entity in entities] if entities else None @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - message_id = data.get('message_id') - from_user = cls._parse_user(data.get('from')) - date = cls._parse_date(data.get('date', 0)) - chat = cls._parse_chat(data.get('chat', {})) - forward_from = cls._parse_user(data.get('forward_from', {})) - forward_from_chat = cls._parse_chat(data.get('forward_from_chat', {})) - forward_from_message_id = data.get('forward_from_message_id') - forward_date = cls._parse_date(data.get('forward_date', 0)) - reply_to_message = cls._parse_message(data.get('reply_to_message', {})) - edit_date = cls._parse_date(data.get('edit_date', 0)) - text = data.get('text') - entities = cls._parse_entities(data.get('entities')) + message_id = raw_data.get('message_id') + from_user = cls._parse_user(raw_data.get('from')) + date = cls._parse_date(raw_data.get('date', 0)) + chat = cls._parse_chat(raw_data.get('chat', {})) + forward_from = cls._parse_user(raw_data.get('forward_from', {})) + forward_from_chat = cls._parse_chat(raw_data.get('forward_from_chat', {})) + forward_from_message_id = raw_data.get('forward_from_message_id') + forward_date = cls._parse_date(raw_data.get('forward_date', 0)) + reply_to_message = cls._parse_message(raw_data.get('reply_to_message', {})) + edit_date = cls._parse_date(raw_data.get('edit_date', 0)) + text = raw_data.get('text') + entities = cls._parse_entities(raw_data.get('entities')) - audio = data.get('audio') - document = data.get('document') - game = data.get('game') - photo = data.get('photo') - sticker = data.get('sticker') - video = data.get('video') - voice = data.get('voice') - video_note = data.get('video_note') - new_chat_members = data.get('new_chat_members') - caption = data.get('caption') - contact = data.get('contact') - location = data.get('location') - venue = data.get('venue') - new_chat_member = data.get('new_chat_member') - left_chat_member = data.get('left_chat_member') - new_chat_title = data.get('new_chat_title') - new_chat_photo = data.get('new_chat_photo') - delete_chat_photo = data.get('delete_chat_photo') - group_chat_created = data.get('group_chat_created') - supergroup_chat_created = data.get('supergroup_chat_created') - channel_chat_created = data.get('channel_chat_created') - migrate_to_chat_id = data.get('migrate_to_chat_id') - migrate_from_chat_id = data.get('migrate_from_chat_id') - pinned_message = data.get('pinned_message') - invoice = data.get('invoice') - successful_payment = data.get('successful_payment') + audio = raw_data.get('audio') + document = raw_data.get('document') + game = raw_data.get('game') + photo = raw_data.get('photo') + sticker = raw_data.get('sticker') + video = raw_data.get('video') + voice = raw_data.get('voice') + video_note = raw_data.get('video_note') + new_chat_members = raw_data.get('new_chat_members') + caption = raw_data.get('caption') + contact = raw_data.get('contact') + location = raw_data.get('location') + venue = raw_data.get('venue') + new_chat_member = raw_data.get('new_chat_member') + left_chat_member = raw_data.get('left_chat_member') + new_chat_title = raw_data.get('new_chat_title') + new_chat_photo = raw_data.get('new_chat_photo') + delete_chat_photo = raw_data.get('delete_chat_photo') + group_chat_created = raw_data.get('group_chat_created') + supergroup_chat_created = raw_data.get('supergroup_chat_created') + channel_chat_created = raw_data.get('channel_chat_created') + migrate_to_chat_id = raw_data.get('migrate_to_chat_id') + migrate_from_chat_id = raw_data.get('migrate_from_chat_id') + pinned_message = raw_data.get('pinned_message') + invoice = raw_data.get('invoice') + successful_payment = raw_data.get('successful_payment') if text: content_type = ContentType.TEXT @@ -156,7 +154,7 @@ class Message(Deserializable): else: content_type = ContentType.UNKNOWN - return Message(data, message_id, from_user, date, chat, forward_from, forward_from_chat, + return Message(message_id, from_user, date, chat, forward_from, forward_from_chat, forward_from_message_id, forward_date, reply_to_message, edit_date, text, entities, audio, document, game, photo, sticker, video, voice, video_note, new_chat_members, caption, contact, location, venue, new_chat_member, left_chat_member, new_chat_title, new_chat_photo, diff --git a/aiogram/types/message_entity.py b/aiogram/types/message_entity.py index 9baf8e61..561ff586 100644 --- a/aiogram/types/message_entity.py +++ b/aiogram/types/message_entity.py @@ -3,11 +3,9 @@ from .user import User class MessageEntity(Deserializable): - __slots__ = ('data', 'type', 'offset', 'length', 'url', 'user') - - def __init__(self, data, type, offset, length, url, user): - self.data = data + __slots__ = ('type', 'offset', 'length', 'url', 'user') + def __init__(self, type, offset, length, url, user): self.type = type self.offset = offset self.length = length @@ -19,16 +17,16 @@ class MessageEntity(Deserializable): return User.de_json(user) if user else None @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - type = data.get('type') - offset = data.get('offset') - length = data.get('length') - url = data.get('url') - user = cls._parse_user(data.get('user')) + type = raw_data.get('type') + offset = raw_data.get('offset') + length = raw_data.get('length') + url = raw_data.get('url') + user = cls._parse_user(raw_data.get('user')) - return MessageEntity(data, type, offset, length, url, user) + return MessageEntity(type, offset, length, url, user) class MessageEntityType: diff --git a/aiogram/types/photo_size.py b/aiogram/types/photo_size.py index 843172fe..ac952b59 100644 --- a/aiogram/types/photo_size.py +++ b/aiogram/types/photo_size.py @@ -11,12 +11,12 @@ class PhotoSize(Deserializable): self.file_size = file_size @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - file_id = data.get('file_id') - width = data.get('width') - height = data.get('height') - file_size = data.get('file_size') + file_id = raw_data.get('file_id') + width = raw_data.get('width') + height = raw_data.get('height') + file_size = raw_data.get('file_size') return PhotoSize(file_id, width, height, file_size) diff --git a/aiogram/types/sticker.py b/aiogram/types/sticker.py index 999d83dc..839fb979 100644 --- a/aiogram/types/sticker.py +++ b/aiogram/types/sticker.py @@ -2,10 +2,9 @@ from . import Deserializable class Sticker(Deserializable): - __slots__ = ('data', 'file_id', 'width', 'height', 'thumb', 'emoji', 'file_size') + __slots__ = ('file_id', 'width', 'height', 'thumb', 'emoji', 'file_size') - def __init__(self, data, file_id, width, height, thumb, emoji, file_size): - self.data = data + def __init__(self, file_id, width, height, thumb, emoji, file_size): self.file_id = file_id self.width = width self.height = height @@ -14,14 +13,14 @@ class Sticker(Deserializable): self.file_size = file_size @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - file_id = data.get('file_id') - width = data.get('width') - height = data.get('height') - thumb = data.get('thumb') - emoji = data.get('emoji') - file_size = data.get('file_size') + file_id = raw_data.get('file_id') + width = raw_data.get('width') + height = raw_data.get('height') + thumb = raw_data.get('thumb') + emoji = raw_data.get('emoji') + file_size = raw_data.get('file_size') - return Sticker(data, file_id, width, height, thumb, emoji, file_size) + return Sticker(file_id, width, height, thumb, emoji, file_size) diff --git a/aiogram/types/update.py b/aiogram/types/update.py index 30713fd9..21198c1a 100644 --- a/aiogram/types/update.py +++ b/aiogram/types/update.py @@ -6,10 +6,8 @@ class Update(Deserializable): __slots__ = ('update_id', 'message', 'edited_message', 'channel_post', 'edited_channel_post', 'inline_query', 'chosen_inline_result', 'callback_query', 'shipping_query', 'pre_checkout_query') - def __init__(self, data, update_id, message, edited_message, channel_post, edited_channel_post, inline_query, + def __init__(self, update_id, message, edited_message, channel_post, edited_channel_post, inline_query, chosen_inline_result, callback_query, shipping_query, pre_checkout_query): - self.data = data - self.update_id = update_id self.message: Message = message self.edited_message: Message = edited_message @@ -26,7 +24,7 @@ class Update(Deserializable): return Message.de_json(message) if message else None @classmethod - def de_json(cls, data): + def de_json(cls, raw_data): """ update_id Integer The update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. message Message Optional. New incoming message of any kind — text, photo, sticker, etc. @@ -38,22 +36,22 @@ class Update(Deserializable): callback_query CallbackQuery Optional. New incoming callback query shipping_query ShippingQuery Optional. New incoming shipping query. Only for invoices with flexible price pre_checkout_query PreCheckoutQuery Optional. New incoming pre-checkout query. Contains full information about checkout - :param data: + :param raw_data: :return: """ - data = cls.check_json(data) + raw_data = cls.check_json(raw_data) - update_id = data.get('update_id') - message = cls._parse_message(data.get('message')) - edited_message = cls._parse_message(data.get('edited_message')) - channel_post = cls._parse_message(data.get('channel_post')) - edited_channel_post = cls._parse_message(data.get('edited_channel_post')) + update_id = raw_data.get('update_id') + message = cls._parse_message(raw_data.get('message')) + edited_message = cls._parse_message(raw_data.get('edited_message')) + channel_post = cls._parse_message(raw_data.get('channel_post')) + edited_channel_post = cls._parse_message(raw_data.get('edited_channel_post')) - inline_query = data.get('inline_query') - chosen_inline_result = data.get('chosen_inline_result') - callback_query = data.get('callback_query') - shipping_query = data.get('shipping_query') - pre_checkout_query = data.get('pre_checkout_query') + inline_query = raw_data.get('inline_query') + chosen_inline_result = raw_data.get('chosen_inline_result') + callback_query = raw_data.get('callback_query') + shipping_query = raw_data.get('shipping_query') + pre_checkout_query = raw_data.get('pre_checkout_query') - return Update(data, update_id, message, edited_message, channel_post, edited_channel_post, inline_query, + return Update(update_id, message, edited_message, channel_post, edited_channel_post, inline_query, chosen_inline_result, callback_query, shipping_query, pre_checkout_query) diff --git a/aiogram/types/user.py b/aiogram/types/user.py index 7fd37ca5..fefd8f20 100644 --- a/aiogram/types/user.py +++ b/aiogram/types/user.py @@ -3,11 +3,9 @@ from ..utils.user_language import get_language class User(Deserializable): - __slots__ = ('data', 'id', 'first_name', 'last_name', 'username', 'language_code') - - def __init__(self, data, id, first_name, last_name, username, language_code): - self.data: dict = data + __slots__ = ('id', 'first_name', 'last_name', 'username', 'language_code') + def __init__(self, id, first_name, last_name, username, language_code): self.id: int = id self.first_name: str = first_name self.last_name: str = last_name @@ -15,25 +13,25 @@ class User(Deserializable): self.language_code: str = language_code @classmethod - def de_json(cls, data: str or dict) -> 'User': + def de_json(cls, raw_data: str or dict) -> 'User': """ id Integer Unique identifier for this user or bot first_name String User‘s or bot’s first name last_name String Optional. User‘s or bot’s last name username String Optional. User‘s or bot’s username language_code String Optional. IETF language tag of the user's language - :param data: + :param raw_data: :return: """ - data = cls.check_json(data) + raw_data = cls.check_json(raw_data) - id = data.get('id') - first_name = data.get('first_name') - last_name = data.get('last_name') - username = data.get('username') - language_code = data.get('language_code') + id = raw_data.get('id') + first_name = raw_data.get('first_name') + last_name = raw_data.get('last_name') + username = raw_data.get('username') + language_code = raw_data.get('language_code') - return User(data, id, first_name, last_name, username, language_code) + return User(id, first_name, last_name, username, language_code) @property def full_name(self): diff --git a/aiogram/types/user_profile_photos.py b/aiogram/types/user_profile_photos.py index 767ca2a5..ed4db003 100644 --- a/aiogram/types/user_profile_photos.py +++ b/aiogram/types/user_profile_photos.py @@ -2,18 +2,17 @@ from . import Deserializable class UserProfilePhotos(Deserializable): - __slots__ = ('data', 'total_count', 'photos') + __slots__ = ('total_count', 'photos') - def __init__(self, data, total_count, photos): - self.data = data + def __init__(self, total_count, photos): self.total_count = total_count self.photos = photos @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - total_count = data.get('total_count') - photos = data.get('photos') + total_count = raw_data.get('total_count') + photos = raw_data.get('photos') - return UserProfilePhotos(data, total_count, photos) + return UserProfilePhotos(total_count, photos) diff --git a/aiogram/types/venue.py b/aiogram/types/venue.py index 810d4e1d..0847da35 100644 --- a/aiogram/types/venue.py +++ b/aiogram/types/venue.py @@ -2,22 +2,21 @@ from . import Deserializable class Venue(Deserializable): - __slots__ = ('data', 'location', 'title', 'address', 'foursquare_id') + __slots__ = ('location', 'title', 'address', 'foursquare_id') - def __init__(self, data, location, title, address, foursquare_id): - self.data = data + def __init__(self, location, title, address, foursquare_id): self.location = location self.title = title self.address = address self.foursquare_id = foursquare_id @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - location = data.get('location') - title = data.get('title') - address = data.get('address') - foursquare_id = data.get('foursquare_id') + location = raw_data.get('location') + title = raw_data.get('title') + address = raw_data.get('address') + foursquare_id = raw_data.get('foursquare_id') - return Venue(data, location, title, address, foursquare_id) + return Venue(location, title, address, foursquare_id) diff --git a/aiogram/types/video.py b/aiogram/types/video.py index bb05fdb0..ae296af6 100644 --- a/aiogram/types/video.py +++ b/aiogram/types/video.py @@ -2,10 +2,9 @@ from . import Deserializable class Video(Deserializable): - __slots__ = ('data', 'file_id', 'width', 'height', 'duration', 'thumb', 'mime_type', 'file_size') + __slots__ = ('file_id', 'width', 'height', 'duration', 'thumb', 'mime_type', 'file_size') - def __init__(self, data, file_id, width, height, duration, thumb, mime_type, file_size): - self.data = data + def __init__(self, file_id, width, height, duration, thumb, mime_type, file_size): self.file_id = file_id self.width = width self.height = height @@ -15,15 +14,15 @@ class Video(Deserializable): self.file_size = file_size @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - file_id = data.get('file_id') - width = data.get('width') - height = data.get('height') - duration = data.get('duration') - thumb = data.get('thumb') - mime_type = data.get('mime_type') - file_size = data.get('file_size') + file_id = raw_data.get('file_id') + width = raw_data.get('width') + height = raw_data.get('height') + duration = raw_data.get('duration') + thumb = raw_data.get('thumb') + mime_type = raw_data.get('mime_type') + file_size = raw_data.get('file_size') - return Video(data, file_id, width, height, duration, thumb, mime_type, file_size) + return Video(file_id, width, height, duration, thumb, mime_type, file_size) diff --git a/aiogram/types/video_note.py b/aiogram/types/video_note.py index f3892d6a..dd2ff966 100644 --- a/aiogram/types/video_note.py +++ b/aiogram/types/video_note.py @@ -2,10 +2,9 @@ from . import Deserializable class VideoNote(Deserializable): - __slots__ = ('data', 'file_id', 'length', 'duration', 'thumb', 'file_size') + __slots__ = ('file_id', 'length', 'duration', 'thumb', 'file_size') - def __init__(self, data, file_id, length, duration, thumb, file_size): - self.data = data + def __init__(self, file_id, length, duration, thumb, file_size): self.file_id = file_id self.length = length self.duration = duration @@ -13,13 +12,13 @@ class VideoNote(Deserializable): self.file_size = file_size @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - file_id = data.get('file_id') - length = data.get('length') - duration = data.get('duration') - thumb = data.get('thumb') - file_size = data.get('file_size') + file_id = raw_data.get('file_id') + length = raw_data.get('length') + duration = raw_data.get('duration') + thumb = raw_data.get('thumb') + file_size = raw_data.get('file_size') - return VideoNote(data, file_id, length, duration, thumb, file_size) + return VideoNote(file_id, length, duration, thumb, file_size) diff --git a/aiogram/types/voice.py b/aiogram/types/voice.py index 592391d5..d8c84e5c 100644 --- a/aiogram/types/voice.py +++ b/aiogram/types/voice.py @@ -2,22 +2,21 @@ from . import Deserializable class Voice(Deserializable): - __slots__ = ('data', 'file_id', 'duration', 'mime_type', 'file_size') + __slots__ = ('file_id', 'duration', 'mime_type', 'file_size') - def __init__(self, data, file_id, duration, mime_type, file_size): - self.data = data + def __init__(self, file_id, duration, mime_type, file_size): self.file_id = file_id self.duration = duration self.mime_type = mime_type self.file_size = file_size @classmethod - def de_json(cls, data): - data = cls.check_json(data) + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) - file_id = data.get('file_id') - duration = data.get('duration') - mime_type = data.get('mime_type') - file_size = data.get('file_size') + file_id = raw_data.get('file_id') + duration = raw_data.get('duration') + mime_type = raw_data.get('mime_type') + file_size = raw_data.get('file_size') - return Voice(data, file_id, duration, mime_type, file_size) + return Voice(file_id, duration, mime_type, file_size)