HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/tempora/__pycache__/schedule.cpython-310.pyc
o

�N�g��@s�dZddlZddlZddlZddlZddlZdd�Zdd�ZGdd�dej�ZGd	d
�d
e�Z	Gdd�de	�Z
Gd
d�d�ZGdd�de�ZGdd�de�Z
dS)a�
Classes for calling functions a schedule. Has time zone support.

For example, to run a job at 08:00 every morning in 'Asia/Calcutta':

>>> job = lambda: print("time is now", datetime.datetime())
>>> time = datetime.time(8, tzinfo=pytz.timezone('Asia/Calcutta'))
>>> cmd = PeriodicCommandFixedDelay.daily_at(time, job)
>>> sched = InvokeScheduler()
>>> sched.add(cmd)
>>> while True:  # doctest: +SKIP
...     sched.run_pending()
...     time.sleep(.1)
�NcCstj��jtjd�S)u�
    Provide the current timezone-aware datetime.

    A client may override this function to change the default behavior,
    such as to use local time or timezone-naïve times.
    ��tzinfo)�datetime�utcnow�replace�pytz�utc�r	r	�D/opt/saltstack/salt/lib/python3.10/site-packages/tempora/schedule.py�nowsrcCstj�|�jtjd�S)u�
    Convert a numeric timestamp to a timezone-aware datetime.

    A client may override this function to change the default behavior,
    such as to use local time or timezone-naïve times.
    r)r�utcfromtimestamprrr)�tsr	r	r
�from_timestamp"src@sHeZdZdZedd��Zedd��Zedd��Zedd	��Z	d
d�Z
dS)
�DelayedCommandzK
    A command to be executed after some delay (seconds or timedelta).
    c	Cs&||j|j|j|j|j|j|j|j�S�N)�year�month�day�hour�minute�second�microsecondr)�cls�otherr	r	r
�
from_datetime1s�zDelayedCommand.from_datetimecCs<t|tj�stj|d�}t�|}|�|�}||_||_|S)N��seconds)�
isinstancer�	timedeltarr�delay�target)rrr Zdue_time�cmdr	r	r
�after>s

zDelayedCommand.aftercCst|tj�s|St|�S)z�
        If input is a real number, interpret it as a Unix timestamp
        (seconds sinc Epoch in UTC) and return a timezone-aware
        datetime object. Otherwise return input unchanged.
        )r�numbersZRealr)�inputr	r	r
�_from_timestampHszDelayedCommand._from_timestampcCs*|�|�}|�|�}|t�|_||_|S)zt
        Construct a DelayedCommand to come due at `at`, where `at` may be
        a datetime or timestamp.
        )r%rrrr )r�atr r!r	r	r
�at_timeSs


zDelayedCommand.at_timecCs
t�|kSr)r��selfr	r	r
�due_�
zDelayedCommand.dueN)�__name__�
__module__�__qualname__�__doc__�classmethodrr"�staticmethodr%r'r*r	r	r	r
r,s

	


rcs<eZdZdZdd�Zedd��Zdd�Z�fdd	�Z�Z	S)
�PeriodicCommandzY
    Like a delayed command, but expect this command to run every delay
    seconds.
    cCs|�||j�S)z.
        Add delay to self, localized
        )�	_localizerr(r	r	r
�
_next_timeiszPeriodicCommand._next_timecCs2z
|j}|�|jdd��WSty|YSw)zH
        Rely on pytz.localize to ensure new result honors DST.
        Nr)r�localizer�AttributeError)�dt�tzr	r	r
r3os�zPeriodicCommand._localizecCs$|j�|���}|j|_|j|_|Sr)�	__class__rr4rr )r)r!r	r	r
�nextzszPeriodicCommand.nextcs2|dkr|t��kstd��tt|��||�dS)Nrz7A PeriodicCommand must have a positive, non-zero delay.)rr�
ValueError�superr2�__setattr__)r)�key�value�r9r	r
r=�s
�zPeriodicCommand.__setattr__)
r,r-r.r/r4r1r3r:r=�
__classcell__r	r	r@r
r2cs

r2c@s(eZdZdZedd��Zedd��ZdS)�PeriodicCommandFixedDelayz�
    Like a periodic command, but don't calculate the delay based on
    the current time. Instead use a fixed delay following the initial
    run.
    cCs<|�|�}|�|�}t|tj�rtj|d�}||_||_|S)z}
        >>> cmd = PeriodicCommandFixedDelay.at_time(0, 30, None)
        >>> cmd.delay.total_seconds()
        30.0
        r)	r%rrr#�Numberrrrr )rr&rr r!r	r	r
r'�s

z!PeriodicCommandFixedDelay.at_timecCsXtjdd�}tj�tj��|�}||8}|t�kr"||7}|t�ks|�|�|�||�S)a
        Schedule a command to run at a specific time each day.

        >>> from tempora import utc
        >>> noon = utc.time(12, 0)
        >>> cmd = PeriodicCommandFixedDelay.daily_at(noon, None)
        >>> cmd.delay.total_seconds()
        86400.0
        �)�days)rr�combine�date�todayrr'r3)rr&r ZdailyZwhenr	r	r
�daily_at�s

�z"PeriodicCommandFixedDelay.daily_atN)r,r-r.r/r0r'rIr	r	r	r
rB�s
rBc@s6eZdZdZdd�Zdd�Zdd�Zejdd	��Z	d
S)�	Schedulerzj
    A rudimentary abstract scheduler accepting DelayedCommands
    and dispatching them on schedule.
    cCs
g|_dSr)�queuer(r	r	r
�__init__�r+zScheduler.__init__cCs t|t�sJ�t�|j|�dSr)rr�bisect�insortrK�r)Zcommandr	r	r
�add�sz
Scheduler.addcCsT|jr(|jd}|��sdS|�|�t|t�r|�|���|jd=|jsdSdS)Nr)rKr*�runrr2rPr:rOr	r	r
�run_pending�s


�zScheduler.run_pendingcCsdS)z!
        Run the command
        Nr	rOr	r	r
rQ�sz
Scheduler.runN)
r,r-r.r/rLrPrR�abc�abstractmethodrQr	r	r	r
rJ�s
rJc@seZdZdZdd�ZdS)�InvokeSchedulerzB
    Command targets are functions to be invoked on schedule.
    cCs|��dSr)r rOr	r	r
rQ�szInvokeScheduler.runN)r,r-r.r/rQr	r	r	r
rU�srUcs(eZdZdZ�fdd�Zdd�Z�ZS)�CallbackSchedulerzH
    Command targets are passed to a dispatch callable on schedule.
    cst���||_dSr)r<rL�dispatch)r)rWr@r	r
rL�s

zCallbackScheduler.__init__cCs|�|j�dSr)rWr rOr	r	r
rQ�szCallbackScheduler.run)r,r-r.r/rLrQrAr	r	r@r
rV�srV)r/rr#rSrMrrrrr2rBrJrUrVr	r	r	r
�<module>s

7%*