HEX
Server: LiteSpeed
System: Linux 112.webhostingindonesia.co.id 5.14.0-570.62.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 10:10:59 EST 2025 x86_64
User: iyfwylsv (10313)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/fail2ban/server/__pycache__/mytime.cpython-39.pyc
a

���7��x�@s6dZdZdZddlZddlZddlZGdd�d�ZdS)z
Cyril Jaquierz Copyright (c) 2004 Cyril Jaquier�GPL�Nc
@sReZdZdZdZdZdZedd��Zedd��Z	edd��Z
ed	d
��Zedd��Zed(d
d��Z
ed)dd��Ze�d�Ze�d�ZdZe�ed�ded�fe�ed�ded�fe�ed�ded�fe�ed�ded�fe�ed�ded�fe�ed �ded!�fe�ed"�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_|durtj�|�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.9/site-packages/fail2ban/server/mytime.py�setAlternateNow/s	�zMyTime.setAlternateNowcCs
|t_dSr)r�myTimer	rrr�setTime<s	zMyTime.setTimecCstjdurt��StjSdS)zqDecorate time.time() for the purpose of testing mocking

		@return time.time() if setTime was called with None
		N)rr�timerrrrrGs
zMyTime.timecCs"tjdurt��St�tj�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.gmtimecCs4tjdurtj��Stjtjkr&tjStj�tj�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,tjdus|durt�|�St�tj�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:|dkrtj�|�jdd�nt�dddddd�}|�|�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)�microsecondi'����;)rr�replace�strftime)ZunixTime�format�dtrrr�time2strus
����zMyTime.time2strz(?i)(?<=[a-z])(\d)z(\d)\s+(\d)z(?i)(?<=[\d\s])(%s)\bzdays?|da|dd?�*�Qzweeks?|wee?|ww?�:	zmonths?|mon?gTDAzyears?|yea?|yy?g~~Azseconds?|sec?|ss?�zminutes?|min?|mm?�<zhours?|hou?|hh?�cCsTt|tttf�r|Stj�d|�}tjD]\}}|�||�}q(tj�d|�}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)�selfr2rrr�__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)N�i�3�r!imzy �zw zd ���r"r%��zh r$i�zm i�
ih��zs z0 )r2r'�roundr(�str)r3�s�c�rrrr�__str__�sN





zMyTime.seconds2str.__str__cCs|��Sr1)rB)r3rrr�__repr__�szMyTime.seconds2str.__repr__N)�__name__�
__module__�__qualname__�__doc__r4rBrCrrrr�seconds2str�s
+rH)N)r)rDrErFrGrrr�staticmethodr
rrrrrr�re�compiler*r-Z_str2sec_subpartr>r,r0rHrrrrr!s@	









�

r)�
__author__�
__copyright__�__license__rrJrrrrrr�<module>s