
    ՟fE              	           d Z ddlmZmZmZmZmZ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mZmZ erddlmZmZ dd	lm Z m!Z!m"Z" dd
lm#Z# dZ$ edd      Z% G d deeeeef         Z&y)z/This module contains the CallbackContext class.    )TYPE_CHECKINGAny	AwaitableDict	GeneratorGenericListMatchNoReturnOptionalTypeTypeVarUnion)CallbackQuery)Update)warn)ExtBot)BDBTCDUD)FutureQueue)ApplicationJobJobQueue)CCTzihttps://github.com/python-telegram-bot/python-telegram-bot/wiki/Storing-bot%2C-user-and-chat-related-dataSTz#CallbackContext[Any, Any, Any, Any])boundc                   x   e Zd ZdZdZ	 	 d+dedddee   dee   fd	Ze	d,d       Z
e	d
efd       Zej                  ded
efd       Ze	d
ee   fd       Zej                  ded
efd       Ze	d
ee   fd       Zej                  ded
efd       Zd-dZded
dfdZe	 	 d+ded   dededdded   deeeed   def   ee   f      d
dfd       Zeded   dedd d
dfd!       Zeded   dd"dd d
dfd#       Z d$e!e"ef   d
dfd%Z#e	d
e$fd&       Z%e	d
ed'   fd(       Z&e	d.d)       Z'e	d
ee(e"      fd*       Z)y)/CallbackContexta  
    This is a context object passed to the callback called by :class:`telegram.ext.BaseHandler`
    or by the :class:`telegram.ext.Application` in an error handler added by
    :attr:`telegram.ext.Application.add_error_handler` or to the callback of a
    :class:`telegram.ext.Job`.

    Note:
        :class:`telegram.ext.Application` will create a single context for an entire update. This
        means that if you got 2 handlers in different groups and they both get called, they will
        receive the same :class:`CallbackContext` object (of course with proper attributes like
        :attr:`matches` differing). This allows you to add custom attributes in a lower handler
        group callback, and then subsequently access those attributes in a higher handler group
        callback. Note that the attributes on :class:`CallbackContext` might change in the future,
        so make sure to use a fairly unique name for the attributes.

    Warning:
         Do not combine custom attributes with :paramref:`telegram.ext.BaseHandler.block` set to
         :obj:`False` or :attr:`telegram.ext.Application.concurrent_updates` set to
         :obj:`True`. Due to how those work, it will almost certainly execute the callbacks for an
         update out of order, and the attributes that you think you added will not be present.

    This class is a :class:`~typing.Generic` class and accepts four type variables:

    1. The type of :attr:`bot`. Must be :class:`telegram.Bot` or a subclass of that class.
    2. The type of :attr:`user_data` (if :attr:`user_data` is not :obj:`None`).
    3. The type of :attr:`chat_data` (if :attr:`chat_data` is not :obj:`None`).
    4. The type of :attr:`bot_data` (if :attr:`bot_data` is not :obj:`None`).

    Examples:
        * :any:`Context Types Bot <examples.contexttypesbot>`
        * :any:`Custom Webhook Bot <examples.customwebhookbot>`

    .. seealso:: :attr:`telegram.ext.ContextTypes.DEFAULT_TYPE`,
        :wiki:`Job Queue <Extensions---JobQueue>`

    Args:
        application (:class:`telegram.ext.Application`): The application associated with this
            context.
        chat_id (:obj:`int`, optional): The ID of the chat associated with this object. Used
            to provide :attr:`chat_data`.

            .. versionadded:: 20.0
        user_id (:obj:`int`, optional): The ID of the user associated with this object. Used
            to provide :attr:`user_data`.

            .. versionadded:: 20.0
    Attributes:
        coroutine (:term:`awaitable`): Optional. Only present in error handlers if the
            error was caused by an awaitable run with :meth:`Application.create_task` or a handler
            callback with :attr:`block=False <BaseHandler.block>`.
        matches (List[:meth:`re.Match <re.Match.expand>`]): Optional. If the associated update
            originated from a :class:`filters.Regex`, this will contain a list of match objects for
            every pattern where ``re.search(pattern, string)`` returned a match. Note that filters
            short circuit, so combined regex filters will not always be evaluated.
        args (List[:obj:`str`]): Optional. Arguments passed to a command if the associated update
            is handled by :class:`telegram.ext.CommandHandler`, :class:`telegram.ext.PrefixHandler`
            or :class:`telegram.ext.StringCommandHandler`. It contains a list of the words in the
            text after the command, using any whitespace string as a delimiter.
        error (:exc:`Exception`): Optional. The error that was raised. Only present when passed
            to an error handler registered with :attr:`telegram.ext.Application.add_error_handler`.
        job (:class:`telegram.ext.Job`): Optional. The job which originated this callback.
            Only present when passed to the callback of :class:`telegram.ext.Job` or in error
            handlers if the error is caused by a job.

            .. versionchanged:: 20.0
                :attr:`job` is now also present in error handlers if the error is caused by a job.

    )	__dict___application_chat_id_user_idargs	coroutineerrorjobmatchesNselfapplication$Application[BT, ST, UD, CD, BD, Any]chat_iduser_idc                 t    || _         || _        || _        d | _        d | _        d | _        d | _        d | _        y )N)r#   r$   r%   r&   r*   r(   r)   r'   )r+   r,   r.   r/   s       X/var/www/cvtools/html/venv/lib/python3.12/site-packages/telegram/ext/_callbackcontext.py__init__zCallbackContext.__init__   sD     CN'.'.)-	37*.
