
    i                        d Z ddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZ 	 ddlmZ ddlmZ dZn# e$ r dZY nw xY wddl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rddl m!Z! erddl"m#Z$ ddl%m&Z&  e' e(d                    Z) ee*d          Z+de,de-fdZ. G d de	e                   Z/ G d de	e                   Z#dS )z2This module contains the classes JobQueue and Job.    N)TYPE_CHECKINGAnyGenericcastoverload)AsyncIOExecutor)AsyncIOSchedulerTF)UTClocalize)
get_logger)build_repr_with_selected_attrs)JSONDict)ExtBot)CCTJobCallback)Iterable)Job)Application   JobQueue)
class_namecallbackreturnc                 <    t          | dd          p| j        j        S )a  Get the name of a callback function or callable object.

    Args:
        callback: A callable object (function, method, or callable class instance)

    Returns:
        The name of the callback, using __name__ if available, otherwise the class name.
    __name__N)getattr	__class__r   )r   s    V/Users/shanyulin/my-agent/.venv/lib/python3.11/site-packages/telegram/ext/_jobqueue.py_get_callback_namer   7   s!     8Z..M(2D2MM    c                      e Zd ZdZdZdZd3dZdefdZe	d4d	            Z
e	defd
            Zdej        fdZed5dddeddfd            Ze	 d5deej        z  ej        z  ej        z  dedej        fd            Z	 d5deej        z  ej        z  ej        z  dz  dedej        dz  fdZ	 	 	 	 d6dZed7d            Z	 	 	 	 	 d8dee         deej        z  ej        z  ej        z  dedz  dedz  dedz  dedz  dedz  ddfd Z	 	 	 	 	 	 	 d9dee         d!eej        z  d"eej        z  ej        z  ej        z  dz  d#eej        z  ej        z  ej        z  dz  dedz  dedz  dedz  dedz  dedz  ddfd$Z	 	 	 	 	 d8dee         dej        d%ededz  dedz  dedz  dedz  dedz  ddfd&Ze dddddfdee         dej        d'e!ed(f         dedz  dedz  dedz  dedz  dedz  ddfd)Z"	 	 	 	 d:dee         dededz  dedz  dedz  dedz  ddfd*Z#d3d+Z$d;d-eddfd.Z%d<d/ee&j'        e         z  dz  de!d0         fd1Z(dede!d0         fd2Z)dS )=r   a  This class allows you to periodically perform tasks with the bot. It is a convenience
    wrapper for the APScheduler library.

    This class is a :class:`~typing.Generic` class and accepts one type variable that specifies
    the type of the argument ``context`` of the job callbacks (:paramref:`~run_once.callback`) of
    :meth:`run_once` and the other scheduling methods.

    Important:
        If you want to use this class, you must install PTB with the optional requirement
        ``job-queue``, i.e.

        .. code-block:: bash

           pip install "python-telegram-bot[job-queue]"

    Examples:
        :any:`Timer Bot <examples.timerbot>`

    .. seealso:: :wiki:`Architecture Overview <Architecture>`,
        :wiki:`Job Queue <Extensions---JobQueue>`

    .. versionchanged:: 20.0
        To use this class, PTB must be installed via
        ``pip install "python-telegram-bot[job-queue]"``.

    Attributes:
        scheduler (:class:`apscheduler.schedulers.asyncio.AsyncIOScheduler`): The scheduler.

            Warning:
                This scheduler is configured by :meth:`set_application`. Additional configuration
                settings can be made by users. However, calling
                :meth:`~apscheduler.schedulers.base.BaseScheduler.configure` will delete any
                previous configuration settings. Therefore, please make sure to pass the values
                returned by :attr:`scheduler_configuration` to the method call in addition to your
                custom values.
                Alternatively, you can also use methods like
                :meth:`~apscheduler.schedulers.base.BaseScheduler.add_jobstore` to avoid using
                :meth:`~apscheduler.schedulers.base.BaseScheduler.configure` altogether.

            .. versionchanged:: 20.0
                Uses :class:`~apscheduler.schedulers.asyncio.AsyncIOScheduler` instead of
                :class:`~apscheduler.schedulers.background.BackgroundScheduler`

    )_application	_executor	scheduler)sunmontuewedthufrisatr   Nc                     t           st          d          d | _        t                      | _        t          di | j        | _        d S )Nz\To use `JobQueue`, PTB must be installed via `pip install "python-telegram-bot[job-queue]"`. )APS_AVAILABLERuntimeErrorr"   r   r#   r	   scheduler_configurationr$   selfs    r   __init__zJobQueue.__init__t   s_     	5  
 HL(**-= .
 .
*.
 .
r    c                 .    t          | | j                  S )a$  Give a string representation of the JobQueue in the form ``JobQueue[application=...]``.

        As this class doesn't implement :meth:`object.__str__`, the default implementation
        will be used, which is equivalent to :meth:`__repr__`.

        Returns:
            :obj:`str`
        )application)r   r5   r1   s    r   __repr__zJobQueue.__repr__   s     .d@PQQQQr    3Application[Any, CCT, Any, Any, Any, JobQueue[CCT]]c                 |    | j         t          d          |                                  }||S t          d          )z1The application this JobQueue is associated with.Nz)No application was set for this JobQueue.z,The application instance is no longer alive.)r"   r/   r2   r5   s     r   r5   zJobQueue.application   sH     $JKKK''))"IJJJr    c                     t           }| j        rMt          | j        j        t
                    r.| j        j        j        r| j        j        j        j        pt           }|d| j        idS )a_  Provides configuration values that are used by :class:`JobQueue` for :attr:`scheduler`.

        Tip:
            Since calling
            :meth:`scheduler.configure() <apscheduler.schedulers.base.BaseScheduler.configure>`
            deletes any previous setting, please make sure to pass these values to the method call
            in addition to your custom values:

            .. code-block:: python

                scheduler.configure(..., **job_queue.scheduler_configuration)

            Alternatively, you can also use methods like
            :meth:`~apscheduler.schedulers.base.BaseScheduler.add_jobstore` to avoid using
            :meth:`~apscheduler.schedulers.base.BaseScheduler.configure` altogether.

        .. versionadded:: 20.7

        Returns:
            dict[:obj:`str`, :obj:`object`]: The configuration values as dictionary.

        default)timezone	executors)	r
   r"   
