HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/lib/python3.6/site-packages/fail2ban/server/__pycache__/mytime.cpython-36.pyc
3

UB(d��@s6dZdZdZddlZddlZddlZGdd�d�ZdS)z
Cyril Jaquierz Copyright (c) 2004 Cyril JaquierZGPL�Nc@sReZdZdZdZdZdZedd��Zedd��Z	edd��Z
ed	d
��Zedd��Zed*d
d��Z
ed+dd��Zejd�Zejd�ZdZejed�ded-�fejed�ded0�fejed�ded7�fejed!�ded=�fejed"�ded#�fejed$�ded�fejed%�ded>�ffZed&d'��ZGd(d)�d)�ZdS)?�MyTimea`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.
	NcCs$|t_|dk	rtjj|�ndt_dS)zrSet 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)�t�r�/usr/lib/python3.6/mytime.py�setAlternateNow/s	zMyTime.setAlternateNowcCs
|t_dS)zrSet current time.

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

		@param t the time to set or None
		N)r�myTime)rrrr	�setTime<s	zMyTime.setTimecCstjdkrtj�StjSdS)zqDecorate time.time() for the purpose of testing mocking

		@return time.time() if setTime was called with None
		N)rr�timerrrr	r
Gs
zMyTime.timecCs"tjdkrtj�Stjtj�SdS)zuDecorate time.gmtime() for the purpose of testing mocking

		@return time.gmtime() if setTime was called with None
		N)rrr
�gmtimerrrr	rSs
z
MyTime.gmtimecCs4tjdkrtjj�Stjtjkr&tjStjjtj�S)zwDecorate datetime.now() for the purpose of testing mocking

		@return datetime.now() if setTime was called with None
		N)rrr�nowrrrrrrr	r^s


z
MyTime.nowcCs,tjdks|dk	rtj|�Stjtj�SdS)z{Decorate time.localtime() for the purpose of testing mocking

		@return time.localtime() if setTime was called with None
		N)rrr
�	localtime)�xrrr	rjs
zMyTime.localtime�%Y-%m-%d %H:%M:%ScCs:|dkrtjj|�jdd�ntjdddddd�}|j|�S)	z�Convert 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
		lp��r)Zmicrosecondi'����;)rr�replaceZstrftime)ZunixTime�formatZdtrrr	�time2strus
0zMyTime.time2strz(?i)(?<=[a-z])(\d)z(\d)\s+(\d)z(?i)(?<=[\d\s])(%s)\bzdays?|da|dd?�*��<zweeks?|wee?|ww?�zmonths?|mon?im�in�rzyears?|yea?|yy?zseconds?|sec?|ss?�zminutes?|min?|mm?zhours?|hou?|hh?cCsXt|tttf�r|Stjjd|�}xtjD]\}}|j||�}q*Wtjjd|�}t	|�S)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)�valZrexpZrplrrr	�str2seconds�szMyTime.str2secondsc@s(eZdZdZdd�Zdd�Zdd�ZdS)	zMyTime.seconds2stra�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
		cCs
||_dS)N)�sec)�selfr,rrr	�__init__�szMyTime.seconds2str.__init__cCs:|j}d}|dkr�ttt|�d��}t|d�d}|d;}|dkrb|t|d�d7}|d;}|rv|t|�d7}|dd�S|d
kr�ttt|�d��}t|d�d}|d;}|d
kr�|t|d
�d7}|d
;}|r�|t|�d7}|dd�S|dk�rxttt|�d��}t|d�d}|d;}|dk�rV|t|d�d7}|d;}|�rl|t|�d7}|dd�S|dk�r�ttt|�d��}t|d�d}|d;}|dk�r�|t|d�d7}|d;}|dd�Sd}|dk�r
|t|d�d7}|d;}|�r"|t|�d7}n|j�s.d}|dd�S)Nri�3�i�Qimzy rzw zd r i�:	i�rzh ri�zm i�
ih��zs z0 ���r3r3r3r3)r,r"�roundr#�str)r-�s�c�rrrr	�__str__�sb




zMyTime.seconds2str.__str__cCs|j�S)N)r9)r-rrr	�__repr__�szMyTime.seconds2str.__repr__N)�__name__�
__module__�__qualname__�__doc__r.r9r:rrrr	�seconds2str�s
+r?)N)ri�i�Qr/i`'i�:	iGi�i��i  i��g~~AgTDAiGi�i��i  i��g~~Ai)r;r<r=r>rrr�staticmethodr
rr
rrrr�re�compiler%r(Z_str2sec_subpartr5r'r+r?rrrr	r!s2



r)�
__author__Z
__copyright__Z__license__rrAr
rrrrr	�<module>s