'+  	    returnc                     | j                   S )zP:class:`telegram.ext.Application`: The application associated with this context.)r#   r+   s    r1   r,   zCallbackContext.application   s        r3   c                 .    | j                   j                  S )aA  :obj:`ContextTypes.bot_data`: Optional. An object that can be used to keep any data in.
        For each update it will be the same :attr:`ContextTypes.bot_data`. Defaults to :obj:`dict`.

        .. seealso:: :wiki:`Storing Bot, User and Chat Related Data            <Storing-bot%2C-user-and-chat-related-data>`
        )r,   bot_datar6   s    r1   r8   zCallbackContext.bot_data   s     (((r3   _c                 &    t        dt               )Nz0You can not assign a new value to bot_data, see AttributeError_STORING_DATA_WIKIr+   r9   s     r1   r8   zCallbackContext.bot_data   s    >?Q>RS
 	
r3   c                 b    | j                   #| j                  j                  | j                      S y)a  :obj:`ContextTypes.chat_data`: Optional. An object that can be used to keep any data in.
        For each update from the same chat id it will be the same :obj:`ContextTypes.chat_data`.
        Defaults to :obj:`dict`.

        Warning:
            When a group chat migrates to a supergroup, its chat id will change and the
            ``chat_data`` needs to be transferred. For details see our
            :wiki:`wiki page <Storing-bot,-user-and-chat-related-data#chat-migration>`.

        .. seealso:: :wiki:`Storing Bot, User and Chat Related Data            <Storing-bot%2C-user-and-chat-related-data>`

        .. versionchanged:: 20.0
            The chat data is now also present in error handlers if the error is caused by a job.
        N)r$   r#   	chat_datar6   s    r1   r@   zCallbackContext.chat_data   s,    " ==$$$..t}}==r3   c                 &    t        dt               )Nz1You can not assign a new value to chat_data, see r;   r>   s     r1   r@   zCallbackContext.chat_data       ?@R?ST
 	
r3   c                 b    | j                   #| j                  j                  | j                      S y)a  :obj:`ContextTypes.user_data`: Optional. An object that can be used to keep any data in.
        For each update from the same user it will be the same :obj:`ContextTypes.user_data`.
        Defaults to :obj:`dict`.

        .. seealso:: :wiki:`Storing Bot, User and Chat Related Data            <Storing-bot%2C-user-and-chat-related-data>`

        .. versionchanged:: 20.0
            The user data is now also present in error handlers if the error is caused by a job.
        N)r%   r#   	user_datar6   s    r1   rD   zCallbackContext.user_data   s,     ==$$$..t}}==r3   c                 &    t        dt               )Nz1You can not assign a new value to user_data, see r;   r>   s     r1   rD   zCallbackContext.user_data   rB   r3   c                   K   | j                   j                  rV| j                   j                  j                  j                  r7| j                   j                  j	                  | j                         d{    | j                   j                  j                  j
                  rO| j                  C| j                   j                  j                  | j                  | j
                         d{    | j                   j                  j                  j                  rQ| j                  D| j                   j                  j                  | j                  | j                         d{    yyyy7 7 7 w)a  If :attr:`application` uses persistence, calls
        :meth:`telegram.ext.BasePersistence.refresh_bot_data` on :attr:`bot_data`,
        :meth:`telegram.ext.BasePersistence.refresh_chat_data` on :attr:`chat_data` and
        :meth:`telegram.ext.BasePersistence.refresh_user_data` on :attr:`user_data`, if
        appropriate.

        Will be called by :meth:`telegram.ext.Application.process_update` and
        :meth:`telegram.ext.Job.run`.

        .. versionadded:: 13.6
        N)r.   r@   )r/   rD   )r,   persistence
