From 59bf35924b1515eac228c7d58a5ff6d8c077a7d4 Mon Sep 17 00:00:00 2001 From: JosXa Date: Mon, 11 Sep 2017 23:39:20 +0200 Subject: [PATCH 01/10] Added `utils.helpers.effective_message_type` which extracts the type of message as a string from an update or message. --- telegram/message.py | 17 +++++---- telegram/utils/helpers.py | 28 +++++++++++++++ tests/test_helpers.py | 21 +++++++++++- tests/test_message.py | 72 ++++++++++++++++++++++++++------------- 4 files changed, 107 insertions(+), 31 deletions(-) diff --git a/telegram/message.py b/telegram/message.py index 58098813885..89a270cb283 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -26,7 +26,6 @@ from telegram.utils.deprecate import warn_deprecate_obj from telegram.utils.helpers import escape_html, escape_markdown, to_timestamp, from_timestamp - _UNDEFINED = object() @@ -183,6 +182,14 @@ class Message(TelegramObject): _effective_attachment = _UNDEFINED + ATTACHMENT_TYPES = ['audio', 'game', 'document', 'photo', 'sticker', 'video', 'voice', + 'video_note', 'contact', 'location', 'venue', 'invoice', + 'successful_payment'] + MESSAGE_TYPES = ['text', 'new_chat_members', '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'] + ATTACHMENT_TYPES + def __init__(self, message_id, from_user, @@ -337,11 +344,9 @@ def effective_attachment(self): if self._effective_attachment is not _UNDEFINED: return self._effective_attachment - for i in (self.audio, self.game, self.document, self.photo, self.sticker, - self.video, self.voice, self.video_note, self.contact, self.location, - self.venue, self.invoice, self.successful_payment): - if i: - self._effective_attachment = i + for i in Message.ATTACHMENT_TYPES: + if getattr(self, i, None): + self._effective_attachment = getattr(self, i) break else: self._effective_attachment = None diff --git a/telegram/utils/helpers.py b/telegram/utils/helpers.py index 9da126e0531..4fad84e6caa 100644 --- a/telegram/utils/helpers.py +++ b/telegram/utils/helpers.py @@ -100,3 +100,31 @@ def mention_markdown(user_id, name): """ if isinstance(user_id, int): return '[{}](tg://user?id={})'.format(escape_markdown(name), user_id) + + +def effective_message_type(entity): + """ + Extracts the type of message as a string identifier from a :class:`telegram.Message` or an + :class:`telegram.Update`. + + Args: + entity (:obj:`Update` or :obj:`Message`) The ``update`` or ``message`` to extract from + + Returns: + str: One of ``Message.MESSAGE_TYPES`` + """ + + # TODO: Importing on file-level yields cyclic Import Errors + from telegram import Message + from telegram import Update + + if isinstance(entity, Message): + message = entity + elif isinstance(entity, Update): + message = entity.effective_message + else: + raise AttributeError("The argument `entity` must be either of type `Message` or `Update`.") + + for i in Message.MESSAGE_TYPES: + if getattr(message, i, None): + return i diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 49cd7751d7b..23e069642e7 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -16,7 +16,9 @@ # # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. - +from telegram import Sticker +from telegram import User +from telegram.message import Message from telegram.utils import helpers @@ -26,3 +28,20 @@ def test_escape_markdown(self): expected_str = '\*bold\*, \_italic\_, \`code\`, \[text\_link](http://github.com/)' assert expected_str == helpers.escape_markdown(test_str) + + def test_effective_message_type(self): + test_message = Message(message_id=1, + from_user=None, + date=None, + chat=None) + + test_message.text = 'Test' + assert helpers.effective_message_type(test_message) == 'text' + test_message.text = None + + test_message.sticker = Sticker('sticker_id', 50, 50) + assert helpers.effective_message_type(test_message) == 'sticker' + test_message.sticker = None + + test_message.new_chat_members = [User(55, 'new_user', False)] + assert helpers.effective_message_type(test_message) == 'new_chat_members' diff --git a/tests/test_message.py b/tests/test_message.py index 1dc2a8e4942..424be953fef 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -33,34 +33,52 @@ def message(bot): @pytest.fixture(scope='function', params=[ - {'forward_from': User(99, 'forward_user', False), - 'forward_date': datetime.now()}, - {'forward_from_chat': Chat(-23, 'channel'), - 'forward_from_message_id': 101, - 'forward_date': datetime.now()}, + { + 'forward_from': User(99, 'forward_user', False), + 'forward_date': datetime.now() + }, + { + 'forward_from_chat': Chat(-23, 'channel'), + 'forward_from_message_id': 101, + 'forward_date': datetime.now() + }, {'reply_to_message': Message(50, None, None, None)}, {'edit_date': datetime.now()}, - {'test': 'a text message', - 'enitites': [MessageEntity('bold', 10, 4), - MessageEntity('italic', 16, 7)]}, - {'audio': Audio('audio_id', 12), - 'caption': 'audio_file'}, - {'document': Document('document_id'), - 'caption': 'document_file'}, - {'game': Game('my_game', 'just my game', - [PhotoSize('game_photo_id', 30, 30), ])}, - {'photo': [PhotoSize('photo_id', 50, 50)], - 'caption': 'photo_file'}, + { + 'test': 'a text message', + 'enitites': [MessageEntity('bold', 10, 4), + MessageEntity('italic', 16, 7)] + }, + { + 'audio': Audio('audio_id', 12), + 'caption': 'audio_file' + }, + { + 'document': Document('document_id'), + 'caption': 'document_file' + }, + { + 'game': Game('my_game', 'just my game', + [PhotoSize('game_photo_id', 30, 30), ]) + }, + { + 'photo': [PhotoSize('photo_id', 50, 50)], + 'caption': 'photo_file' + }, {'sticker': Sticker('sticker_id', 50, 50)}, - {'video': Video('video_id', 12, 12, 12), - 'caption': 'video_file'}, + { + 'video': Video('video_id', 12, 12, 12), + 'caption': 'video_file' + }, {'voice': Voice('voice_id', 5)}, {'video_note': VideoNote('video_note_id', 20, 12)}, {'new_chat_members': [User(55, 'new_user', False)]}, {'contact': Contact('phone_numner', 'contact_name')}, {'location': Location(-23.691288, 46.788279)}, - {'venue': Venue(Location(-23.691288, 46.788279), - 'some place', 'right here')}, + { + 'venue': Venue(Location(-23.691288, 46.788279), + 'some place', 'right here') + }, {'left_chat_member': User(33, 'kicked', False)}, {'new_chat_title': 'new title'}, {'new_chat_photo': [PhotoSize('photo_id', 50, 50)]}, @@ -72,9 +90,11 @@ def message(bot): {'migrate_from_chat_id': -54321}, {'pinned_message': Message(7, None, None, None)}, {'invoice': Invoice('my invoice', 'invoice', 'start', 'EUR', 243)}, - {'successful_payment': SuccessfulPayment('EUR', 243, 'payload', - 'charge_id', 'provider_id', - order_info={})}, + { + 'successful_payment': SuccessfulPayment('EUR', 243, 'payload', + 'charge_id', 'provider_id', + order_info={}) + }, {'forward_signature': 'some_forward_sign'}, {'author_signature': 'some_author_sign'} ], @@ -188,6 +208,11 @@ def test_parse_entities_url_emoji(self): assert message.parse_entities() == {link_entity: text} assert next(iter(message.parse_entities())).url == url + def test_type(self, message, message_params): + message.photo = [PhotoSize('photo_id', 50, 50)] + message.photo.caption = 'Test' + assert message.type == 'photo' + def test_chat_id(self, message): assert message.chat_id == message.chat.id @@ -201,7 +226,6 @@ def test_effective_attachment(self, message_params): item = None assert message_params.effective_attachment == item - def test_reply_text(self, monkeypatch, message): def test(*args, **kwargs): id = args[1] == message.chat_id From cd9b061d74d99f7b9a8f66d1b4de4b8c41e408dc Mon Sep 17 00:00:00 2001 From: JosXa Date: Mon, 11 Sep 2017 23:51:14 +0200 Subject: [PATCH 02/10] Accidentally left a test method --- tests/test_message.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/test_message.py b/tests/test_message.py index 424be953fef..0402b81227d 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -208,11 +208,6 @@ def test_parse_entities_url_emoji(self): assert message.parse_entities() == {link_entity: text} assert next(iter(message.parse_entities())).url == url - def test_type(self, message, message_params): - message.photo = [PhotoSize('photo_id', 50, 50)] - message.photo.caption = 'Test' - assert message.type == 'photo' - def test_chat_id(self, message): assert message.chat_id == message.chat.id From 753684ed3a336e91324b3f62e0a3f7cb1d521e58 Mon Sep 17 00:00:00 2001 From: JosXa Date: Mon, 11 Sep 2017 23:39:20 +0200 Subject: [PATCH 03/10] Added `utils.helpers.effective_message_type` which extracts the type of message as a string from an update or message. --- telegram/message.py | 17 +++++---- telegram/utils/helpers.py | 28 +++++++++++++++ tests/test_helpers.py | 21 +++++++++++- tests/test_message.py | 72 ++++++++++++++++++++++++++------------- 4 files changed, 107 insertions(+), 31 deletions(-) diff --git a/telegram/message.py b/telegram/message.py index 58098813885..89a270cb283 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -26,7 +26,6 @@ from telegram.utils.deprecate import warn_deprecate_obj from telegram.utils.helpers import escape_html, escape_markdown, to_timestamp, from_timestamp - _UNDEFINED = object() @@ -183,6 +182,14 @@ class Message(TelegramObject): _effective_attachment = _UNDEFINED + ATTACHMENT_TYPES = ['audio', 'game', 'document', 'photo', 'sticker', 'video', 'voice', + 'video_note', 'contact', 'location', 'venue', 'invoice', + 'successful_payment'] + MESSAGE_TYPES = ['text', 'new_chat_members', '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'] + ATTACHMENT_TYPES + def __init__(self, message_id, from_user, @@ -337,11 +344,9 @@ def effective_attachment(self): if self._effective_attachment is not _UNDEFINED: return self._effective_attachment - for i in (self.audio, self.game, self.document, self.photo, self.sticker, - self.video, self.voice, self.video_note, self.contact, self.location, - self.venue, self.invoice, self.successful_payment): - if i: - self._effective_attachment = i + for i in Message.ATTACHMENT_TYPES: + if getattr(self, i, None): + self._effective_attachment = getattr(self, i) break else: self._effective_attachment = None diff --git a/telegram/utils/helpers.py b/telegram/utils/helpers.py index 9da126e0531..4fad84e6caa 100644 --- a/telegram/utils/helpers.py +++ b/telegram/utils/helpers.py @@ -100,3 +100,31 @@ def mention_markdown(user_id, name): """ if isinstance(user_id, int): return '[{}](tg://user?id={})'.format(escape_markdown(name), user_id) + + +def effective_message_type(entity): + """ + Extracts the type of message as a string identifier from a :class:`telegram.Message` or an + :class:`telegram.Update`. + + Args: + entity (:obj:`Update` or :obj:`Message`) The ``update`` or ``message`` to extract from + + Returns: + str: One of ``Message.MESSAGE_TYPES`` + """ + + # TODO: Importing on file-level yields cyclic Import Errors + from telegram import Message + from telegram import Update + + if isinstance(entity, Message): + message = entity + elif isinstance(entity, Update): + message = entity.effective_message + else: + raise AttributeError("The argument `entity` must be either of type `Message` or `Update`.") + + for i in Message.MESSAGE_TYPES: + if getattr(message, i, None): + return i diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 49cd7751d7b..23e069642e7 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -16,7 +16,9 @@ # # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. - +from telegram import Sticker +from telegram import User +from telegram.message import Message from telegram.utils import helpers @@ -26,3 +28,20 @@ def test_escape_markdown(self): expected_str = '\*bold\*, \_italic\_, \`code\`, \[text\_link](http://github.com/)' assert expected_str == helpers.escape_markdown(test_str) + + def test_effective_message_type(self): + test_message = Message(message_id=1, + from_user=None, + date=None, + chat=None) + + test_message.text = 'Test' + assert helpers.effective_message_type(test_message) == 'text' + test_message.text = None + + test_message.sticker = Sticker('sticker_id', 50, 50) + assert helpers.effective_message_type(test_message) == 'sticker' + test_message.sticker = None + + test_message.new_chat_members = [User(55, 'new_user', False)] + assert helpers.effective_message_type(test_message) == 'new_chat_members' diff --git a/tests/test_message.py b/tests/test_message.py index 1dc2a8e4942..424be953fef 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -33,34 +33,52 @@ def message(bot): @pytest.fixture(scope='function', params=[ - {'forward_from': User(99, 'forward_user', False), - 'forward_date': datetime.now()}, - {'forward_from_chat': Chat(-23, 'channel'), - 'forward_from_message_id': 101, - 'forward_date': datetime.now()}, + { + 'forward_from': User(99, 'forward_user', False), + 'forward_date': datetime.now() + }, + { + 'forward_from_chat': Chat(-23, 'channel'), + 'forward_from_message_id': 101, + 'forward_date': datetime.now() + }, {'reply_to_message': Message(50, None, None, None)}, {'edit_date': datetime.now()}, - {'test': 'a text message', - 'enitites': [MessageEntity('bold', 10, 4), - MessageEntity('italic', 16, 7)]}, - {'audio': Audio('audio_id', 12), - 'caption': 'audio_file'}, - {'document': Document('document_id'), - 'caption': 'document_file'}, - {'game': Game('my_game', 'just my game', - [PhotoSize('game_photo_id', 30, 30), ])}, - {'photo': [PhotoSize('photo_id', 50, 50)], - 'caption': 'photo_file'}, + { + 'test': 'a text message', + 'enitites': [MessageEntity('bold', 10, 4), + MessageEntity('italic', 16, 7)] + }, + { + 'audio': Audio('audio_id', 12), + 'caption': 'audio_file' + }, + { + 'document': Document('document_id'), + 'caption': 'document_file' + }, + { + 'game': Game('my_game', 'just my game', + [PhotoSize('game_photo_id', 30, 30), ]) + }, + { + 'photo': [PhotoSize('photo_id', 50, 50)], + 'caption': 'photo_file' + }, {'sticker': Sticker('sticker_id', 50, 50)}, - {'video': Video('video_id', 12, 12, 12), - 'caption': 'video_file'}, + { + 'video': Video('video_id', 12, 12, 12), + 'caption': 'video_file' + }, {'voice': Voice('voice_id', 5)}, {'video_note': VideoNote('video_note_id', 20, 12)}, {'new_chat_members': [User(55, 'new_user', False)]}, {'contact': Contact('phone_numner', 'contact_name')}, {'location': Location(-23.691288, 46.788279)}, - {'venue': Venue(Location(-23.691288, 46.788279), - 'some place', 'right here')}, + { + 'venue': Venue(Location(-23.691288, 46.788279), + 'some place', 'right here') + }, {'left_chat_member': User(33, 'kicked', False)}, {'new_chat_title': 'new title'}, {'new_chat_photo': [PhotoSize('photo_id', 50, 50)]}, @@ -72,9 +90,11 @@ def message(bot): {'migrate_from_chat_id': -54321}, {'pinned_message': Message(7, None, None, None)}, {'invoice': Invoice('my invoice', 'invoice', 'start', 'EUR', 243)}, - {'successful_payment': SuccessfulPayment('EUR', 243, 'payload', - 'charge_id', 'provider_id', - order_info={})}, + { + 'successful_payment': SuccessfulPayment('EUR', 243, 'payload', + 'charge_id', 'provider_id', + order_info={}) + }, {'forward_signature': 'some_forward_sign'}, {'author_signature': 'some_author_sign'} ], @@ -188,6 +208,11 @@ def test_parse_entities_url_emoji(self): assert message.parse_entities() == {link_entity: text} assert next(iter(message.parse_entities())).url == url + def test_type(self, message, message_params): + message.photo = [PhotoSize('photo_id', 50, 50)] + message.photo.caption = 'Test' + assert message.type == 'photo' + def test_chat_id(self, message): assert message.chat_id == message.chat.id @@ -201,7 +226,6 @@ def test_effective_attachment(self, message_params): item = None assert message_params.effective_attachment == item - def test_reply_text(self, monkeypatch, message): def test(*args, **kwargs): id = args[1] == message.chat_id From c0d0b824f46d5e1043366f21f6bd0e057b14f025 Mon Sep 17 00:00:00 2001 From: JosXa Date: Mon, 11 Sep 2017 23:51:14 +0200 Subject: [PATCH 04/10] Accidentally left a test method --- tests/test_message.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/test_message.py b/tests/test_message.py index 424be953fef..0402b81227d 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -208,11 +208,6 @@ def test_parse_entities_url_emoji(self): assert message.parse_entities() == {link_entity: text} assert next(iter(message.parse_entities())).url == url - def test_type(self, message, message_params): - message.photo = [PhotoSize('photo_id', 50, 50)] - message.photo.caption = 'Test' - assert message.type == 'photo' - def test_chat_id(self, message): assert message.chat_id == message.chat.id From 20151e870dae336468a456212d4ec57f90ad1e79 Mon Sep 17 00:00:00 2001 From: JosXa Date: Mon, 2 Oct 2017 03:20:54 +0200 Subject: [PATCH 05/10] Reverted test_message --- tests/test_message.py | 67 ++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 43 deletions(-) diff --git a/tests/test_message.py b/tests/test_message.py index 0402b81227d..1dc2a8e4942 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -33,52 +33,34 @@ def message(bot): @pytest.fixture(scope='function', params=[ - { - 'forward_from': User(99, 'forward_user', False), - 'forward_date': datetime.now() - }, - { - 'forward_from_chat': Chat(-23, 'channel'), - 'forward_from_message_id': 101, - 'forward_date': datetime.now() - }, + {'forward_from': User(99, 'forward_user', False), + 'forward_date': datetime.now()}, + {'forward_from_chat': Chat(-23, 'channel'), + 'forward_from_message_id': 101, + 'forward_date': datetime.now()}, {'reply_to_message': Message(50, None, None, None)}, {'edit_date': datetime.now()}, - { - 'test': 'a text message', - 'enitites': [MessageEntity('bold', 10, 4), - MessageEntity('italic', 16, 7)] - }, - { - 'audio': Audio('audio_id', 12), - 'caption': 'audio_file' - }, - { - 'document': Document('document_id'), - 'caption': 'document_file' - }, - { - 'game': Game('my_game', 'just my game', - [PhotoSize('game_photo_id', 30, 30), ]) - }, - { - 'photo': [PhotoSize('photo_id', 50, 50)], - 'caption': 'photo_file' - }, + {'test': 'a text message', + 'enitites': [MessageEntity('bold', 10, 4), + MessageEntity('italic', 16, 7)]}, + {'audio': Audio('audio_id', 12), + 'caption': 'audio_file'}, + {'document': Document('document_id'), + 'caption': 'document_file'}, + {'game': Game('my_game', 'just my game', + [PhotoSize('game_photo_id', 30, 30), ])}, + {'photo': [PhotoSize('photo_id', 50, 50)], + 'caption': 'photo_file'}, {'sticker': Sticker('sticker_id', 50, 50)}, - { - 'video': Video('video_id', 12, 12, 12), - 'caption': 'video_file' - }, + {'video': Video('video_id', 12, 12, 12), + 'caption': 'video_file'}, {'voice': Voice('voice_id', 5)}, {'video_note': VideoNote('video_note_id', 20, 12)}, {'new_chat_members': [User(55, 'new_user', False)]}, {'contact': Contact('phone_numner', 'contact_name')}, {'location': Location(-23.691288, 46.788279)}, - { - 'venue': Venue(Location(-23.691288, 46.788279), - 'some place', 'right here') - }, + {'venue': Venue(Location(-23.691288, 46.788279), + 'some place', 'right here')}, {'left_chat_member': User(33, 'kicked', False)}, {'new_chat_title': 'new title'}, {'new_chat_photo': [PhotoSize('photo_id', 50, 50)]}, @@ -90,11 +72,9 @@ def message(bot): {'migrate_from_chat_id': -54321}, {'pinned_message': Message(7, None, None, None)}, {'invoice': Invoice('my invoice', 'invoice', 'start', 'EUR', 243)}, - { - 'successful_payment': SuccessfulPayment('EUR', 243, 'payload', - 'charge_id', 'provider_id', - order_info={}) - }, + {'successful_payment': SuccessfulPayment('EUR', 243, 'payload', + 'charge_id', 'provider_id', + order_info={})}, {'forward_signature': 'some_forward_sign'}, {'author_signature': 'some_author_sign'} ], @@ -221,6 +201,7 @@ def test_effective_attachment(self, message_params): item = None assert message_params.effective_attachment == item + def test_reply_text(self, monkeypatch, message): def test(*args, **kwargs): id = args[1] == message.chat_id From 03e65679af71784ace3ea5b0f09d3b8c79794a54 Mon Sep 17 00:00:00 2001 From: JosXa Date: Mon, 2 Oct 2017 03:28:26 +0200 Subject: [PATCH 06/10] Concluded test and added fallback return value --- telegram/utils/helpers.py | 2 ++ telegram/vendor/ptb_urllib3 | 2 +- tests/test_helpers.py | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/telegram/utils/helpers.py b/telegram/utils/helpers.py index 4fad84e6caa..0ad4b464881 100644 --- a/telegram/utils/helpers.py +++ b/telegram/utils/helpers.py @@ -128,3 +128,5 @@ def effective_message_type(entity): for i in Message.MESSAGE_TYPES: if getattr(message, i, None): return i + + return None diff --git a/telegram/vendor/ptb_urllib3 b/telegram/vendor/ptb_urllib3 index 06d04e451f6..4c1693fb817 160000 --- a/telegram/vendor/ptb_urllib3 +++ b/telegram/vendor/ptb_urllib3 @@ -1 +1 @@ -Subproject commit 06d04e451f6beb5562057bf793218c4e363d8bc0 +Subproject commit 4c1693fb817aa511622298b3ce4873c57648f402 diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 23e069642e7..0632bc8b339 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -16,6 +16,8 @@ # # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. +from telegram import Update + from telegram import Sticker from telegram import User from telegram.message import Message @@ -45,3 +47,11 @@ def test_effective_message_type(self): test_message.new_chat_members = [User(55, 'new_user', False)] assert helpers.effective_message_type(test_message) == 'new_chat_members' + + test_update = Update(1) + test_message.text = 'Test' + test_update.message = test_message + assert helpers.effective_message_type(test_update) == 'text' + + empty_update = Update(2) + assert helpers.effective_message_type(empty_update) is None From 43ff0712ba2e0e0799b9ed423ed6725f9f649e21 Mon Sep 17 00:00:00 2001 From: JosXa Date: Sat, 7 Oct 2017 02:42:26 +0200 Subject: [PATCH 07/10] Removed urllib3 --- telegram/vendor/ptb_urllib3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram/vendor/ptb_urllib3 b/telegram/vendor/ptb_urllib3 index 4c1693fb817..06d04e451f6 160000 --- a/telegram/vendor/ptb_urllib3 +++ b/telegram/vendor/ptb_urllib3 @@ -1 +1 @@ -Subproject commit 4c1693fb817aa511622298b3ce4873c57648f402 +Subproject commit 06d04e451f6beb5562057bf793218c4e363d8bc0 From 8cd1eaf740422e4d04fa0414d0439f44c6bd0d1c Mon Sep 17 00:00:00 2001 From: JosXa Date: Thu, 1 Feb 2018 17:27:30 +0100 Subject: [PATCH 08/10] Merge remote-tracking branch 'remotes/origin/master' into extract-urls # Conflicts: # telegram/utils/helpers.py --- telegram/utils/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegram/utils/helpers.py b/telegram/utils/helpers.py index 21bae538704..846dc6d6404 100644 --- a/telegram/utils/helpers.py +++ b/telegram/utils/helpers.py @@ -121,13 +121,13 @@ def effective_message_type(entity): :class:`telegram.Update`. Args: - entity (:obj:`Update` or :obj:`Message`) The ``update`` or ``message`` to extract from + entity (:obj:`Update` | :obj:`Message`) The ``update`` or ``message`` to extract from Returns: str: One of ``Message.MESSAGE_TYPES`` """ - # TODO: Importing on file-level yields cyclic Import Errors + # Importing on file-level yields cyclic Import Errors from telegram import Message from telegram import Update From bfcee92375f1c27e08c93e09f2c4cd6b9e387c95 Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Sat, 10 Feb 2018 18:00:15 +0200 Subject: [PATCH 09/10] fix typo --- telegram/utils/helpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/telegram/utils/helpers.py b/telegram/utils/helpers.py index 846dc6d6404..0d33c2ced1b 100644 --- a/telegram/utils/helpers.py +++ b/telegram/utils/helpers.py @@ -117,7 +117,7 @@ def mention_markdown(user_id, name): def effective_message_type(entity): """ - Extracts the type of message as a string identifier from a :class:`telegram.Message` or an + Extracts the type of message as a string identifier from a :class:`telegram.Message` or a :class:`telegram.Update`. Args: @@ -125,6 +125,7 @@ def effective_message_type(entity): Returns: str: One of ``Message.MESSAGE_TYPES`` + """ # Importing on file-level yields cyclic Import Errors From e96e973f6418c6cdc383c3a8a88347fb3d47e11f Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Sat, 10 Feb 2018 18:13:32 +0200 Subject: [PATCH 10/10] raise TypeError instead of AttributeError --- telegram/utils/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram/utils/helpers.py b/telegram/utils/helpers.py index 0d33c2ced1b..3dcf5ce04af 100644 --- a/telegram/utils/helpers.py +++ b/telegram/utils/helpers.py @@ -137,7 +137,7 @@ def effective_message_type(entity): elif isinstance(entity, Update): message = entity.effective_message else: - raise AttributeError("The argument `entity` must be either of type `Message` or `Update`.") + raise TypeError("entity is not Message or Update (got: {})".format(type(entity))) for i in Message.MESSAGE_TYPES: if getattr(message, i, None):