Prevented modifications to the request object's original data (#454)

fixes #357
This commit is contained in:
Hugo Hakim Damer 2016-12-19 23:07:35 +01:00 committed by Noam Meltzer
parent c3984e1bf1
commit a8fecc527d
17 changed files with 33 additions and 3 deletions

View file

@ -15,6 +15,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
- `Eugene Lisitsky <https://github.com/lisitsky>`_
- `franciscod <https://github.com/franciscod>`_
- `Hugo Damer <https://github.com/HakimusGIT>`_
- `Jacob Bom <https://github.com/bomjacob>`_
- `JASON0916 <https://github.com/JASON0916>`_
- `jh0ker <https://github.com/jh0ker>`_

View file

@ -55,6 +55,8 @@ class Animation(TelegramObject):
if not data:
return None
data = super(Animation, Animation).de_json(data, bot)
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
return Animation(**data)

View file

@ -60,6 +60,8 @@ class CallbackQuery(TelegramObject):
if not data:
return None
data = super(CallbackQuery, CallbackQuery).de_json(data, bot)
data['from_user'] = User.de_json(data.get('from'), bot)
data['message'] = Message.de_json(data.get('message'), bot)

View file

@ -59,6 +59,8 @@ class ChatMember(TelegramObject):
if not data:
return None
data = super(ChatMember, ChatMember).de_json(data, bot)
data['user'] = User.de_json(data.get('user'), bot)
return ChatMember(**data)

View file

@ -74,7 +74,8 @@ class ChosenInlineResult(TelegramObject):
if not data:
return None
# Required
data = super(ChosenInlineResult, ChosenInlineResult).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)

View file

@ -63,6 +63,8 @@ class Document(TelegramObject):
if not data:
return None
data = super(Document, Document).de_json(data, bot)
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
return Document(**data)

View file

@ -73,6 +73,8 @@ class Game(TelegramObject):
if not data:
return None
data = super(Game, Game).de_json(data, bot)
data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot)
data['animation'] = Animation.de_json(data.get('animation'), bot)

View file

@ -49,6 +49,8 @@ class GameHighScore(TelegramObject):
if not data:
return None
data = super(GameHighScore, GameHighScore).de_json(data, bot)
data['user'] = User.de_json(data.get('user'), bot)
return GameHighScore(**data)

View file

@ -200,6 +200,8 @@ class Message(TelegramObject):
if not data:
return None
data = super(Message, Message).de_json(data, bot)
data['from_user'] = User.de_json(data.get('from'), bot)
data['date'] = datetime.fromtimestamp(data['date'])
data['chat'] = Chat.de_json(data.get('chat'), bot)

View file

@ -67,6 +67,8 @@ class ReplyKeyboardMarkup(ReplyMarkup):
if not data:
return None
data = super(ReplyKeyboardMarkup, ReplyKeyboardMarkup).de_json(data, bot)
data['keyboard'] = [KeyboardButton.de_list(keyboard, bot) for keyboard in data['keyboard']]
return ReplyKeyboardMarkup(**data)

View file

@ -67,6 +67,8 @@ class Sticker(TelegramObject):
if not data:
return None
data = super(Sticker, Sticker).de_json(data, bot)
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
return Sticker(**data)

View file

@ -86,6 +86,8 @@ class Update(TelegramObject):
if not data:
return None
data = super(Update, Update).de_json(data, bot)
data['message'] = Message.de_json(data.get('message'), bot)
data['edited_message'] = Message.de_json(data.get('edited_message'), bot)
data['inline_query'] = InlineQuery.de_json(data.get('inline_query'), bot)

View file

@ -77,6 +77,8 @@ class User(TelegramObject):
if not data:
return None
data = super(User, User).de_json(data, bot)
return User(bot=bot, **data)
def get_profile_photos(self, *args, **kwargs):

View file

@ -52,6 +52,8 @@ class UserProfilePhotos(TelegramObject):
if not data:
return None
data = super(UserProfilePhotos, UserProfilePhotos).de_json(data, bot)
data['photos'] = [PhotoSize.de_list(photo, bot) for photo in data['photos']]
return UserProfilePhotos(**data)

View file

@ -31,8 +31,8 @@ import urllib3
from urllib3.connection import HTTPConnection
from telegram import (InputFile, TelegramError)
from telegram.error import Unauthorized, InvalidToken, NetworkError, TimedOut, BadRequest, \
ChatMigrated, RetryAfter
from telegram.error import (Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated,
RetryAfter, InvalidToken)
logging.getLogger('urllib3').setLevel(logging.WARNING)

View file

@ -78,6 +78,8 @@ class Video(TelegramObject):
if not data:
return None
data = super(Video, Video).de_json(data, bot)
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
return Video(**data)

View file

@ -61,4 +61,6 @@ class Voice(TelegramObject):
if not data:
return None
data = super(Voice, Voice).de_json(data, bot)
return Voice(**data)