diff --git a/aiogram/bot/api.py b/aiogram/bot/api.py index 92523534..f0065cc6 100644 --- a/aiogram/bot/api.py +++ b/aiogram/bot/api.py @@ -47,7 +47,8 @@ async def _check_result(method_name, response): """ if response.status != 200: body = await response.text() - raise TelegramAPIError(f"The server returned HTTP {response.status}. Response body:\n[{body}]", + raise TelegramAPIError("The server returned HTTP {0}. Response body:\n[{1}]".format( + response.status, body), method_name, response.status, body) result_json = await response.json(loads=json.loads) @@ -56,9 +57,9 @@ async def _check_result(method_name, response): body = await response.text() code = result_json.get('error_code') description = result_json.get('description') - raise TelegramAPIError(f"Error code: {code} Description {description}", + raise TelegramAPIError("Error code: {0} Description {1}".format(code, description), method_name, response.status, body) - log.debug(f"Response for '{method_name}': {result_json}") + log.debug("Response for '{0}': {1}".format(method_name, result_json)) return result_json.get('result') @@ -120,7 +121,8 @@ async def request(session, token, method, data=None, files=None) -> bool or dict :param files: files :return: bool or dict """ - log.debug(f"Make request: '{method}' with data: {data or {}} and files {files or {}}") + log.debug("Make request: '{0}' with data: {1} and files {2}".format( + method, data or {}, files or {})) data = _compose_data(data, files) url = Methods.api_url(token=token, method=method) async with session.post(url, data=data) as response: diff --git a/aiogram/dispatcher/__init__.py b/aiogram/dispatcher/__init__.py index 5254fb87..25cd6ec4 100644 --- a/aiogram/dispatcher/__init__.py +++ b/aiogram/dispatcher/__init__.py @@ -93,7 +93,7 @@ class Dispatcher: continue if updates: - log.info(f"Received {len(updates)} updates.") + log.info("Received {0} updates.".format(len(updates))) offset = updates[-1].update_id + 1 await self.process_updates(updates) diff --git a/aiogram/dispatcher/handler.py b/aiogram/dispatcher/handler.py index b7d7efe8..d0eb9b57 100644 --- a/aiogram/dispatcher/handler.py +++ b/aiogram/dispatcher/handler.py @@ -109,4 +109,4 @@ class NextStepHandler: def gen_identifier(chat_id, from_user_id): - return f"{chat_id}:{from_user_id}" + return "{0}:{1}".format(chat_id, from_user_id) diff --git a/aiogram/dispatcher/state.py b/aiogram/dispatcher/state.py index ea543fd8..127b79f3 100644 --- a/aiogram/dispatcher/state.py +++ b/aiogram/dispatcher/state.py @@ -501,7 +501,9 @@ class Controller: self.delete(key) def __str__(self): - return f"{self._chat}:{self._user} - {self._state}" + return "{0}:{1} - {2}".format( + self._chat, self._user, self._state + ) class AsyncController: @@ -611,7 +613,9 @@ class AsyncController: raise RuntimeError("Item assignment not allowed with async storage") def __str__(self): - return f"{self._chat}:{self._user} - {self._state}" + return "{0}:{1} - {2}".format( + self._chat, self._user, self._state + ) class StateMachine: @@ -650,7 +654,9 @@ class StateMachine: :param state: :return: """ - log.debug(f"Set state for {chat}:{user} to '{state}'") + log.debug("Set state for {0}:{1} to '{2}'".format( + chat, user, state + )) self.storage.set_state(chat, user, state) def get_state(self, chat, user): @@ -669,7 +675,7 @@ class StateMachine: :param user: :return: """ - log.debug(f"Reset state for {chat}:{user}") + log.debug("Reset state for {0}:{1}".format(chat, user)) self.storage.del_state(chat, user) async def process_message(self, message): @@ -686,11 +692,15 @@ class StateMachine: raise SkipHandler() if state not in self.steps: - log.warning(f"Found unknown state '{state}' for {chat_id}:{from_user_id}. Condition will be reset.") + log.warning("Found unknown state '{0}' for {1}:{2}. Condition will be reset.".format( + state, chat_id, from_user_id + )) self.del_state(chat_id, from_user_id) raise SkipHandler() - log.debug(f"Process state for {chat_id}:{from_user_id} - '{state}'") + log.debug("Process state for {0}:{1} - '{2}'".format( + chat_id, from_user_id, state + )) callback = self.steps[state] controller = Controller(self, chat_id, from_user_id, state) await callback(message, controller) @@ -731,7 +741,9 @@ class AsyncStateMachine: :param state: :return: """ - log.debug(f"Set state for {chat}:{user} to '{state}'") + log.debug("Set state for {0}:{1} to '{2}'".format( + chat, user, state + )) await self.storage.set_state(chat, user, state) async def get_state(self, chat, user): @@ -750,7 +762,7 @@ class AsyncStateMachine: :param user: :return: """ - log.debug(f"Reset state for {chat}:{user}") + log.debug("Reset state for {0}:{1}".format(chat, user)) await self.storage.del_state(chat, user) async def process_message(self, message): @@ -767,11 +779,15 @@ class AsyncStateMachine: raise SkipHandler() if state not in self.steps: - log.warning(f"Found unknown state '{state}' for {chat_id}:{from_user_id}. Condition will be reset.") + log.warning("Found unknown state '{0}' for {1}:{2}. Condition will be reset.".format( + state, chat_id, from_user_id + )) await self.del_state(chat_id, from_user_id) raise SkipHandler() - log.debug(f"Process state for {chat_id}:{from_user_id} - '{state}'") + log.debug("Process state for {0}:{1} - '{2}'".format( + chat_id, from_user_id, state + )) callback = self.steps[state] controller = AsyncController(self, chat_id, from_user_id, state) await callback(message, controller) diff --git a/aiogram/exceptions.py b/aiogram/exceptions.py index 08ec5f89..86358878 100644 --- a/aiogram/exceptions.py +++ b/aiogram/exceptions.py @@ -8,7 +8,7 @@ class ValidationError(Exception): class TelegramAPIError(Exception): def __init__(self, message, method, status, body): super(TelegramAPIError, self).__init__( - f"A request to the Telegram API was unsuccessful.\n{message}") + "A request to the Telegram API was unsuccessful.\n" + message) self.method = method self.status = status self.body = body diff --git a/aiogram/types/base.py b/aiogram/types/base.py index 829004b3..6664a03d 100644 --- a/aiogram/types/base.py +++ b/aiogram/types/base.py @@ -66,7 +66,7 @@ class Deserializable: Bot instance """ if not hasattr(self, '_bot'): - raise AttributeError(f"{self.__class__.__name__} is not configured.") + raise AttributeError("{0} is not configured.".format(self.__class__.__name__)) return getattr(self, '_bot') @bot.setter diff --git a/aiogram/utils/markdown.py b/aiogram/utils/markdown.py index f699f4ef..7c705a00 100644 --- a/aiogram/utils/markdown.py +++ b/aiogram/utils/markdown.py @@ -64,11 +64,11 @@ def hpre(*content, sep='\n'): def link(title, url): - return f"[{_escape(title)}]({url})" + return "[{0}]({1})".format(_escape(title), url) def hlink(title, url): - return f"{_escape(title)}" + return "{1}".format(url, _escape(title)) def escape_md(*content, sep=' '):