store_datar8   refresh_bot_datar@   r$   refresh_chat_datarD   r%   refresh_user_datar6   s    r1   refresh_datazCallbackContext.refresh_data   s.     ''++66??&&22CCDMMRRR++66@@T]]E^&&22DD MM"nn E    ++66@@T]]E^&&22DD MM"nn E    F_@ (R
s8   A4E76E17A8E7/E30A8E7(E5)	E73E75E7callback_queryc                     t        | j                  t              rG| j                  j                  t	        d      | j                  j                  j                  |       yt	        d      )a  
        Deletes the cached data for the specified callback query.

        .. versionadded:: 13.6

        Note:
            Will *not* raise exceptions in case the data is not found in the cache.
            *Will* raise :exc:`KeyError` in case the callback query can not be found in the cache.

        .. seealso:: :wiki:`Arbitrary callback_data <Arbitrary-callback_data>`

        Args:
            callback_query (:class:`telegram.CallbackQuery`): The callback query.

        Raises:
            KeyError | RuntimeError: :exc:`KeyError`, if the callback query can not be found in
                the cache and :exc:`RuntimeError`, if the bot doesn't allow for arbitrary
                callback data.
        NzGThis telegram.ext.ExtBot instance does not use arbitrary callback data.z8telegram.Bot does not allow for arbitrary callback data.)