isinstancer5   botr   defaultstzinfor#   )r2   r<   s     r   r0   z JobQueue.scheduler_configuration   sx    0  #	C4+/88	C  $-	C
 '+4;BsH !#T^4
 
 	
r    c                 T    t           j                            | j        j                  S N)dtmdatetimenowr$   r<   r1   s    r   _tz_nowzJobQueue._tz_now   s    | 7888r    Ftime	shift_dayc                     d S rC   r-   r2   rH   rI   s      r   _parse_time_inputzJobQueue._parse_time_input   s    NQcr    c                     d S rC   r-   rK   s      r   rL   zJobQueue._parse_time_input   s	    
 sr    c                    |d S t          |t          t          z            r*|                                 t	          j        |          z   S t          |t          j                  r|                                 |z   S t          |t          j                  rt          j                            t          j        	                    |j
        p| j        j                                                  |          }|j
        t          || j        j                  }|r@|t          j        	                    t                    k    r|t	          j        d          z  }|S |S )N)seconds)tz   )days)r>   intfloatrG   rD   	timedeltarH   rE   combinerF   rA   r$   r<   dater   r
   )r2   rH   rI   	date_times       r   rL   zJobQueue._parse_time_input   s-   
 <4dC%K(( 	@<<>>CM$$?$?$???dCM** 	)<<>>D((dCH%% 
	,,  DK$J4>3J KKPPRRTX I ' %Y0GHH	 3Y#,*:*:3*?*???S]2222	r    r5   c                 f    t          j        |          | _         | j        j        di | j         dS )zSet the application to be used by this JobQueue.

        Args:
            application (:class:`telegram.ext.Application`): The application.

        Nr-   )weakrefrefr"   r$   	configurer0   r9   s     r   set_applicationzJobQueue.set_application   s:     $K44  @@4#?@@@@@r    	job_queueJobQueue[CCT]jobJob[CCT]c                 J   K   |                     | j                   d{V  dS )a  This method is used as a callback for the APScheduler jobs.

        More precisely, the ``func`` argument of :class:`apscheduler.job.Job` is set to this method
        and the ``arg`` argument (representing positional arguments to ``func``) is set to a tuple
        containing the :class:`JobQueue` itself and the :class:`~telegram.ext.Job` instance.

        Tip:
            This method is a static method rather than a bound method. This makes the arguments
            more transparent and allows for easier handling of PTBs integration of APScheduler
            when utilizing advanced features of APScheduler.

        Hint:
            This method is effectively a wrapper for :meth:`telegram.ext.Job.run`.

        .. versionadded:: 20.4

        Args:
            job_queue (:class:`JobQueue`): The job queue that created the job.
            job (:class:`~telegram.ext.Job`): The job to run.
        N)runr5   )r^   r`   s     r   job_callbackzJobQueue.job_callback   s5      , ggi+,,,,,,,,,,,r    r   whendatanamechat_iduser_id
job_kwargsc           	          |si }|pt          |          }t          |||||          }|                     |d          }	 | j        j        | j        f|d|	| |f|	j        p| j        j        d|}
|
|_        |S )a  Creates a new :class:`Job` instance that runs once and adds it to the queue.

        Args:
            callback (:term:`coroutine function`): The callback function that should be executed by
                the new job. Callback signature::

                    async def callback(context: CallbackContext)

            when (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` |                                           :obj:`datetime.datetime` | :obj:`datetime.time`):
                Time in or at which the job should run. This parameter will be interpreted
                depending on its type.

                * :obj:`int` or :obj:`float` will be interpreted as "seconds from now" in which the
                  job should run.
                * :obj:`datetime.timedelta` will be interpreted as "time from now" in which the
                  job should run.
                * :obj:`datetime.datetime` will be interpreted as a specific date and time at
                  which the job should run. If the timezone (:attr:`datetime.datetime.tzinfo`) is
                  :obj:`None`, the default timezone of the bot will be used, which is UTC unless
                  :attr:`telegram.ext.Defaults.tzinfo` is used.
                * :obj:`datetime.time` will be interpreted as a specific time of day at which the
                  job should run. This could be either today or, if the time has already passed,
                  tomorrow. If the timezone (:attr:`datetime.time.tzinfo`) is :obj:`None`, the
                  default timezone of the bot will be used, which is UTC unless
                  :attr:`telegram.ext.Defaults.tzinfo` is used.

            chat_id (:obj:`int`, optional): Chat id of the chat associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.chat_data` will
                be available in the callback.

                .. versionadded:: 20.0

            user_id (:obj:`int`, optional): User id of the user associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.user_data` will
                be available in the callback.

                .. versionadded:: 20.0
            data (:obj:`object`, optional): Additional data needed for the callback function.
                Can be accessed through :attr:`Job.data` in the callback. Defaults to
                :obj:`None`.

                .. versionchanged:: 20.0
                    Renamed the parameter ``context`` to :paramref:`data`.
            name (:obj:`str`, optional): The name of the new job. Defaults to
                :external:attr:`callback.__name__ <definition.__name__>`.
            job_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to pass to the
                :meth:`apscheduler.schedulers.base.BaseScheduler.add_job()`.

        Returns:
            :class:`telegram.ext.Job`: The new :class:`Job` instance that has been added to the job
            queue.

        r   rf   rg   rh   ri   T)rI   rW   )rg   triggerrun_dateargsr<   )	r   r   rL   r$   add_jobrd   rA   r<   _job)r2   r   re   rf   rg   rh   ri   rj   r`   rX   js              r   run_oncezJobQueue.run_once  s    @  	J3)(338$T7T[\\\**44*@@	"DN"
%@)@
 
 
 
 
r    intervalfirstlastc
           
         |	si }	|pt          |          }t          |||||          }
|                     |          }|                     |          }|r|r||k     rt          d          t	          |t
          j                  r|                                } | j        j	        | j
        fd| |
f||||d|	}||
_        |
S )a~  Creates a new :class:`Job` instance that runs at specified intervals and adds it to the
        queue.

        Note:
            For a note about DST, please see the documentation of `APScheduler`_.

        .. _`APScheduler`: https://apscheduler.readthedocs.io/en/stable/modules/triggers/cron.html
                           #daylight-saving-time-behavior

        Args:
            callback (:term:`coroutine function`): The callback function that should be executed by
                the new job. Callback signature::

                    async def callback(context: CallbackContext)

            interval (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta`): The interval in which
                the job will run. If it is an :obj:`int` or a :obj:`float`, it will be interpreted
                as seconds.
            first (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` |                                           :obj:`datetime.datetime` | :obj:`datetime.time`, optional):
                Time in or at which the job should run. This parameter will be interpreted
                depending on its type.

                * :obj:`int` or :obj:`float` will be interpreted as "seconds from now" in which the
                  job should run.
                * :obj:`datetime.timedelta` will be interpreted as "time from now" in which the
                  job should run.
                * :obj:`datetime.datetime` will be interpreted as a specific date and time at
                  which the job should run. If the timezone (:attr:`datetime.datetime.tzinfo`) is
                  :obj:`None`, the default timezone of the bot will be used.
                * :obj:`datetime.time` will be interpreted as a specific time of day at which the
                  job should run. This could be either today or, if the time has already passed,
                  tomorrow. If the timezone (:attr:`datetime.time.tzinfo`) is :obj:`None`, the
                  default timezone of the bot will be used, which is UTC unless
                  :attr:`telegram.ext.Defaults.tzinfo` is used.

                Defaults to :paramref:`interval`

                Note:
                    Setting :paramref:`first` to ``0``, ``datetime.datetime.now()`` or another
                    value that indicates that the job should run immediately will not work due
                    to how the APScheduler library works. If you want to run a job immediately,
                    we recommend to use an approach along the lines of::

                        job = context.job_queue.run_repeating(callback, interval=5)
                        await job.run(context.application)

                    .. seealso:: :meth:`telegram.ext.Job.run`

            last (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` |                                           :obj:`datetime.datetime` | :obj:`datetime.time`, optional):
                Latest possible time for the job to run. This parameter will be interpreted
                depending on its type. See :paramref:`first` for details.

                If :paramref:`last` is :obj:`datetime.datetime` or :obj:`datetime.time` type
                and ``last.tzinfo`` is :obj:`None`, the default timezone of the bot will be
                assumed, which is UTC unless :attr:`telegram.ext.Defaults.tzinfo` is used.

                Defaults to :obj:`None`.
            data (:obj:`object`, optional): Additional data needed for the callback function.
                Can be accessed through :attr:`Job.data` in the callback. Defaults to
                :obj:`None`.

                .. versionchanged:: 20.0
                    Renamed the parameter ``context`` to :paramref:`data`.
            name (:obj:`str`, optional): The name of the new job. Defaults to
                :external:attr:`callback.__name__ <definition.__name__>`.
            chat_id (:obj:`int`, optional): Chat id of the chat associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.chat_data` will
                be available in the callback.

                .. versionadded:: 20.0

            user_id (:obj:`int`, optional): User id of the user associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.user_data` will
                be available in the callback.

                .. versionadded:: 20.0
            job_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to pass to the
                :meth:`apscheduler.schedulers.base.BaseScheduler.add_job()`.

        Returns:
            :class:`telegram.ext.Job`: The new :class:`Job` instance that has been added to the job
            queue.

        rl   z"'last' must not be before 'first'!rt   )rm   ro   
