U
    gA                     @   s   d Z ddlZddlmZmZmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZ ddlmZmZ ed	Zerdd
lmZ G dd deeeef ZdS )z9This module contains the ChosenInlineResultHandler class.    N)TYPE_CHECKINGAnyMatchOptionalPatternTypeVarUnioncast)Update)DEFAULT_TRUE)DVType)BaseHandler)CCTHandlerCallbackRT)Applicationc                	       s   e Zd ZdZdZedfdeeee	f e
e eeeee f  d fddZeeeeef  dd	d
Zeedeeee f ddddZ  ZS )ChosenInlineResultHandlera  Handler class to handle Telegram updates that contain
    :attr:`telegram.Update.chosen_inline_result`.

    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`.
        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`
        pattern (:obj:`str` | :func:`re.Pattern <re.compile>`, optional): Regex pattern. If not
            :obj:`None`, :func:`re.match`
            is used on :attr:`telegram.ChosenInlineResult.result_id` to determine if an update
            should be handled by this handler. This is accessible in the callback as
            :attr:`telegram.ext.CallbackContext.matches`.

            .. versionadded:: 13.6
    Attributes:
        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`.
        pattern (`Pattern`): Optional. Regex pattern to test
            :attr:`telegram.ChosenInlineResult.result_id` against.

            .. versionadded:: 13.6

    )patternNz"ChosenInlineResultHandler[CCT, RT]selfcallbackblockr   c                    s.   t  j||d t|tr$t|}|| _d S )N)r   )super__init__
isinstancestrrecompiler   r   	__class__ T/tmp/pip-unpacked-wheel-swnnwir2/telegram/ext/_handlers/choseninlineresulthandler.pyr   N   s    

z"ChosenInlineResultHandler.__init__)updatereturnc                 C   s:   t |tr6|jr6| jr2t| j|jj }r6|S ndS dS )zDetermines whether an update should be passed to this handler's :attr:`callback`.

        Args:
            update (:class:`telegram.Update` | :obj:`object`): Incoming update.

        Returns:
            :obj:`bool` | :obj:`re.match`

        TN)r   r
   Zchosen_inline_resultr   r   matchZ	result_id)r   r"   r$   r    r    r!   check_update[   s    
z&ChosenInlineResultHandler.check_updatez)Application[Any, CCT, Any, Any, Any, Any])contextr"   applicationcheck_resultr#   c                 C   s   | j rtt|}|g|_dS )zuThis function adds the matched regex pattern result to
        :attr:`telegram.ext.CallbackContext.matches`.
        N)r   r	   r   matches)r   r&   r"   r'   r(   r    r    r!   collect_additional_contextm   s    

z4ChosenInlineResultHandler.collect_additional_context)__name__
__module____qualname____doc__	__slots__r   r   r
   r   r   r   boolr   r   r   r   r   objectr%   r   r*   __classcell__r    r    r   r!   r   #   s"   (r   )r.   r   typingr   r   r   r   r   r   r   r	   Ztelegramr
   Ztelegram._utils.defaultvaluer   Ztelegram._utils.typesr   Z"telegram.ext._handlers.basehandlerr   Ztelegram.ext._utils.typesr   r   r   Ztelegram.extr   r   r    r    r    r!   <module>   s   (