isinstancebotr   callback_data_cacheRuntimeError	drop_data)r+   rM   s     r1   drop_callback_dataz"CallbackContext.drop_callback_data   s\    ( dhh'xx++3"]  HH((22>BJ r3   clsr   updater(   z%Application[BT, CCT, UD, CD, BD, Any]r)   zJob[Any]r'   zFuture[object]c                     || j                  ||      }n|| j                  ||      }n | |      }||_        ||_        |S )a'  
        Constructs an instance of :class:`telegram.ext.CallbackContext` to be passed to the error
        handlers.

        .. seealso:: :meth:`telegram.ext.Application.add_error_handler`

        .. versionchanged:: 20.0
            Removed arguments ``async_args`` and ``async_kwargs``.

        Args:
            update (:obj:`object` | :class:`telegram.Update`): The update associated with the
                error. May be :obj:`None`, e.g. for errors in job callbacks.
            error (:obj:`Exception`): The error.
            application (:class:`telegram.ext.Application`): The application associated with this
                context.
            job (:class:`telegram.ext.Job`, optional): The job associated with the error.

                .. versionadded:: 20.0
            coroutine (:term:`awaitable`, optional): The awaitable associated
                with this error if the error was caused by a coroutine run with
                :meth:`Application.create_task` or a handler callback with
                :attr:`block=False <BaseHandler.block>`.

                .. versionadded:: 20.0

                .. versionchanged:: 20.2
                    Accepts :class:`asyncio.Future` and generator-based coroutine functions.
        Returns:
            :class:`telegram.ext.CallbackContext`
        )from_updatefrom_jobr(   r'   )rU   rV   r(   r,   r)   r'   r+   s          r1   
from_errorzCallbackContext.from_error  sM    T ??6;7D_<<[1D{#D
"r3   z)Application[Any, CCT, Any, Any, Any, Any]c                     t        |t              rC|j                  }|j                  }|r|j                  nd}|r|j                  nd} | |||      S  | |      S )a  
        Constructs an instance of :class:`telegram.ext.CallbackContext` to be passed to the
        handlers.

        .. seealso:: :meth:`telegram.ext.Application.add_handler`

        Args:
            update (:obj:`object` | :class:`telegram.Update`): The update.
            application (:class:`telegram.ext.Application`): The application associated with this
                context.

        Returns:
            :class:`telegram.ext.CallbackContext`
        Nr.   r/   )rO   r   effective_chateffective_userid)rU   rV   r,   chatuserr.   r/   s          r1   rX   zCallbackContext.from_updateP  sX    ( ff%((D((D!%dgg4G!%dgg4G{GWEE;r3   zJob[CCT]c                 R     | ||j                   |j                        }||_        |S )a  
        Constructs an instance of :class:`telegram.ext.CallbackContext` to be passed to a
        job callback.

        .. seealso:: :meth:`telegram.ext.JobQueue`

        Args:
            job (:class:`telegram.ext.Job`): The job.
            application (:class:`telegram.ext.Application`): The application associated with this
                context.

        Returns:
            :class:`telegram.ext.CallbackContext`
        r\   )r.   r/   r)   )rU   r)   r,   r+   s       r1   rY   zCallbackContext.from_jobn  s&    ( ;S[[Ir3   datac                 N    |j                         D ]  \  }}t        | ||        y)zUpdates ``self.__slots__`` with the passed data.

        Args:
            data (Dict[:obj:`str`, :obj:`object`]): The data.
        N)itemssetattr)r+   rc   keyvalues       r1   rV   zCallbackContext.update  s)     **, 	&JCD#u%	&r3   c                 .    | j                   j                  S )z<:class:`telegram.Bot`: The bot associated with this context.)r#   rP   r6   s    r1   rP   zCallbackContext.bot  s       $$$r3   zJobQueue[ST]c                 t    | j                   j                  t        dd       | j                   j                  S )z
        :class:`telegram.ext.JobQueue`: The :class:`JobQueue` used by the
        :class:`telegram.ext.Application`.

        .. seealso:: :wiki:`Job Queue <Extensions---JobQueue>`
        zqNo `JobQueue` set up. To use `JobQueue`, you must install PTB via `pip install "python-telegram-bot[job-queue]"`.   )
stacklevel)r#   
_job_queuer   r6   s    r1   	job_queuezCallbackContext.job_queue  s;     ''/B
   +++r3   c                 .    | j                   j                  S )z
        :class:`asyncio.Queue`: The :class:`asyncio.Queue` instance used by the
            :class:`telegram.ext.Application` and (usually) the :class:`telegram.ext.Updater`
            associated with this context.

        )r#   update_queuer6   s    r1   rp   zCallbackContext.update_queue  s       ---r3   c                 L    	 | j                   d   S # t        t        f$ r Y yw xY w)z
        :meth:`re.Match <re.Match.expand>`: The first match from :attr:`matches`.
            Useful if you are only filtering using a single regex filter.
            Returns :obj:`None` if :attr:`matches` is empty.
        r   N)r*   
IndexError	TypeErrorr6   s    r1   matchzCallbackContext.match  s,    	<<?"I& 		s    ##)NN)r4   r-   )r4   N)r4   zQueue[object])*__name__
__module____qualname____doc__	__slots__r   r   intr2   propertyr,   r   r8   setterobjectr   r   r@   r   rD   rL   r   rT   classmethodr   	Exceptionr   r   r   r   rZ   rX   rY   r   strrV   r   rP   rn   rp   r
   rt    r3   r1   r!   r!   9   s   CJ
I "&!%	; # #	" ! ! )" ) ) __
& 
X 
 

 8B<  ( 
6 
h 
 

 8B<   
6 
h 
 

4 4 >  %) 2%[22 2 =	2
 j!2 )H%56cABIcNRS
2 
2 2h  %[   A  
	   : %[ A 
	 .&4V, & & %R % % ,8N3 , , . . 	xc
+ 	 	r3   r!   N)'rx   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   telegram._callbackqueryr   telegram._updater   telegram._utils.warningsr   telegram.ext._extbotr   telegram.ext._utils.typesr   r   r   r   asyncior   r   telegram.extr   r   r   r   r=   r   r!   r   r3   r1   <module>r      su   & 6     2 # ) ' 4 4%77-6  T>?gb"b"n- r3   