start_dateend_daterO   rg   )r   r   rL   
ValueErrorr>   rD   rU   total_secondsr$   rp   rd   rq   )r2   r   rt   ru   rv   rf   rg   rh   ri   rj   r`   dt_firstdt_lastrr   s                 r   run_repeatingzJobQueue.run_repeatingX  s   D  	J3)(338$T7T[\\\))%00((.. 	Cx 	CGh$6$6ABBBh.. 	0--//H"DN"	
	
 	
 	
 	
 
r    dayc	                     |si }|pt          |          }t          |||||          }	 | j        j        | j        fd| |	f||dk    rdn||j        |j        |j        |j        p| j        j	        d|}
|
|	_
        |	S )a	  Creates a new :class:`Job` that runs on a monthly basis and adds it to the queue.

        .. versionchanged:: 20.0
            The ``day_is_strict`` argument was removed. Instead one can now pass ``-1`` to the
            :paramref:`day` parameter to have the job run on the last day of the month.

        Args:
            callback (:term:`coroutine function`): The callback function that should be executed by
                the new job. Callback signature::

                    async def callback(context: CallbackContext)

            when (:obj:`datetime.time`): Time of day at which the job should run. If the timezone
                (``when.tzinfo``) is :obj:`None`, the default timezone of the bot will be used,
                which is UTC unless :attr:`telegram.ext.Defaults.tzinfo` is used.
            day (:obj:`int`): Defines the day of the month whereby the job would run. It should
                be within the range of ``1`` and ``31``, inclusive. If a month has fewer days than
                this number, the job will not run in this month. Passing ``-1`` leads to the job
                running on the last day of the month.
            data (:obj:`object`, optional): Additional data needed for the callback function.
                Can be accessed through :attr:`Job.data` in the callback. Defaults to
                :obj:`None`.

                .. versionchanged:: 20.0
                    Renamed the parameter ``context`` to :paramref:`data`.
            name (:obj:`str`, optional): The name of the new job. Defaults to
                :external:attr:`callback.__name__ <definition.__name__>`.
            chat_id (:obj:`int`, optional): Chat id of the chat associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.chat_data` will
                be available in the callback.

                .. versionadded:: 20.0

            user_id (:obj:`int`, optional): User id of the user associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.user_data` will
                be available in the callback.

                .. versionadded:: 20.0
            job_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to pass to the
                :meth:`apscheduler.schedulers.base.BaseScheduler.add_job()`.

        Returns:
            :class:`telegram.ext.Job`: The new :class:`Job` instance that has been added to the job
            queue.

        rl   cronrv   )rm   ro   rg   r   hourminutesecondr<   )r   r   r$   rp   rd   r   r   r   rA   r<   rq   )r2   r   re   r   rf   rg   rh   ri   rj   r`   rr   s              r   run_monthlyzJobQueue.run_monthly  s    r  	J3)(338$T7T[\\\"DN"
));;[;DN$;
 
 
 
 
r    rR   .c	                 ,    |si }|pt          |          }t          |||||          }	  j        j         j        f| |	fdd                     fd|D                       |j        |j        |j        |j	        p j        j
        d|}
