mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 14:35:00 +01:00
Prevented modifications to the request object's original data (#454)
fixes #357
This commit is contained in:
parent
c3984e1bf1
commit
a8fecc527d
17 changed files with 33 additions and 3 deletions
|
@ -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>`_
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -61,4 +61,6 @@ class Voice(TelegramObject):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
data = super(Voice, Voice).de_json(data, bot)
|
||||
|
||||
return Voice(**data)
|
||||
|
|
Loading…
Reference in a new issue