o
    th+                     @   s   d dl mZmZ d dlmZ d dlZd dlmZ d dlm	Z	m
Z
mZmZmZmZmZ z
d dlmZmZ W n eyE   d dlmZmZ Y nw G dd deZdS )	    )ismethodisclass)uuid4N)BaseTrigger)
ref_to_obj
obj_to_refdatetime_reprrepr_escapeget_callable_namecheck_callable_argsconvert_to_datetime)IterableMappingc                       s   e Zd ZdZdZd" fdd	Zdd Zdd	 Zd
d Zdd Z	dd Z
edd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Z  ZS )#Joba  
    Contains the options given when scheduling callables and its current schedule and other state.
    This class should never be instantiated by the user.

    :var str id: the unique identifier of this job
    :var str name: the description of this job
    :var func: the callable to execute
    :var tuple|list args: positional arguments to the callable
    :var dict kwargs: keyword arguments to the callable
    :var bool coalesce: whether to only run the job once when several run times are due
    :var trigger: the trigger object that controls the schedule of this job
    :var str executor: the name of the executor that will run this job
    :var int misfire_grace_time: the time (in seconds) how much this job's execution is allowed to
        be late (``None`` means "allow the job to run no matter how late it is")
    :var int max_instances: the maximum number of concurrently executing instances allowed for this
        job
    :var datetime.datetime next_run_time: the next scheduled run time of this job

    .. note::
        The ``misfire_grace_time`` has some non-obvious effects on job execution. See the
        :ref:`missed-job-executions` section in the documentation for an in-depth explanation.
    )
_scheduler_jobstore_aliasidtriggerexecutorfuncfunc_refargskwargsnamemisfire_grace_timecoalescemax_instancesnext_run_time__weakref__Nc                    s:   t t|   || _d | _| jdd|pt ji| d S )Nr    )superr   __init__r   r   _modifyr   hex)self	schedulerr   r   	__class__r   E/var/www/html/bot/env/lib/python3.10/site-packages/apscheduler/job.pyr!   -   s    zJob.__init__c                 K   s   | j j| j| jfi | | S )a-  
        Makes the given changes to this job and saves it in the associated job store.

        Accepted keyword arguments are the same as the variables on this class.

        .. seealso:: :meth:`~apscheduler.schedulers.base.BaseScheduler.modify_job`

        :return Job: this job instance

        )r   
modify_jobr   r   )r$   changesr   r   r(   modify3   s   z
Job.modifyc                 K   s    | j j| j| j|fi | | S )z
        Shortcut for switching the trigger on this job.

        .. seealso:: :meth:`~apscheduler.schedulers.base.BaseScheduler.reschedule_job`

        :return Job: this job instance

        )r   reschedule_jobr   r   )r$   r   trigger_argsr   r   r(   
rescheduleA   s   	zJob.reschedulec                 C      | j | j| j | S )z
        Temporarily suspend the execution of this job.

        .. seealso:: :meth:`~apscheduler.schedulers.base.BaseScheduler.pause_job`

        :return Job: this job instance

        )r   	pause_jobr   r   r$   r   r   r(   pauseM      	z	Job.pausec                 C   r/   )z
        Resume the schedule of this job if previously paused.

        .. seealso:: :meth:`~apscheduler.schedulers.base.BaseScheduler.resume_job`

        :return Job: this job instance

        )r   
resume_jobr   r   r1   r   r   r(   resumeY   r3   z
Job.resumec                 C   s   | j | j| j dS )z
        Unschedules this job and removes it from its associated job store.

        .. seealso:: :meth:`~apscheduler.schedulers.base.BaseScheduler.remove_job`

        N)r   