|
|	_        |	S )a	  Creates a new :class:`Job` that runs on a daily basis and adds it to the queue.

        Note:
            For a note about DST, please see the documentation of `APScheduler`_.

        .. _`APScheduler`: https://apscheduler.readthedocs.io/en/stable/modules/triggers/cron.html
                           #daylight-saving-time-behavior

        Args:
            callback (:term:`coroutine function`): The callback function that should be executed by
                the new job. Callback signature::

                    async def callback(context: CallbackContext)

            time (:obj:`datetime.time`): Time of day at which the job should run. If the timezone
                (:obj:`datetime.time.tzinfo`) is :obj:`None`, the default timezone of the bot will
                be used, which is UTC unless :attr:`telegram.ext.Defaults.tzinfo` is used.
            days (tuple[:obj:`int`], optional): Defines on which days of the week the job should
                run (where ``0-6`` correspond to sunday - saturday). By default, the job will run
                every day.

                .. versionchanged:: 20.0
                    Changed day of the week mapping of 0-6 from monday-sunday to sunday-saturday.

            data (:obj:`object`, optional): Additional data needed for the callback function.
                Can be accessed through :attr:`Job.data` in the callback. Defaults to
                :obj:`None`.

                .. versionchanged:: 20.0
                    Renamed the parameter ``context`` to :paramref:`data`.
            name (:obj:`str`, optional): The name of the new job. Defaults to
                :external:attr:`callback.__name__ <definition.__name__>`.
            chat_id (:obj:`int`, optional): Chat id of the chat associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.chat_data` will
                be available in the callback.

                .. versionadded:: 20.0

            user_id (:obj:`int`, optional): User id of the user associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.user_data` will
                be available in the callback.

                .. versionadded:: 20.0
            job_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to pass to the
                :meth:`apscheduler.schedulers.base.BaseScheduler.add_job()`.

        Returns:
            :class:`telegram.ext.Job`: The new :class:`Job` instance that has been added to the job
            queue.

        rl   r   ,c                 *    g | ]}j         |         S r-   )_CRON_MAPPING).0dr2   s     r   
