From 932ac9477b5d3b3f950f085a251daf6e1288cc6f Mon Sep 17 00:00:00 2001 From: bedilbek Date: Sat, 11 Apr 2020 13:02:50 +0500 Subject: [PATCH] Add ENABLE_MIDDLEWARE=False in apihelpers to keep backward compatibility --- telebot/__init__.py | 3 ++- telebot/apihelper.py | 2 ++ tests/test_telebot.py | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index a143479..de928dd 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -309,7 +309,8 @@ class TeleBot: for update in updates: - self.process_middlewares(update) + if apihelper.ENABLE_MIDDLEWARE: + self.process_middlewares(update) if update.update_id > self.last_update_id: self.last_update_id = update.update_id diff --git a/telebot/apihelper.py b/telebot/apihelper.py index cbcc08c..4c4c680 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -26,6 +26,8 @@ FILE_URL = None CONNECT_TIMEOUT = 3.5 READ_TIMEOUT = 9999 +ENABLE_MIDDLEWARE = False + def _get_req_session(reset=False): return util.per_thread('req_session', lambda: requests.session(), reset) diff --git a/tests/test_telebot.py b/tests/test_telebot.py index 3157bdd..b3fbfcf 100644 --- a/tests/test_telebot.py +++ b/tests/test_telebot.py @@ -508,6 +508,10 @@ class TestTeleBot: assert ret_msg.caption_entities[0].type == 'italic' def test_typed_middleware_handler(self): + from telebot import apihelper + + apihelper.ENABLE_MIDDLEWARE = True + tb = telebot.TeleBot('') update = self.create_message_update('/help') @@ -524,6 +528,10 @@ class TestTeleBot: assert update.message.text == 'got' * 2 def test_default_middleware_handler(self): + from telebot import apihelper + + apihelper.ENABLE_MIDDLEWARE = True + tb = telebot.TeleBot('') update = self.create_message_update('/help')