L i^$dZddlZddlZddlmZmZddlmZmZmZm Z m Z m Z m Z ddl mZddlmZddlmZddlmZdd lmZmZerdd lmZe d ZGd d eeeefZy)z4This module contains the CallbackQueryHandler class.N)MatchPattern) TYPE_CHECKINGAnyCallableOptionalTypeVarUnioncast)Update) DEFAULT_TRUE)DVType) BaseHandler)CCTHandlerCallback) ApplicationRTceZdZdZdZddefdddeeee fde e e e e eeege effde e e e e fd eef fd Zd ed e e eeffd Zded eddde eee fd df dZxZS)CallbackQueryHandleraHandler class to handle Telegram :attr:`callback queries `. Optionally based on a regex. Read the documentation of the :mod:`re` module for more information. Note: * If your bot allows arbitrary objects as :paramref:`~telegram.InlineKeyboardButton.callback_data`, it may happen that the original :attr:`~telegram.InlineKeyboardButton.callback_data` for the incoming :class:`telegram.CallbackQuery` can not be found. This is the case when either a malicious client tempered with the :attr:`telegram.CallbackQuery.data` or the data was simply dropped from cache or not persisted. In these cases, an instance of :class:`telegram.ext.InvalidCallbackData` will be set as :attr:`telegram.CallbackQuery.data`. .. versionadded:: 13.6 * If neither :paramref:`pattern` nor :paramref:`game_pattern` is set, `any` ``CallbackQuery`` will be handled. If only :paramref:`pattern` is set, queries with :attr:`~telegram.CallbackQuery.game_short_name` will `not` be considered and vice versa. If both patterns are set, queries with either :attr: `~telegram.CallbackQuery.game_short_name` or :attr:`~telegram.CallbackQuery.data` matching the defined pattern will be handled .. versionadded:: 21.5 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: 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: Update, context: CallbackContext) The return value of the callback is usually ignored except for the special case of :class:`telegram.ext.ConversationHandler`. pattern (:obj:`str` | :func:`re.Pattern ` | :obj:`callable` | :obj:`type`, optional): Pattern to test :attr:`telegram.CallbackQuery.data` against. If a string or a regex pattern is passed, :func:`re.match` is used on :attr:`telegram.CallbackQuery.data` to determine if an update should be handled by this handler. If your bot allows arbitrary objects as :paramref:`~telegram.InlineKeyboardButton.callback_data`, non-strings will be accepted. To filter arbitrary objects you may pass: - a callable, accepting exactly one argument, namely the :attr:`telegram.CallbackQuery.data`. It must return :obj:`True` or :obj:`False`/:obj:`None` to indicate, whether the update should be handled. - a :obj:`type`. If :attr:`telegram.CallbackQuery.data` is an instance of that type (or a subclass), the update will be handled. If :attr:`telegram.CallbackQuery.data` is :obj:`None`, the :class:`telegram.CallbackQuery` update will not be handled. .. seealso:: :wiki:`Arbitrary callback_data ` .. versionchanged:: 13.6 Added support for arbitrary callback data. game_pattern (:obj:`str` | :func:`re.Pattern ` | optional) Pattern to test :attr:`telegram.CallbackQuery.game_short_name` against. If a string or a regex pattern is passed, :func:`re.match` is used on :attr:`telegram.CallbackQuery.game_short_name` to determine if an update should be handled by this handler. .. versionadded:: 21.5 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: callback (:term:`coroutine function`): The callback function for this handler. pattern (:func:`re.Pattern ` | :obj:`callable` | :obj:`type`): Optional. Regex pattern, callback or type to test :attr:`telegram.CallbackQuery.data` against. .. versionchanged:: 13.6 Added support for arbitrary callback data. game_pattern (:func:`re.Pattern `): Optional. Regex pattern to test :attr:`telegram.CallbackQuery.game_short_name` 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`. ) game_patternpatternNselfzCallbackQueryHandler[CCT, RT]callbackrrblockc.t|||t|r tj|r t dt |trtj|}t |trtj|}||_ ||_ y)N)rzQThe `pattern` must not be a coroutine function! Use an ordinary function instead.) super__init__callableasyncioiscoroutinefunction TypeError isinstancestrrecompilerr)rrrrr __class__s q/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/ext/_handlers/callbackqueryhandler.pyrzCallbackQueryHandler.__init__s / G !> %||M22mS1}==u= $$!2!2ODDuD r(context applicationz)Application[Any, CCT, Any, Any, Any, Any] check_resultcF|jrtd|}|g|_yy)zAdd the result of ``re.match(pattern, update.callback_query.data)`` to :attr:`CallbackContext.matches` as list with one element. rN)rr matches)rr4r)r5r6s r'collect_additional_contextz/CallbackQueryHandler.collect_additional_contexts% <<6L+nGO r()__name__ __module__ __qualname____doc__ __slots__r rr rrrr r#rr0robjectboolrrr3rr9 __classcell__)r&s@r'rr&sVp,I ;?*M-M!&#r/2M #ws|T8VHhtn4L+MM N M uS'#,%678 Md|M2)6)huT6\7J.K)V - - -A - D%*,- -  -r(r)r=rr$rrtypingrrrrr r r telegramr telegram._utils.defaultvaluer telegram._utils.typesr"telegram.ext._handlers.basehandlerrtelegram.ext._utils.typesrr telegram.extrrrr(r'rJsS&; OOO5(::( T]k-;vsB7k-r(