<listcomp>z&JobQueue.run_daily.<locals>.<listcomp>n  s!    !F!F!FA$"4Q"7!F!F!Fr    )rg   ro   rm   day_of_weekr   r   r   r<   )r   r   r$   rp   rd   joinr   r   r   rA   r<   rq   )r2   r   rH   rR   rf   rg   rh   ri   rj   r`   rr   s   `          r   	run_dailyzJobQueue.run_daily%  s    |  	J3)(338$T7T[\\\"DN"
!F!F!F!F!F!F!FGG;;[;DN$;
 
 
 
 
r    c                     |pt          |          }t          |||||          } | j        j        | j        f| |f|d|}||_        |S )aL  Creates a new custom defined :class:`Job`.

        Args:
            callback (:term:`coroutine function`): The callback function that should be executed by
                the new job. Callback signature::

                    async def callback(context: CallbackContext)

            job_kwargs (:obj:`dict`): Arbitrary keyword arguments. Used as arguments for
                :meth:`apscheduler.schedulers.base.BaseScheduler.add_job`.
            data (:obj:`object`, optional): Additional data needed for the callback function.
                Can be accessed through :attr:`Job.data` in the callback. Defaults to
                :obj:`None`.

                .. versionchanged:: 20.0
                    Renamed the parameter ``context`` to :paramref:`data`.
            name (:obj:`str`, optional): The name of the new job. Defaults to
                :external:attr:`callback.__name__ <definition.__name__>`.
            chat_id (:obj:`int`, optional): Chat id of the chat associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.chat_data` will
                be available in the callback.

                .. versionadded:: 20.0

            user_id (:obj:`int`, optional): User id of the user associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.user_data` will
                be available in the callback.

                .. versionadded:: 20.0

        Returns:
            :class:`telegram.ext.Job`: The new :class:`Job` instance that has been added to the job
            queue.

        rl   )ro   rg   )r   r   r$   rp   rd   rq   )	r2   r   rj   rf   rg   rh   ri   r`   rr   s	            r   
run_customzJobQueue.run_customy  sh    X 3)(338$T7T[\\\"DN"4#4`D#;T``U_``
r    c                 X   K   | j         j        s| j                                          dS dS )z+Starts the :class:`~telegram.ext.JobQueue`.N)r$   runningstartr1   s    r   r   zJobQueue.start  s9       ~% 	#N  """""	# 	#r    Twaitc                    K   |r!t          j        | j        j        ddi d{V  | j        j        r7| j                            |           t          j        d           d{V  dS dS )zShuts down the :class:`~telegram.ext.JobQueue`.

        Args:
            wait (:obj:`bool`, optional): Whether to wait until all currently running jobs
                have finished. Defaults to :obj:`True`.

        return_exceptionsTN)r   g{Gz?)asynciogatherr#   _pending_futuresr$   r   shutdownsleep)r2   r   s     r   stopzJobQueue.stop  s        	.0"&         >! 	&N###... -%%%%%%%%%%%		& 	&r    pattern)ra   .c                     d | j                                         D             }t          |          S t          fd|D                       S )a%  Returns a tuple of all *scheduled* jobs that are currently in the :class:`JobQueue`.

        Args:
            pattern (:obj:`str` | :obj:`re.Pattern`, optional): A regular expression pattern. If
                passed, only jobs whose name matches the pattern will be returned.
                Defaults to :obj:`None`.

                Hint:
                    This uses :func:`re.search` and not :func:`re.match`.

                .. versionadded:: 21.10

        Returns:
            tuple[:class:`Job`]: Tuple of all *scheduled* jobs.
        c              3   J   K   | ]}t                               |          V  d S rC   )r   from_aps_job)r   r`   s     r   	<genexpr>z JobQueue.jobs.<locals>.<genexpr>  sA       )
 )
&)CS!!)
 )
 )
 )
 )
 )
r    Nc              3      K   | ]9}|j         	t          j                                      |j                   5|V  :d S rC   )rg   recompilesearch)r   r`   r   s     r   r   z JobQueue.jobs.<locals>.<genexpr>  sb       
 
