From e5ec44def279108ff1c91b175e6da96f1b7ee558 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Wed, 29 Nov 2017 13:51:48 +0200 Subject: [PATCH 1/5] Change version. --- aiogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiogram/__init__.py b/aiogram/__init__.py index ac6b1c96..f7ec1957 100644 --- a/aiogram/__init__.py +++ b/aiogram/__init__.py @@ -10,7 +10,7 @@ except ImportError as e: from .utils.versions import Stage, Version -VERSION = Version(1, 0, 2, stage=Stage.DEV, build=0) +VERSION = Version(1, 0, 2, stage=Stage.FINAL, build=0) API_VERSION = Version(3, 5) __version__ = VERSION.version From 3e0d7e1ef5355a4761074dc5db7fb230653d6625 Mon Sep 17 00:00:00 2001 From: Arslan 'Ars2014' Sakhapov Date: Tue, 9 Jan 2018 23:10:22 +0500 Subject: [PATCH 2/5] Fix error replacing 'to_json' by 'to_python' --- aiogram/types/inline_keyboard.py | 2 +- aiogram/types/reply_keyboard.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/aiogram/types/inline_keyboard.py b/aiogram/types/inline_keyboard.py index 636f101c..76c47e98 100644 --- a/aiogram/types/inline_keyboard.py +++ b/aiogram/types/inline_keyboard.py @@ -54,7 +54,7 @@ class InlineKeyboardMarkup(base.TelegramObject): """ btn_array = [] for button in args: - btn_array.append(button.to_json()) + btn_array.append(button.to_python()) self.inline_keyboard.append(btn_array) return self diff --git a/aiogram/types/reply_keyboard.py b/aiogram/types/reply_keyboard.py index c16bc496..27a595c2 100644 --- a/aiogram/types/reply_keyboard.py +++ b/aiogram/types/reply_keyboard.py @@ -41,7 +41,7 @@ class ReplyKeyboardMarkup(base.TelegramObject): elif isinstance(button, bytes): row.append({'text': button.decode('utf-8')}) else: - row.append(button.to_json()) + row.append(button.to_python()) if i % self.row_width == 0: self.keyboard.append(row) row = [] @@ -55,7 +55,7 @@ class ReplyKeyboardMarkup(base.TelegramObject): if isinstance(button, str): btn_array.append({'text': button}) else: - btn_array.append(button.to_json()) + btn_array.append(button.to_python()) self.keyboard.append(btn_array) return self From 2656cab2f1876d8ab6a6a4c0f9c374aedfa47cb2 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Wed, 10 Jan 2018 19:38:41 +0200 Subject: [PATCH 3/5] TelegramObject is iterable. --- aiogram/types/base.py | 47 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/aiogram/types/base.py b/aiogram/types/base.py index e291afe5..2770fd84 100644 --- a/aiogram/types/base.py +++ b/aiogram/types/base.py @@ -4,7 +4,6 @@ from typing import TypeVar from .fields import BaseField from ..utils import json -from ..utils.context import get_value PROPS_ATTR_NAME = '_props' VALUES_ATTR_NAME = '_values' @@ -187,15 +186,61 @@ class TelegramObject(metaclass=MetaTelegramObject): return self.as_json() def __getitem__(self, item): + """ + Item getter (by key) + + :param item: + :return: + """ if item in self.props: return self.props[item].get_value(self) raise KeyError(item) def __setitem__(self, key, value): + """ + Item setter (by key) + + :param key: + :param value: + :return: + """ if key in self.props: return self.props[key].set_value(self, value, self.conf.get('parent', None)) raise KeyError(key) def __contains__(self, item): + """ + Check key contains in that object + + :param item: + :return: + """ self.clean() return item in self.values + + def __iter__(self): + """ + Iterate over items + + :return: + """ + for item in self.to_python().items(): + yield item + + def iter_keys(self): + """ + Iterate over keys + + :return: + """ + for key, _ in self: + yield key + + def iter_values(self): + """ + Iterate over values + + :return: + """ + for _, value in self: + yield value From 0144d54e811ffcfe4ef079bad7cbc60a7ec86a40 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Wed, 10 Jan 2018 20:41:19 +0200 Subject: [PATCH 4/5] Change version --- aiogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiogram/__init__.py b/aiogram/__init__.py index e7a1292d..6af7fd8c 100644 --- a/aiogram/__init__.py +++ b/aiogram/__init__.py @@ -19,7 +19,7 @@ else: asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) -VERSION = Version(1, 0, 3, stage=Stage.FINAL, build=0) +VERSION = Version(1, 0, 4, stage=Stage.FINAL, build=0) API_VERSION = Version(3, 5) __version__ = VERSION.version From 9b383a8c34be77f9e53c07f411ceceb0cd270bfa Mon Sep 17 00:00:00 2001 From: Sergey Baboshin Date: Sat, 13 Jan 2018 18:42:21 +0300 Subject: [PATCH 5/5] Fixed code example --- docs/source/quick_start.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/source/quick_start.rst b/docs/source/quick_start.rst index a9ff0890..c5ff7e9c 100644 --- a/docs/source/quick_start.rst +++ b/docs/source/quick_start.rst @@ -48,5 +48,9 @@ Summary bot = Bot(token='BOT TOKEN HERE') dp = Dispatcher(bot) + @dp.message_handler(commands=['start', 'help']) + async def send_welcome(message: types.Message): + await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.") + if __name__ == '__main__': executor.start_polling(dp)