
    =*f                     <    S r SrSrSSKrSSKrSSKr " S S5      rg)zCyril Jaquierz Copyright (c) 2004 Cyril JaquierGPL    Nc                      \ rS rSrSrSrSrSr\S 5       r	\S 5       r
\S 5       r\S 5       r\S 5       r\S!S	 j5       r\S"S
 j5       r\R"                  " S5      r\R"                  " S5      rSr\R"                  " \S-  5      S\" S5      -   4\R"                  " \S-  5      S\" S5      -   4\R"                  " \S-  5      S\" S5      -   4\R"                  " \S-  5      S\" S5      -   4\R"                  " \S-  5      S\" S5      -   4\R"                  " \S-  5      S\" S5      -   4\R"                  " \S-  5      S\" S5      -   44r\S 5       r " S S5      rS rg)#MyTime!   aZ  A wrapper around time module primarily for testing purposes

This class is a wrapper around time.time()  and time.gmtime(). When
performing unit test, it is very useful to get a fixed value from
these functions.  Thus, time.time() and time.gmtime() should never
be called directly.  This wrapper should be called instead. The API
are equivalent.
Nc                     U [         l        U b)  [        R                  R                  U 5      [         l        gS[         l        gzlSet current time.

Use None in order to always get the real current time.

@param t the time to set or None
N)r   alternateNowTimedatetimefromtimestampalternateNowts    8/usr/lib/python3/dist-packages/fail2ban/server/mytime.pysetAlternateNowMyTime.setAlternateNow/   s7     &)*8""1% 	<@ 	    c                     U [         l        gr   )r   myTimer   s    r   setTimeMyTime.setTime<   s     &-r   c                  n    [         R                  c  [        R                  " 5       $ [         R                  $ )zmDecorate time.time() for the purpose of testing mocking

@return time.time() if setTime was called with None
)r   r   time r   r   r   MyTime.timeG   s$     ]]
))+
--r   c                      [         R                  c  [        R                  " 5       $ [        R                  " [         R                  5      $ )zqDecorate time.gmtime() for the purpose of testing mocking

@return time.gmtime() if setTime was called with None
)r   r   r   gmtimer   r   r   r   MyTime.gmtimeS   s-     ]]
++-
++fmm
$$r   c                     [         R                  c  [        R                  R                  5       $ [         R                  [         R                  :X  a  [         R
                  $ [        R                  R                  [         R                  5      $ )zsDecorate datetime.now() for the purpose of testing mocking

@return datetime.now() if setTime was called with None
)r   r   r
   nowr	   r   r   r   r   r   r   
MyTime.now^   s\     ]]





!!]]f---


				(	(	77r   c                     [         R                  b  U b  [        R                  " U 5      $ [        R                  " [         R                  5      $ )zwDecorate time.localtime() for the purpose of testing mocking

@return time.localtime() if setTime was called with None
)r   r   r   	localtime)xs    r   r"   MyTime.localtimej   s4     ]]am
..

..
''r   c                     U S:  a,  [         R                   R                  U 5      R                  SS9O[         R                   " SSSSSS5      nUR                  U5      $ )	zConvert time to a string representing as date and time using given format.
Default format is ISO 8601, YYYY-MM-DD HH:MM:SS without microseconds.

@return ISO-capable string representation of given unixTime
l    p r   )microsecondi'           ;   )r
   r   replacestrftime)unixTimeformatdts      r   time2strMyTime.time2stru   sa     , &&WW $,$5$5dBBB$O  
V	r   z(?i)(?<=[a-z])(\d)z(\d)\s+(\d)z(?i)(?<=[\d\s])(%s)\bzdays?|da|dd?*Q zweeks?|wee?|ww?:	 zmonths?|mon?g    TDAzyears?|yea?|yy?g    ~~Azseconds?|sec?|ss?   zminutes?|min?|mm?<   zhours?|hou?|hh?  c                 0   [        U [        [        [        45      (       a  U $ [        R
                  R                  SU 5      n [        R                   H  u  pUR                  X 5      n M     [        R                  R                  SU 5      n [        U 5      $ )a  Wraps string expression like "1h 2m 3s" into number contains seconds (3723).
The string expression will be evaluated as mathematical expression, spaces between each groups 
  will be wrapped to "+" operand (only if any operand does not specified between).
Because of case insensitivity and overwriting with minutes ("m" or "mm"), the short replacement for month
  are "mo" or "mon".
Ex: 1hour+30min = 5400
    0d 1h 30m   = 5400
    1year-6mo   = 15778800
    6 months    = 15778800
warn: month is not 30 days, it is a year in seconds / 12, the leap years will be respected also:
      >>>> float(str2seconds("1month")) / 60 / 60 / 24
      30.4375
      >>>> float(str2seconds("1year")) / 60 / 60 / 24
      365.25    

@returns number (calculated seconds from expression "val")
z \1z\1+\2)

isinstanceintfloatcomplexr   _str2sec_prepsub_str2sec_parts_str2sec_finieval)valrexprpls      r   str2secondsMyTime.str2seconds   sw    & c5'*++
:  -#((id	#	3 )  3/#	cr   c                   *    \ rS rSrSrS rS rS rSrg)MyTime.seconds2str   a  Converts seconds to string on demand (if string representation needed).
Ex: seconds2str(86400*390)            = 1y 3w 4d
    seconds2str(86400*368)            = 1y 3d
    seconds2str(86400*365.5)          = 1y
    seconds2str(86400*2+3600*7+60*15) = 2d 7h 15m
    seconds2str(86400*2+3599)         = 2d 1h
    seconds2str(3600-5)               = 1h
    seconds2str(3600-10)              = 59m 50s
    seconds2str(59)                   = 59s
c                     Xl         g Nsec)selfrM   s     r   __init__MyTime.seconds2str.__init__   s    8r   c                 @   U R                   nSnUS:  ap  [        [        [        U5      S-  5      5      n[	        US-  5      S-   o1S-  nUS:  a  U[	        US-  5      S-   -  o1S-  nU(       a  U[	        U5      S-   -  nUS S	 $ US
:  ap  [        [        [        U5      S-  5      5      n[	        US-  5      S-   o1S-  nUS:  a  U[	        US-  5      S-   -  o1S-  nU(       a  U[	        U5      S-   -  nUS S	 $ US:  ap  [        [        [        U5      S-  5      5      n[	        US-  5      S-   o1S-  nUS:  a  U[	        US-  5      S-   -  o1S-  nU(       a  U[	        U5      S-   -  nUS S	 $ US:  aX  [        [        [        U5      S-  5      5      n[	        US-  5      S-   o1S-  nUS:  a  U[	        US-  5      S-   -  o1S-  nUS S	 $ SnUS:  a  U[	        US-  5      S-   -  o1S-  nU(       a  U[	        U5      S-   -  nOU R                   (       d  SnUS S	 $ )N   i3r3   im  zy    zw zd r4   r7         zh r6   i  zm i  
   ih      zs z0 )rM   r:   roundr;   str)rN   scrs       r   __str__MyTime.seconds2str.__str__   s9    xx1Q8mE%(5.!"AAsFdAHAAv#ad)d
QFA#a&4-QSb6M6kE%(4- !AAsFdAHABw#ae*t
Q"WQ#a&4-QSb6M5jE%(2+AAtGtA$YQBw#ae*t
Q"WQ#a&4-QSb6M4iE%(2+AAsFdAHAAv#ad)d
QFASb6M	12gQUd	AGAQ$AHHA
CR&=r   c                 "    U R                  5       $ rK   )r_   )rN   s    r   __repr__MyTime.seconds2str.__repr__   s    
,,.r   rL   N)	__name__
__module____qualname____firstlineno____doc__rO   r_   rb   __static_attributes__r   r   r   seconds2strrH      s    	*Vr   rj   r   rK   )z%Y-%m-%d %H:%M:%S)rd   re   rf   rg   rh   r   r	   r   staticmethodr   r   r   r   r   r"   r0   recompiler=   r@   _str2sec_subpartr[   r?   rE   rj   ri   r   r   r   r   r   !   s    
A 
A   	 	 % % 	8 	8 ( ( 
 
 12N+, ::01CM8IJ::!334C
O8KL::01C@Y<Z8Z[::!334C@V<W8WX::!556CF
C::!556CGD::!334CJG  89 9r   r   )
__author____copyright____license__r
   rl   r   r   r   r   r   <module>rr      s+   ( 
2  	 J Jr   