ch
;=:g;N;N;U;UVYV^;_;_

 
 
 
 
 
r    )r$   get_jobstuple)r2   r   jobs_generators    ` r   jobszJobQueue.jobs  s|     )
 )
-1^-D-D-F-F)
 )
 )
 ?((( 
 
 
 
)
 
 
 
 
 	
r    c                 X    |                      dt          j        |           d          S )af  Returns a tuple of all *scheduled* jobs with the given name that are currently
        in the :class:`JobQueue`.

        Hint:
            This method is a convenience wrapper for :meth:`jobs` with a pattern that matches the
            given name.

        Returns:
            tuple[:class:`Job`]: Tuple of all *scheduled* jobs matching the name.
        ^$)r   r   escape)r2   rg   s     r   get_jobs_by_namezJobQueue.get_jobs_by_name  s*     yy/RYt__///000r    r   N)r   r7   )Fr5   r7   r   N)r^   r_   r`   ra   r   N)NNNNN)NNNNNNNNNNN)TrC   )*r   
__module____qualname____doc__	__slots__r   r3   strr6   propertyr5   r   r0   rD   rE   rG   r   boolrL   rT   rU   rH   r]   staticmethodrd   r   r   objectrS   rs   r~   r   	_ALL_DAYSr   r   r   r   r   r   Patternr   r   r-   r    r   r   r   C   s        + +Z ;IEM
 
 
 
	R# 	R 	R 	R 	R K K K XK "
 "
 "
 "
 X"
H9 9 9 9 9 QQdQtQQQQ XQ   cm#cl2SX=  
	   X   cm#cl2SX=D  
		   0
AP
A	
A 
A 
A 
A - - - \-6 #""&*R Rc"R cm#cl2SX=R tm	R
 DjR tR tR tOR 
R R R Rp IMGK"""&*} }c"} #-'} s}$s|3ch>E	}
 cm#cl2SX=D} tm} Dj} t} t} tO} 
} } } }H #""&*L Lc"L hL 	L
 tmL DjL tL tL tOL 
L L L Ld !*"""&*R Rc"R hR CHo	R
 tmR DjR tR tR tOR 
R R R Rp #""2 2c"2 2 tm	2
 Dj2 t2 t2 
2 2 2 2h# # # #& &t &t & & & &.
 
C"*S/1D8 
E/DZ 
 
 
 
