
    k7ih                     j   S SK r S SKJr  S SKJrJrJr  S SKJr  S SKJ	r	J
r
Jr  S SKJr  S SKJr  S\S	\4S
 jrS	\4S jrS	\4S jrS\S	\4S jrS\S	\4S jrS\	S	\S-  4S jr\S\
S	\4S j5       r\S\
S-  S	\S-  4S j5       rS\
S-  S	\S-  4S jrS\\
S-     \
-  S-  S\S	\\S-     4S jrg)    N)Sequence)datetime	timedeltatimezone)Real)AnySupportsFloatoverload)InvalidTTLError)IncorrectTTLCountErrorepochreturnc                 H    [         R                  " U [        R                  S9$ )z0Convert an epoch timestamp to a datetime object.tz)r   fromtimestampr   utc)r   s    ]/home/james-whalen/.local/lib/python3.13/site-packages/key_value/shared/utils/time_to_live.pyepoch_to_datetimer      s    !!%HLL99    c                  ,    [         R                   " 5       $ )z&Get the current time as epoch seconds.)time r   r   now_as_epochr      s    99;r   c                  F    [         R                  " [        R                  S9$ )z*Get the current time as a datetime object.r   )r   nowr   r   r   r   r   r   r      s    <<8<<((r   r   c                 8    U [        5       -
  R                  5       $ )zIGet the number of seconds between the current time and a datetime object.)r   total_seconds)r   s    r   
seconds_tor      s    su++--r   secondsc                 Z    [         R                  " [        R                  S9[	        U S9-   $ )zCGet the current time plus a number of seconds as a datetime object.r   r    )r   r   r   r   r   r"   s    r   now_plusr#      s    <<8<<(9W+EEEr   valuec                 ~     [        U [        5      (       a  [        R                  " U 5      $  g ! [         a     g f = fN)
isinstancestrr   fromisoformat
ValueError)r$   s    r   try_parse_datetime_strr+   $   sC    eS!!))%00 "
   s   */ 
<<tc                     g r&   r   r,   s    r   prepare_ttlr/   .   s    ,/r   c                     g r&   r   r.   s    r   r/   r/   2   s    :=r   c                     U c  g[        U [        [        -  5      (       a  [        U [        5      (       a  [	        U S[        U 5      R                  0S9e[        U 5      nUS::  a	  [	        U S9eU$ )a  Prepare a TTL for use in a put operation.

If a TTL is provided, it will be validated and returned as a float.
If a None is provided, None will be returned.

If the provided TTL is not a float or float-adjacent type, an InvalidTTLError will be raised. In addition,
if a bool is provided, an InvalidTTLError will be raised. If the user passes TTL=True, true becomes `1` and the
entry immediately expires which is likely not what the user intended.
Ntypettl
extra_infor   )r4   )r'   r   r	   boolr   r2   __name__float)r,   r4   s     r   r/   r/   6   sh     	y a-..*Q2E2E!a9I9I0JKK
(C
ax!$$Jr   countc                 <   / nU c  S/U-  nU$ [        U [        5      (       ag  [        U [        5      (       a  [        U S[	        U 5      R
                  0S9e[        U 5      U:w  a	  [        XS9eU  Vs/ s H  n[        US9PM     nnU$ [        U S9/U-  nU$ s  snf )zPrepare a list of TTLs for use in a put_many operation.

If a single TTL (or None) is provided, it will be repeated `count` times.

If multiple TTLs are provided, they will be validated, including that the number of TTLs is equal to `count`.Nr2   r3   )r4   r9   r.   )	r'   r   r(   r   r2   r7   lenr   r/   )r,   r9   validated_ttlsr4   s       r   prepare_ttlsr=   O   s     *,Ny%" ! 
Ax	 	 a "aVT!W=M=M4NOO q6U?(Q<< 9::+,:
  &*+e3 ;s   3B)r   collections.abcr   r   r   r   numbersr   typingr   r	   r
   key_value.shared.errorsr   !key_value.shared.errors.key_valuer   r8   r   r   r   r   r#   r+   r/   intlistr=   r   r   r   <module>rE      s     $ 2 2  / / 3 D:U :x :
e 
)X )
. .e .
Fe F F
# (T/  
 /= /U / 
 / 
 ==4' =EDL = 
 ==4' EDL 2H]T12]BTI RU Z^_dgk_kZl r   