Merge branch 'dev-2.x' of github.com:aiogram/aiogram into chat_type_builtin_filter

This commit is contained in:
Egor 2020-06-29 00:17:45 +05:00
commit 9d7a2b811e
6 changed files with 825 additions and 533 deletions

View file

@ -43,5 +43,5 @@ __all__ = [
'utils'
]
__version__ = '2.9.1'
__version__ = '2.9.2'
__api_version__ = '4.9'

View file

@ -216,39 +216,50 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
try:
if update.message:
types.Message.set_current(update.message)
types.User.set_current(update.message.from_user)
types.Chat.set_current(update.message.chat)
return await self.message_handlers.notify(update.message)
if update.edited_message:
types.Message.set_current(update.edited_message)
types.User.set_current(update.edited_message.from_user)
types.Chat.set_current(update.edited_message.chat)
return await self.edited_message_handlers.notify(update.edited_message)
if update.channel_post:
types.Message.set_current(update.channel_post)
types.Chat.set_current(update.channel_post.chat)
return await self.channel_post_handlers.notify(update.channel_post)
if update.edited_channel_post:
types.Message.set_current(update.edited_channel_post)
types.Chat.set_current(update.edited_channel_post.chat)
return await self.edited_channel_post_handlers.notify(update.edited_channel_post)
if update.inline_query:
types.InlineQuery.set_current(update.inline_query)
types.User.set_current(update.inline_query.from_user)
return await self.inline_query_handlers.notify(update.inline_query)
if update.chosen_inline_result:
types.ChosenInlineResult.set_current(update.chosen_inline_result)
types.User.set_current(update.chosen_inline_result.from_user)
return await self.chosen_inline_result_handlers.notify(update.chosen_inline_result)
if update.callback_query:
types.CallbackQuery.set_current(update.callback_query)
if update.callback_query.message:
types.Chat.set_current(update.callback_query.message.chat)
types.User.set_current(update.callback_query.from_user)
return await self.callback_query_handlers.notify(update.callback_query)
if update.shipping_query:
types.ShippingQuery.set_current(update.shipping_query)
types.User.set_current(update.shipping_query.from_user)
return await self.shipping_query_handlers.notify(update.shipping_query)
if update.pre_checkout_query:
types.PreCheckoutQuery.set_current(update.pre_checkout_query)
types.User.set_current(update.pre_checkout_query.from_user)
return await self.pre_checkout_query_handlers.notify(update.pre_checkout_query)
if update.poll:
types.Poll.set_current(update.poll)
return await self.poll_handlers.notify(update.poll)
if update.poll_answer:
types.PollAnswer.set_current(update.poll_answer)
types.User.set_current(update.poll_answer.user)
return await self.poll_answer_handlers.notify(update.poll_answer)
except Exception as e:

View file

@ -1,5 +1,6 @@
import abc
import datetime
import weakref
__all__ = ('BaseField', 'Field', 'ListField', 'DateTimeField', 'TextField', 'ListOfLists')
@ -109,7 +110,9 @@ class Field(BaseField):
and self.base_object is not None \
and not hasattr(value, 'base_object') \
and not hasattr(value, 'to_python'):
return self.base_object(conf={'parent': parent}, **value)
if not isinstance(parent, weakref.ReferenceType):
parent = weakref.ref(parent)
return self.base_object(conf={'parent':parent}, **value)
return value

File diff suppressed because it is too large Load diff

View file

@ -163,7 +163,7 @@ class HtmlDecoration(TextDecoration):
class MarkdownDecoration(TextDecoration):
MARKDOWN_QUOTE_PATTERN: Pattern[str] = re.compile(r"([_*\[\]()~`>#+\-|{}.!])")
MARKDOWN_QUOTE_PATTERN: Pattern[str] = re.compile(r"([_*\[\]()~`>#+\-=|{}.!\\])")
def link(self, value: str, link: str) -> str:
return f"[{value}]({link})"

View file

@ -0,0 +1,11 @@
import pytest
from aiogram.utils import markdown
class TestMarkdownEscape:
def test_equality_sign_is_escaped(self):
assert markdown.escape_md(r"e = mc2") == r"e \= mc2"
def test_pre_escaped(self):
assert markdown.escape_md(r"hello\.") == r"hello\\\."