Rename data -> raw_data

This commit is contained in:
Alex Root Junior 2017-05-26 03:51:21 +03:00
parent 44bf906110
commit 0d6af5bc8d
19 changed files with 227 additions and 240 deletions

View file

@ -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.")

View file

@ -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)

View file

@ -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)

View file

@ -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):

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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,

View file

@ -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:

View file

@ -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)

View file

@ -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)

View file

@ -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 updates unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if youre 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)

View file

@ -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 Users or bots first name
last_name String Optional. Users or bots last name
username String Optional. Users or bots 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):

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)