L idZddlZddlmZmZddlmZmZmZmZm Z ddl m Z ddl m Z ddlmZddlmZmZerdd lmZed ZGd d eeeefZy) z2This module contains the StringRegexHandler class.N)MatchPattern) TYPE_CHECKINGAnyOptionalTypeVarUnion) DEFAULT_TRUE)DVType) BaseHandler)CCTHandlerCallback) ApplicationRTc eZdZdZdZefdddeeeefde ee e fde e ffd Zd ed eeefd Zd e d ed ddeeed df dZxZS)StringRegexHandlera|Handler class to handle string updates based on a regex which checks the update content. Read the documentation of the :mod:`re` module for more information. The :func:`re.match` function is used to determine if an update should be handled by this handler. Note: This handler is not used to handle Telegram :class:`telegram.Update`, but strings manually put in the queue. For example to send messages with the bot using command line or API. Warning: When setting :paramref:`block` to :obj:`False`, you cannot rely on adding custom attributes to :class:`telegram.ext.CallbackContext`. See its docs for more info. Args: pattern (:obj:`str` | :func:`re.Pattern `): The regex pattern. callback (:term:`coroutine function`): The callback function for this handler. Will be called when :meth:`check_update` has determined that an update should be processed by this handler. Callback signature:: async def callback(update: str, context: CallbackContext) The return value of the callback is usually ignored except for the special case of :class:`telegram.ext.ConversationHandler`. block (:obj:`bool`, optional): Determines whether the return value of the callback should be awaited before processing the next handler in :meth:`telegram.ext.Application.process_update`. Defaults to :obj:`True`. .. seealso:: :wiki:`Concurrency` Attributes: pattern (:obj:`str` | :func:`re.Pattern `): The regex pattern. callback (:term:`coroutine function`): The callback function for this handler. block (:obj:`bool`): Determines whether the return value of the callback should be awaited before processing the next handler in :meth:`telegram.ext.Application.process_update`. )patternselfzStringRegexHandler[CCT, RT]rcallbackblockct|||t|trt j |}||_y)N)r)super__init__ isinstancestrrecompiler)rrrr __class__s o/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/ext/_handlers/stringregexhandler.pyrzStringRegexHandler.__init__Ms6 / gs #jj)G18 updatereturnclt|tr$tj|j|x}r|Sy)zDetermines whether an update should be passed to this handler's :attr:`callback`. Args: update (:obj:`object`): The incoming update. Returns: :obj:`None` | :obj:`re.match` N)rrrmatchr)rr!r$s r check_updatezStringRegexHandler.check_updateZs/ fc "$,,1O(O(OLr context applicationz)Application[Any, CCT, Any, Any, Any, Any] check_resultNc4|jr |r |g|_yyy)z}Add the result of ``re.match(pattern, update)`` to :attr:`CallbackContext.matches` as list with one element. N)rmatches)rr&r!r'r(s rcollect_additional_contextz-StringRegexHandler.collect_additional_contexths <r;sJ&9 ??5(::( T]O-S#r\2O-r