21S 1U?-C 1 1 1 1 1 1r    c                   ~   e Zd ZdZdZ	 	 	 	 d dee         dedz  dedz  de	dz  de	dz  f
d	Z
d
edefdZdedefdZde	fdZdefdZed!d            Zedefd            Zedefd            Zej        deddfd            Zedej        dz  fd            Zed"d            Z	 	 	 	 d#dZ	 	 	 	 d#dZd$dZdS )%r   a
  This class is a convenience wrapper for the jobs held in a :class:`telegram.ext.JobQueue`.
    With the current backend APScheduler, :attr:`job` holds a :class:`apscheduler.job.Job`
    instance.

    Objects of this class are comparable in terms of equality. Two objects of this class are
    considered equal, if their :class:`id <apscheduler.job.Job>` is equal.

    This class is a :class:`~typing.Generic` class and accepts one type variable that specifies
    the type of the argument ``context`` of :paramref:`callback`.

    Important:
        If you want to use this class, you must install PTB with the optional requirement
        ``job-queue``, i.e.

        .. code-block:: bash

           pip install "python-telegram-bot[job-queue]"

    Note:
        All attributes and instance methods of :attr:`job` are also directly available as
        attributes/methods of the corresponding :class:`telegram.ext.Job` object.

    Warning:
        This class should not be instantiated manually.
        Use the methods of :class:`telegram.ext.JobQueue` to schedule jobs.

    .. seealso:: :wiki:`Job Queue <Extensions---JobQueue>`

    .. versionchanged:: 20.0

       * Removed argument and attribute ``job_queue``.
       * Renamed ``Job.context`` to :attr:`Job.data`.
       * Removed argument ``job``
       * To use this class, PTB must be installed via
         ``pip install "python-telegram-bot[job-queue]"``.

    Args:
        callback (:term:`coroutine function`): The callback function that should be executed by the
            new job. Callback signature::

                async def callback(context: CallbackContext)

        data (:obj:`object`, optional): Additional data needed for the :paramref:`callback`
            function. Can be accessed through :attr:`Job.data` in the callback. Defaults to
            :obj:`None`.
        name (:obj:`str`, optional): The name of the new job. Defaults to
            :external:obj:`callback.__name__ <definition.__name__>`.
        chat_id (:obj:`int`, optional): Chat id of the chat that this job is associated with.

            .. versionadded:: 20.0
        user_id (:obj:`int`, optional): User id of the user that this job is associated with.

            .. versionadded:: 20.0
    Attributes:
        callback (:term:`coroutine function`): The callback function that should be executed by the
            new job.
        data (:obj:`object`): Optional. Additional data needed for the :attr:`callback` function.
        name (:obj:`str`): Optional. The name of the new job.
        chat_id (:obj:`int`): Optional. Chat id of the chat that this job is associated with.

            .. versionadded:: 20.0
        user_id (:obj:`int`): Optional. User id of the user that this job is associated with.

            .. versionadded:: 20.0
    )_enabledrq   _removedr   rh   rf   rg   ri   Nr   rf   rg   rh   ri   c                     t           st          d          || _        || _        |pt	          |          | _        || _        || _        d| _        d| _	        t          dd           | _        d S )NzWTo use `Job`, PTB must be installed via `pip install "python-telegram-bot[job-queue]"`.FAPSJob)r.   r/   r   rf   r   rg   rh   ri   r   r   r   rq   )r2   r   rf   rg   rh   ri   s         r   r3   zJob.__init__?  sy      	5  
 +3#'	 $ D(:8(D(D	#*#*4((			r    itemr   c                 z    	 t          | j        |          S # t          $ r}t          d| d          |d}~ww xY w)a  Overrides :py:meth:`object.__getattr__` to get specific attribute of the
        :class:`telegram.ext.Job` object or of its attribute :class:`apscheduler.job.Job`,
        if exists.

        Args:
           item (:obj:`str`): The name of the attribute.

        Returns:
            :object: The value of the attribute.

        Raises:
            :exc:`AttributeError`: If the attribute does not exist in both
                :class:`telegram.ext.Job` and :class:`apscheduler.job.Job` objects.
        zDNeither 'telegram.ext.Job' nor 'apscheduler.job.Job' has attribute ''N)r   r`   AttributeError)r2   r   excs      r   __getattr__zJob.__getattr__X  s\    	48T*** 	 	 	 ^W[^^^ 	s    
:5:otherc                 P    t          || j                  r| j        |j        k    S dS )aP  Defines equality condition for the :class:`telegram.ext.Job` object.
        Two objects of this class are considered to be equal if their
        :class:`id <apscheduler.job.Job>` are equal.

        Returns:
            :obj:`True` if both objects have :paramref:`id` parameters identical.
            :obj:`False` otherwise.
        F)r>   r   id)r2   r   s     r   __eq__z
Job.__eq__n  s,     eT^,, 	'7eh&&ur    c                 *    t          | j                  S )zBuilds a hash value for this object such that the hash of two objects is
        equal if and only if the objects are equal in terms of :meth:`__eq__`.

        Returns:
            :obj:`int`: The hash value of the object.
        )hashr   r1   s    r   __hash__zJob.__hash__{  s     DG}}r    c                     t          | | j        j        | j        t	          | j                  | j        j                  S )a>  Give a string representation of the job in the form
        ``Job[id=..., name=..., callback=..., trigger=...]``.

        As this class doesn't implement :meth:`object.__str__`, the default implementation
        will be used, which is equivalent to :meth:`__repr__`.

        Returns:
            :obj:`str`
        )r   rg   r   rm   )r   r`   r   rg   r   r   rm   r1   s    r   r6   zJob.__repr__  s?     .x{'66H$
 
 
 	
r    r   c                     | j         S )z:class:`apscheduler.job.Job`: The APS Job this job is a wrapper for.

        .. versionchanged:: 20.0
            This property is now read-only.
        )rq   r1   s    r   r`   zJob.job  s     yr    c                     | j         S )z3:obj:`bool`: Whether this job is due to be removed.)r   r1   s    r   removedzJob.removed       }r    c                     | j         S )z):obj:`bool`: Whether this job is enabled.)r   r1   s    r   enabledzJob.enabled  r   r    statusc                 ~    |r| j                                          n| j                                          || _        d S rC   )r`   resumepauser   )r2   r   s     r   r   zJob.enabled  s<     	HOOHNNr    c                     | j         j        S )a  
        :class:`datetime.datetime`: Datetime for the next job execution.
        Datetime is localized according to :attr:`datetime.datetime.tzinfo`.
        If job is removed or already ran it equals to :obj:`None`.

        Warning:
            This attribute is only available, if the :class:`telegram.ext.JobQueue` this job
            belongs to is already started. Otherwise APScheduler raises an :exc:`AttributeError`.
        )r`   next_run_timer1   s    r   next_tz
Job.next_t  s     x%%r    aps_jobra   c                 .    |j         d         }||_        |S )a  Provides the :class:`telegram.ext.Job` that is associated with the given APScheduler
        job.

        Tip:
            This method can be useful when using advanced APScheduler features along with
            :class:`telegram.ext.JobQueue`.

        .. versionadded:: 20.4

        Args:
            aps_job (:class:`apscheduler.job.Job`): The APScheduler job

        Returns:
            :class:`telegram.ext.Job`
        rQ   )ro   rq   )clsr   ext_jobs      r   r   zJob.from_aps_job  s    " ,q/r    r5   r7   c                 d   K   t          j        |                     |                     d{V  dS )a  Executes the callback function independently of the jobs schedule. Also calls
        :meth:`telegram.ext.Application.update_persistence`.

        .. versionchanged:: 20.0
            Calls :meth:`telegram.ext.Application.update_persistence`.

        Args:
            application (:class:`telegram.ext.Application`): The application this job is associated
                with.
        N)r   shield_runr9   s     r   rc   zJob.run  s<       nTYY{3344444444444r    c                 d  K   	 	 |j         j                            | |          }nP# t          $ rC}t                              d| j        |           Y d }~|                    |            d S d }~ww xY w|                                 d {V  | 	                    |           d {V  nS# t          $ rF}|
                    |                    d ||           d| j         d           d {V  Y d }~nd }~ww xY w|                    |            d S # |                    |            w xY w)NzEError while building CallbackContext for job %s. Job will not be run.)exc_info)r`   zJob:z:run:process_error)rg   )context_typescontextfrom_job	Exception_LOGGERcriticalrq   _mark_for_persistence_updaterefresh_datar   create_taskprocess_errorr   )r2   r5   r   r   s       r   r   zJob._run  s     	?%3;DDT;WW     [I  !   
  444>>>>># &&(((((((((--(((((((((( 	 	 	))))$)>>7DG777 *              	 444>>>>>K444>>>>sO    & B, 
A3"A.B, .A338B, +D ,
C<6<C72D 7C<<D D/c                 F    | j                                          d| _        dS )z
        Schedules this job for removal from the :class:`JobQueue`. It will be removed without
        executing its callback function again.
        TN)r`   remover   r1   s    r   schedule_removalzJob.schedule_removal  s!    
 	r    r   )r   r   )r   r   r   ra   r   r   )r   r   r   r   r   r   r   r   r   rS   r3   r   r   r   r   r6   r   r`   r   r   setterrD   rE   r   classmethodr   rc   r   r   r-   r    r   r   r     sV       @ @D	I #"") )c") tm) Dj	)
 t) t) ) ) )2     ,F t    #    
# 
 
 
 
$    X     X     X ^d t    ^ 
&t+ 
& 
& 
& X
&    [(5P5	5 5 5 5 ?P?	? ? ? ?2     r    r   )0r   r   rE   rD   r   rZ   typingr   r   r   r   r   apscheduler.executors.asyncior   apscheduler.schedulers.asyncior	   r.   ImportErrortelegram._utils.datetimer
   r   telegram._utils.loggingr   telegram._utils.reprr   telegram._utils.typesr   telegram.ext._extbotr   telegram.ext._utils.typesr   r   collections.abcr   apscheduler.jobr   r   telegram.extr   r   ranger   r   r   r   r   r   r   r-   r    r   <module>r     s>  & 9 8      				  > > > > > > > > > > > > > >======??????MM   MMM 3 2 2 2 2 2 2 2 . . . . . . ? ? ? ? ? ? * * * * * * ' ' ' ' ' ' 6 6 6 6 6 6 6 6 )(((((( 2111111(((((( E%%((OO	
*X*
5
5
5	N 	NC 	N 	N 	N 	Nk
1 k
1 k
1 k
1 k
1ws| k
1 k
1 k
1\Q Q Q Q Q'#, Q Q Q Q Qs   1 ;;