Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@classmethod
def de_json(cls, json_string):
obj = cls.check_json(json_string)
message_id = obj['message_id']
from_user = None
if 'from' in obj:
from_user = User.de_json(obj['from'])
date = obj['date']
chat = Chat.de_json(obj['chat'])
content_type = None
opts = {}
if 'forward_from' in obj:
opts['forward_from'] = User.de_json(obj['forward_from'])
if 'forward_from_chat' in obj:
opts['forward_from_chat'] = Chat.de_json(obj['forward_from_chat'])
if 'forward_from_message_id' in obj:
opts['forward_from_message_id'] = obj.get('forward_from_message_id')
if 'forward_signature' in obj:
opts['forward_signature'] = obj.get('forward_signature')
if 'forward_date' in obj:
opts['forward_date'] = obj.get('forward_date')
if 'reply_to_message' in obj:
opts['reply_to_message'] = Message.de_json(obj['reply_to_message'])
@classmethod
def de_json(cls, json_string):
obj = cls.check_json(json_string)
id = obj['id']
from_user = User.de_json(obj['from'])
currency = obj['currency']
total_amount = obj['total_amount']
invoice_payload = obj['invoice_payload']
shipping_option_id = obj.get('shipping_option_id')
order_info = None
if 'order_info' in obj:
order_info = OrderInfo.de_json(obj['order_info'])
return cls(id, from_user, currency, total_amount, invoice_payload, shipping_option_id, order_info)
@classmethod
def parse_chat(cls, chat):
if 'first_name' not in chat:
return GroupChat.de_json(chat)
else:
return User.de_json(chat)
@classmethod
def de_json(cls, json_string):
obj = cls.check_json(json_string)
type = obj['type']
offset = obj['offset']
length = obj['length']
url = obj.get('url')
user = None
if 'user' in obj:
user = User.de_json(obj['user'])
return cls(type, offset, length, url, user)
opts['contact'] = Contact.de_json(json.dumps(obj['contact']))
content_type = 'contact'
if 'location' in obj:
opts['location'] = Location.de_json(obj['location'])
content_type = 'location'
if 'venue' in obj:
opts['venue'] = Venue.de_json(obj['venue'])
content_type = 'venue'
if 'new_chat_member' in obj:
opts['new_chat_member'] = User.de_json(obj['new_chat_member'])
content_type = 'new_chat_member'
if 'new_chat_members' in obj:
chat_members = obj['new_chat_members']
nms = []
for m in chat_members:
nms.append(User.de_json(m))
opts['new_chat_members'] = nms
content_type = 'new_chat_members'
if 'left_chat_member' in obj:
opts['left_chat_member'] = User.de_json(obj['left_chat_member'])
content_type = 'left_chat_member'
if 'new_chat_title' in obj:
opts['new_chat_title'] = obj['new_chat_title']
content_type = 'new_chat_title'
if 'new_chat_photo' in obj:
opts['new_chat_photo'] = Message.parse_photo(obj['new_chat_photo'])
content_type = 'new_chat_photo'
if 'delete_chat_photo' in obj:
opts['delete_chat_photo'] = obj['delete_chat_photo']
content_type = 'delete_chat_photo'
if 'group_chat_created' in obj:
opts['group_chat_created'] = obj['group_chat_created']
@classmethod
def de_json(cls, json_string):
obj = cls.check_json(json_string)
position = obj['position']
user = User.de_json(obj['user'])
score = obj['score']
return cls(position, user, score)
@classmethod
def de_json(cls, json_type):
obj = cls.check_json(json_type)
user = User.de_json(obj['user'])
status = obj['status']
until_date = obj.get('until_date')
can_be_edited = obj.get('can_be_edited')
can_change_info = obj.get('can_change_info')
can_post_messages = obj.get('can_post_messages')
can_edit_messages = obj.get('can_edit_messages')
can_delete_messages = obj.get('can_delete_messages')
can_invite_users = obj.get('can_invite_users')
can_restrict_members = obj.get('can_restrict_members')
can_pin_messages = obj.get('can_pin_messages')
can_promote_members = obj.get('can_promote_members')
can_send_messages = obj.get('can_send_messages')
can_send_media_messages = obj.get('can_send_media_messages')
can_send_other_messages = obj.get('can_send_other_messages')
can_add_web_page_previews = obj.get('can_add_web_page_previews')
return cls(user, status, until_date, can_be_edited, can_change_info, can_post_messages, can_edit_messages,
if 'voice' in obj:
opts['voice'] = Audio.de_json(obj['voice'])
content_type = 'voice'
if 'caption' in obj:
opts['caption'] = obj['caption']
if 'contact' in obj:
opts['contact'] = Contact.de_json(json.dumps(obj['contact']))
content_type = 'contact'
if 'location' in obj:
opts['location'] = Location.de_json(obj['location'])
content_type = 'location'
if 'venue' in obj:
opts['venue'] = Venue.de_json(obj['venue'])
content_type = 'venue'
if 'new_chat_member' in obj:
opts['new_chat_member'] = User.de_json(obj['new_chat_member'])
content_type = 'new_chat_member'
if 'new_chat_members' in obj:
chat_members = obj['new_chat_members']
nms = []
for m in chat_members:
nms.append(User.de_json(m))
opts['new_chat_members'] = nms
content_type = 'new_chat_members'
if 'left_chat_member' in obj:
opts['left_chat_member'] = User.de_json(obj['left_chat_member'])
content_type = 'left_chat_member'
if 'new_chat_title' in obj:
opts['new_chat_title'] = obj['new_chat_title']
content_type = 'new_chat_title'
if 'new_chat_photo' in obj:
opts['new_chat_photo'] = Message.parse_photo(obj['new_chat_photo'])