remove_jobr   r   r1   r   r   r(   removee   s   z
Job.removec                 C   s
   | j du S )z{
        Returns ``True`` if the referenced job is still waiting to be added to its designated job
        store.

        N)r   r1   r   r   r(   pendingn   s   
zJob.pendingc                 C   s>   g }| j }|r||kr|| | j||}|r||ks|S )z
        Computes the scheduled run times between ``next_run_time`` and ``now`` (inclusive).

        :type now: datetime.datetime
        :rtype: list[datetime.datetime]

        )r   appendr   get_next_fire_time)r$   now	run_timesr   r   r   r(   _get_run_times{   s   
zJob._get_run_timesc           
      K   s  i }d|v r"| d}t|tjstdt| drtd||d< d|v s.d|v s.d|v rd|v r7| dn| j}d|v rC| dn| j}d|v rO| dn| j	}t|tjr_|}t
|}nt|ruzt|}W n tyt   d}Y nw tdt| d	s|d	ddu rt||d	< t|tjst|tstd
t|tjst|tstdt||| ||d< ||d< ||d< ||d< d	|v r| d	}|rt|tjstd||d	< d|v r| d}|durt|tjr|dkrtd||d< d|v rt| d}||d< d|v r&| d}t|tjr|dkr"td||d< d|v rB| d}t|ts>td|jj ||d< d|v r[| d}t|tjsWtd||d< d|v ro| d}t|| jjd|d< |r{tdd| t|D ]\}	}t| |	| qdS )z|
        Validates the changes to the Job and makes the modifications if and only if all of them
        validate.

        r   zid must be a nonempty stringzThe job ID may not be changedr   r   r   Nz5func must be a callable or a textual reference to oner   z"args must be a non-string iterablez!kwargs must be a dict-like objectr   zname must be a nonempty stringr   r   z<misfire_grace_time must be either None or a positive integerr   r   z(max_instances must be a positive integerr   z+Expected a trigger instance, got %s insteadr   zexecutor must be a stringr   z6The following are not modifiable attributes of Job: %sz, )pop
isinstancesixstring_types	TypeErrorhasattr
ValueErrorr   r   r   r   callabler   getr
   r   r   r   integer_typesboolr   r'   __name__r   r   timezoneAttributeErrorjoin	iteritemssetattr)
r$   r*   approvedvaluer   r   r   r   r   keyr   r   r(   r"      s   














zJob._modifyc                 C   s   | j std| jf | j}t|r(t|js(t|| j kr(|jft| j }n| j}d| j	| j | j
| j|| j| j| j| j| j| jdS )NzThis Job cannot be serialized since the reference to its callable (%r) could not be determined. Consider giving a textual reference (module:function name) instead.   )versionr   r   r   r   r   r   r   r   r   r   r   )r   rD   r   r   r   __self__r   tupler   r   r   r   r   r   r   r   r   r   )r$   r   r   r   r   r(   __getstate__   s.    zJob.__getstate__c                 C   s   | dddkrtd|d  |d | _|d | _t| j| _|d | _|d | _|d | _|d	 | _	|d
 | _
|d | _|d | _|d | _|d | _d S )NrS   rR   z5Job has version %s, but only version 1 can be handledr   r   r   r   r   r   r   r   r   r   r   )rF   rD   r   r   r   r   r   r   r   r   r   r   r   r   r   )r$   stater   r   r(   __setstate__
  s    









zJob.__setstate__c                 C   s   t |tr| j|jkS tS N)r?   r   r   NotImplemented)r$   otherr   r   r(   __eq__  s   
z
Job.__eq__c                 C   s   dt | jt | jf S )Nz<Job (id=%s name=%s)>)r	   r   r   r1   r   r   r(   __repr__!  s   zJob.__repr__c                 C   s   t |  S rY   )r	   __unicode__r1   r   r   r(   __str__$  s   zJob.__str__c                 C   s:   t | dr| jrdt| j nd}nd}d| j| j|f S )Nr   znext run at: pausedr8   z%s (trigger: %s, %s))rC   r   r   r   r   )r$   statusr   r   r(   r^   '  s   
zJob.__unicode__rY   )rI   
__module____qualname____doc__	__slots__r!   r+   r.   r2   r5   r7   propertyr8   r=   r"   rV   rX   r\   r]   r_   r^   __classcell__r   r   r&   r(   r      s&    	
`r   )inspectr   r   uuidr   r@   apscheduler.triggers.baser   apscheduler.utilr   r   r   r	   r
   r   r   collections.abcr   r   ImportErrorcollectionsobjectr   r   r   r   r(   <module>   s    $