From 6459ce0a07a6105b435ba9642d099d7d9cb5ad06 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 21 Jul 2019 01:03:19 +0200 Subject: [PATCH] Fix lots of bound methods breaking due to latest changes on parse_mode Addresses #287 --- .../methods/messages/edit_inline_caption.py | 4 +++- .../methods/messages/edit_message_caption.py | 2 +- pyrogram/client/parser/parser.py | 7 +++++-- .../bots_and_keyboards/callback_query.py | 4 ++-- .../types/messages_and_media/message.py | 20 +++++++++---------- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/pyrogram/client/methods/messages/edit_inline_caption.py b/pyrogram/client/methods/messages/edit_inline_caption.py index 2d904198..298e3ef4 100644 --- a/pyrogram/client/methods/messages/edit_inline_caption.py +++ b/pyrogram/client/methods/messages/edit_inline_caption.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.client.ext import BaseClient @@ -25,7 +27,7 @@ class EditInlineCaption(BaseClient): self, inline_message_id: str, caption: str, - parse_mode: str = "", + parse_mode: Union[str, None] = object, reply_markup: "pyrogram.InlineKeyboardMarkup" = None ) -> bool: """Edit the caption of **inline** media messages. diff --git a/pyrogram/client/methods/messages/edit_message_caption.py b/pyrogram/client/methods/messages/edit_message_caption.py index 6fefe0b2..c760c675 100644 --- a/pyrogram/client/methods/messages/edit_message_caption.py +++ b/pyrogram/client/methods/messages/edit_message_caption.py @@ -28,7 +28,7 @@ class EditMessageCaption(BaseClient): chat_id: Union[int, str], message_id: int, caption: str, - parse_mode: str = "", + parse_mode: Union[str, None] = object, reply_markup: "pyrogram.InlineKeyboardMarkup" = None ) -> "pyrogram.Message": """Edit the caption of media messages. diff --git a/pyrogram/client/parser/parser.py b/pyrogram/client/parser/parser.py index e6681b32..edf9553d 100644 --- a/pyrogram/client/parser/parser.py +++ b/pyrogram/client/parser/parser.py @@ -34,7 +34,10 @@ class Parser: text = str(text or "").strip() if mode == object: - mode = self.client.parse_mode + if self.client: + mode = self.client.parse_mode + else: + mode = "combined" if mode is None: return OrderedDict([ @@ -54,7 +57,7 @@ class Parser: return self.html.parse(text) raise ValueError('parse_mode must be one of {} or None. Not "{}"'.format( - ", ".join('"{}"'.format(m) for m in self.client.PARSE_MODES[:-1]), + ", ".join('"{}"'.format(m) for m in pyrogram.Client.PARSE_MODES[:-1]), mode )) diff --git a/pyrogram/client/types/bots_and_keyboards/callback_query.py b/pyrogram/client/types/bots_and_keyboards/callback_query.py index b09e5440..d58865b2 100644 --- a/pyrogram/client/types/bots_and_keyboards/callback_query.py +++ b/pyrogram/client/types/bots_and_keyboards/callback_query.py @@ -176,7 +176,7 @@ class CallbackQuery(Object, Update): def edit_message_text( self, text: str, - parse_mode: str = "", + parse_mode: Union[str, None] = object, disable_web_page_preview: bool = None, reply_markup: "pyrogram.InlineKeyboardMarkup" = None ) -> Union["pyrogram.Message", bool]: @@ -229,7 +229,7 @@ class CallbackQuery(Object, Update): def edit_message_caption( self, caption: str, - parse_mode: str = "", + parse_mode: Union[str, None] = object, reply_markup: "pyrogram.InlineKeyboardMarkup" = None ) -> Union["pyrogram.Message", bool]: """Edit the caption of media messages attached to callback queries. diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 144f04a4..2f1d5928 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -654,7 +654,7 @@ class Message(Object, Update): self, text: str, quote: bool = None, - parse_mode: str = "", + parse_mode: Union[str, None] = object, disable_web_page_preview: bool = None, disable_notification: bool = None, reply_to_message_id: int = None, @@ -736,7 +736,7 @@ class Message(Object, Update): animation: str, quote: bool = None, caption: str = "", - parse_mode: str = "", + parse_mode: Union[str, None] = object, duration: int = 0, width: int = 0, height: int = 0, @@ -873,7 +873,7 @@ class Message(Object, Update): audio: str, quote: bool = None, caption: str = "", - parse_mode: str = "", + parse_mode: Union[str, None] = object, duration: int = 0, performer: str = None, title: str = None, @@ -1010,7 +1010,7 @@ class Message(Object, Update): file_id: str, quote: bool = None, caption: str = "", - parse_mode: str = "", + parse_mode: Union[str, None] = object, disable_notification: bool = None, reply_to_message_id: int = None, reply_markup: Union[ @@ -1218,7 +1218,7 @@ class Message(Object, Update): quote: bool = None, thumb: str = None, caption: str = "", - parse_mode: str = "", + parse_mode: Union[str, None] = object, disable_notification: bool = None, reply_to_message_id: int = None, reply_markup: Union[ @@ -1613,7 +1613,7 @@ class Message(Object, Update): photo: str, quote: bool = None, caption: str = "", - parse_mode: str = "", + parse_mode: Union[str, None] = object, ttl_seconds: int = None, disable_notification: bool = None, reply_to_message_id: int = None, @@ -2007,7 +2007,7 @@ class Message(Object, Update): video: str, quote: bool = None, caption: str = "", - parse_mode: str = "", + parse_mode: Union[str, None] = object, duration: int = 0, width: int = 0, height: int = 0, @@ -2267,7 +2267,7 @@ class Message(Object, Update): voice: str, quote: bool = None, caption: str = "", - parse_mode: str = "", + parse_mode: Union[str, None] = object, duration: int = 0, disable_notification: bool = None, reply_to_message_id: int = None, @@ -2384,7 +2384,7 @@ class Message(Object, Update): def edit_text( self, text: str, - parse_mode: str = "", + parse_mode: Union[str, None] = object, disable_web_page_preview: bool = None, reply_markup: "pyrogram.InlineKeyboardMarkup" = None ) -> "Message": @@ -2442,7 +2442,7 @@ class Message(Object, Update): def edit_caption( self, caption: str, - parse_mode: str = "", + parse_mode: Union[str, None] = object, reply_markup: "pyrogram.InlineKeyboardMarkup" = None ) -> "Message": """Bound method *edit_caption* of :obj:`Message`.