https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/fail2ban/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/fail2ban/tests/__pycache__/misctestcase.cpython-310.pyc
o

;s*bVF�@sdZdZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
ddlmZddl
mZmZd	d
lmZmZmZmZmZmZmZmZmZd	dlmZGdd
�d
ej�Zejdkredd�Z ndd�Z dd�Z!Gdd�dej�Z"Gdd�de�Z#Gdd�dej�Z$dS)zYaroslav Halchenkoz%Copyright (c) 2013 Yaroslav Halchenko�GPL�N)�glob)�StringIO�)�LogCaptureTestCase�logSys�)	�formatExceptionInfo�	mbasename�	TraceBack�FormatterWithTraceBack�	getLogger�getVerbosityFormat�
splitwords�
uni_decode�
uni_string)�MyTimec@s$eZdZdd�Zdd�Zdd�ZdS)�HelpersTestcCs8ztd��t�\}}|�|d�|�|d�YdS)NzVery bad exception�
ValueError�rr	�assertEqual��self�name�args�r�=/usr/lib/python3/dist-packages/fail2ban/tests/misctestcase.py�testFormatExceptionInfoBasic+s
z(HelpersTest.testFormatExceptionInfoBasiccCs:ztdd��t�\}}|�|d�|�|d�YdS)NzVery badrz('Very bad', None)rrrrr�testFormatExceptionConvertArgs3s

z*HelpersTest.testFormatExceptionConvertArgscCs�|�td�g�|�td�g�|�td�g�|�td�dg�|�td�ddg�|�td�ddg�|�td�ddg�|�td�gd	��|�td�gd	��dS)
N�z  �1z 1 2 �2z 1, 2 , z 1
  2z	 1
  2, 3)r r!�3)rr�rrrr�testsplitwords<szHelpersTest.testsplitwordsN)�__name__�
__module__�__qualname__rrr$rrrrr)s	r�r�cCs"ddl}|j|dd�}t|���S)NrT)�shell)�
subprocess�check_outputr�rstrip��cmdr+�retrrr�_sh_callJsr1cCs,ddl}|j|d|jd�j��}t|���S)NrT)r*�stdout)r+�Popen�PIPEr2�readrr-r.rrrr1OscCstd�S)Nz?fail2ban-python -c 'import sys; print(tuple(sys.version_info))')r1rrrr�_getSysPythonVersionT�r6cs,eZdZ�fdd�Zdd�Zdd�Z�ZS)�	SetupTestcs�tt|���tj��tj�tj�	t
�ddd�}tj�|�r!|p"d|_|js1t
jdkr1t�d��t�}|ttt
j��krKt�dttt
j��|f��dS)Nz..zsetup.pyr(zLSeems to be running not out of source distribution -- cannot locate setup.pyziSeems to be running with python distribution %s -- install can be tested only with system distribution %s)�superr8�setUp�unittest�F2B�
SkipIfFast�os�path�join�dirname�__file__�exists�setup�sys�version_info�SkipTestr6�str�tuple)rrD�sysVer��	__class__rrr:Zs 
����zSetupTest.setUpc	Csr|jsdSt��}tjjtjkrdnd}zt�	dt
j|j||f�|�t�
|��Wt�|�dSt�|�w)Nz >/dev/null 2>&1rz2%s %s --dry-run install --disable-2to3 --root=%s%s)rD�tempfile�mkdtempr;r<�	log_level�logging�DEBUGr>�systemrE�
executable�
assertTrue�listdir�shutil�rmtree)r�tmp�	supdbgoutrrr�testSetupInstallDryRunjs�z SetupTest.testSetupInstallDryRunc
s"|jsdSt���tj�d�}tjjt	j
krdnd}z�|�t�dt
j|j�|f�d��fdd�}|ttd����}gd	�}t|��|�r~d
d�}i}t|��|�D]}tj��|�}	tj�|	�rk|||	d��pld||<qU|j||d
||�|fd�dD]}
|jtj�tj��|
��d|
d�q�td�d��d�}|�t|�dk�|D]}|�tj�|�tj�t
j��q�Wt���t�dt
j|j|r�|dndf�|r�tj�d�r�t�d�dSdSdSt���t�dt
j|j|r�|dndf�|�rtj�d��rt�d�www)N�buildz >/dev/nullrz(%s %s install --disable-2to3 --root=%s%srcs�fdd�|D�S)Ncs g|]}|t��dd��qS)rN)�len)�.0�x�rXrr�
<listcomp>�s zESetupTest.testSetupInstallRoot.<locals>.strippath.<locals>.<listcomp>r)�lr_rr�	strippath�sz1SetupTest.testSetupInstallRoot.<locals>.strippathz%s/*)�etc�usr�varcsFg}t�|�D]\�}}t�|||�}|��fdd�|D��q|S)Nc3s�|]
}tj��|�VqdS�N)r>r?r@)r]�f��baserr�	<genexpr>�s�zISetupTest.testSetupInstallRoot.<locals>.recursive_glob.<locals>.<genexpr>)r>�walk�fnmatch�filter�extend)�treeroot�pattern�results�dirs�files�	goodfilesrrhr�recursive_glob�s
z6SetupTest.testSetupInstallRoot.<locals>.recursive_glob�*z6Got: %s Needed: %s under %s. Files under new paths: %s��msg)zetc/fail2ban/fail2ban.confzetc/fail2ban/jail.confz
Can't find %szfind z -name fail2ban-python�
z%s %s clean --all%sz 2>&1)rDrMrNr>r?rCr;r<rOrPrQrrRrErS�sortedr�set�
differencer@rTr1�splitr\�realpathrVrW)r�remove_buildrYrb�got�needrurs�missing�missing_fullrg�
installedPathrr_r�testSetupInstallRootzsn
����
�����
��
���zSetupTest.testSetupInstallRoot)r%r&r'r:rZr��
__classcell__rrrKrr8Xsr8c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�TestsUtilsTestcCsT|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�dS)	Nz	sample.py�samplez/long/path/sample.pyz/long/path/__init__.pyz
path.__init__z/long/path/base.pyz	path.basez/long/path/base)rr
r#rrr�
testmbasename�s
zTestsUtilsTest.testmbasenamecCsl|�tttjdkrdndd�ttjdkrdnd�td�td�tjdkr2dtjvr4td�dSdSdS)N)�stest�testzf2b-test::non-existing-encodingstest�utest�PyPy)�assertRaises�	ExceptionrrErFr�versionr#rrr�testUniConverters�s��z TestsUtilsTest.testUniConverterscCs(t}Gdd�d�}|�}|�tjd|�|�dd�|��|�d|�|�dd�|�dt���|d�}|�tjd	||�|jd
ddd
�|�d||�|jdddd
�|�d�Gdd�dtj	�}|j
}z t|j
�|_
|j
|�g7_
|�tjd�|�d�W||_
n||_
w|�d�dS)Nc@seZdZddd�Zdd�ZdS)z,TestsUtilsTest.testSafeLogging.<locals>.TestrcSs
||_dSrf)�err)rr�rrr�__init__�s
z5TestsUtilsTest.testSafeLogging.<locals>.Test.__init__cSs|jrtd��dS)N�no represenation for test!u.conv-error (òðåòèé), unterminated utf Ï)r�r�r#rrr�__repr__�sz5TestsUtilsTest.testSafeLogging.<locals>.Test.__repr__N)r)r%r&r'r�r�rrrr�Test�s
r�ztest 1a: %r�	Tracebackr�ztest 1b: %rz.[phase 2] test error conversion by encoding %srztest 2a: %r, %sztest 2azError by logging handlerF��allztest 2b: %r, %sztest 2bz*[phase 3] test unexpected error in handlerc@�eZdZdd�ZdS)z5TestsUtilsTest.testSafeLogging.<locals>._ErrorHandlercSstd��)Nzerror in handler test!)r�)r�recordrrr�handle�r7z<TestsUtilsTest.testSafeLogging.<locals>._ErrorHandler.handleN)r%r&r'r�rrrr�
_ErrorHandler�sr�ztest 3aztest 3b�OK)�	DefLogSys�logrP�NOTICE�assertLogged�pruneLog�noticerE�getdefaultencoding�Handler�handlers�list)rrr�r�r��_org_handlerrrr�testSafeLogging�s0
zTestsUtilsTest.testSafeLoggingc	s�dD]B}t|d�}dd����fdd��zt�d��Wnty(|�}Ynwd|vr4|�d	|�n
d
|vr>|�d	|�|�d|�qdS)N)TF)�compresscSst��rf)rrrrr�
func_raise�sz0TestsUtilsTest.testTraceBack.<locals>.func_raisecs|r
�|d�dS��dS)Nrr)�i��
deep_functionr�rrr�s
z3TestsUtilsTest.testTraceBack.<locals>.deep_functionr�zfail2ban-testcases�>�coverage�:)r�printr�assertIn�assertNotIn)rr��tb�srr�r�
testTraceBack�s

��zTestsUtilsTest.testTraceBackcOs |jt||g|�Ri|��dSrf)�assertRaisesRegex�AssertionError)r�regexp�funr�kwargsrrr�_testAssertionErrorREs z$TestsUtilsTest._testAssertionErrorREcsrdd�}��t�jd|d���t�jd�jd���d�fdd����t�jd	td
���d�fdd��dS)
NcSst|��rf)�KeyErrorrwrrr�_key_errr7z;TestsUtilsTest.testExtendedAssertRaisesRE.<locals>._key_err�^failed$�failed�
__failed__z$failed.* does not match .*__failed__cs��d�jd�S)Nr�r�)r��failrr#rr�<lambda>'s�z;TestsUtilsTest.testExtendedAssertRaisesRE.<locals>.<lambda>rrzJ0 AssertionError not raised X.* does not match .*AssertionError not raisedcs��d�fdd��S)Nz^0 AssertionError not raised X$cs��dtd�S)Nrr)r��intrr#rrr�/szMTestsUtilsTest.testExtendedAssertRaisesRE.<locals>.<lambda>.<locals>.<lambda>)r�rr#rrr�.s
�)r�r�r�r�r�r�)rr�rr#r�testExtendedAssertRaisesREs$��
�
�
�z)TestsUtilsTest.testExtendedAssertRaisesREcs2��dgd����dd���dd���ddd�dD����dgd����dd���dd���ddd�dD����d	�jdd���d
�jdtd����d
�jddd�dD����d�jdd���d�jdtd����d�jddd�dD��t}���|�d���d��jdddd��jdddd��jdddd��jdddd����|�d���d��jdddd��jddddd�t	j
jd}t	j
_��t
t	j
�d�t����t	j
�dd���d ���t	j
�d!�d!���t	j
�d"�d"�dt	j
_z'��t	j
�d#d���d ���t	j
�d!�d$���t	j
�d"�d"�W|t	j
_n|t	j
_w��t	j
�d�����|�d���d%�jd���d&�jdd��jd'�jdddd��jd(�jdddd��jd)�jdddd*d+��jd,�jdddd��jd-�jdddd*d+��jd&�jdddd���ddd.giddd.gi���t�jddd.gidd.dgi���dd/gd/dg��jdd/ggd/dggd.d0��jdd/ggd/dggdd1���t�fd2d���jddd/gidd/dgidd1���t�fd3d���jd4d/d5gd6d7gd8�gd7d6gd5d/gd9�d4gdd1��jd4d/d5gd6d7gd8�gd7d6gd5d/gd9�d4gd:d0���t�fd;d����d<d=gd>d=gggfd<d=gd=d>gggf���td?�td@����t�jd?gd@g���t�jd?ggd@gg���dA�jdgd5d/g���dB�jdd/gd5d/g�dS)CN�a)r��b�c�d�cbacss�|]	}|dkr|VqdS�r�Nr�r]r�rrrrj7s�z;TestsUtilsTest.testExtendedAssertMethods.<locals>.<genexpr>)r�r�r��cbdcs� �|]}|dkr|��VqdSr���upperr�rrrrj;��z'a' unexpectedly found in 'cba'z#1 unexpectedly found in \[0, 1, 2\]rr�z&'A' unexpectedly found in \['C', 'A'\]�Acsr�r�r�r�rrrrjBr�z'a' was not found in 'xyz'�xyzz5 was not found in \[0, 1, 2\]�z!'A' was not found in \['C', 'B'\]csr�)r�Nr�r�rrrrjHr�z
test "xyz"r�Tr��zyxF�test_zyxz
xxxx "xxx"cS�dS�N�2rrrrrr�Z�z:TestsUtilsTest.testExtendedAssertMethods.<locals>.<lambda>r��g9@cSr�r�rrrrrr�_r�g@z.* was found in the logz+All of the .* were found present in the logzwas found in the logzwas not found in the logz&was not found in the log, waited 1e-06g���ư>)r��waitz"None among .* was found in the logz0None among .* was found in the log, waited 1e-06r�B)�level��
nestedOnlycs�jddggddggddd�S�Nr�r�rT)r�r���assertSortedEqualrr#rrr��s�cs"�jdddgidddgiddd�Sr�r�rr#rrr��s��Z�C�E�F�r�r��r�r����cs4�jdddgddgd�gddgddgd�dgdd	�S)
Nr�r�r�r�r�r�r�Tr�r�rr#rrr��s(�r�A1�A2�ABC�CBAz\['A'\] != \['C', 'B'\]z\['A', 'B'\] != \['B', 'C'\])r�r�r��ranger�r��debugr��assertNotLoggedr;r<�fast�assertFalse�
isinstance�maxWaitTime�boolr�assertDictEqualr�r�r�r�)rr�orgfastrr#r�testExtendedAssertMethods2s�������




��
�
��
��
�
� ,�,����z(TestsUtilsTest.testExtendedAssertMethodscCs>|�td�d�|�tddd�d�|�tdddd�d�dS)NrzA%(asctime)s %(name)-24s[%(process)d]: %(levelname)-7s %(message)sF)�paddingz<%(asctime)s %(name)s[%(process)d]: %(levelname)s %(message)s)�addtimer�z0%(name)s[%(process)d]: %(levelname)s %(message)s)rrr#rrr�testVerbosityFormat�s
���z"TestsUtilsTest.testVerbosityFormatcCs�t�}t}d}td�}t�|�}|�||��|�|�|�d�|��}|�	|�
��d��|�d�}|�	|dk�|�
|d|�||d|dd��dS)	Nz %(tb)s | %(tbc)s : %(message)s�fail2ban_tests�XXXz: XXX�|�
rr)rrr
rP�
StreamHandler�setFormatter�
addHandler�error�getvaluerTr-�endswith�indexr)r�strout�	Formatter�fmtr�outr��pindexrrr�testFormatterWithTraceBack�s



,z)TestsUtilsTest.testFormatterWithTraceBackcCs2t}|�dtjj�|�dddd�|�d�dS)Nzlazy logging: %rr�rrr�znot all arguments converted)r�r�r;r<�log_lazyr�r�)rrrrr�testLazyLogging�szTestsUtilsTest.testLazyLoggingN)
r%r&r'r�r�r�r�r�r�r�r�rrrrrrr��s	* fr�c@r�)�
MyTimeTestcCs�tj}|�|d�d�|�|d�d�|�|d�d�|�|d�d�|�|d�d	�|�|d
�d	�|�|d�d�|�t|d
��dddd�|�t|d��dddd�dS)N�1y6mo30w15d12h35m25si]��z2yy 3mo 4ww 10dd 5hh 30mm 20ssi$�mz>2 years 3 months 4 weeks 10 days 5 hours 30 minutes 20 secondsz!1 year + 1 month - 1 week + 1 dayi��zI2 * 0.5 yea + 1*1 mon - 3*1/3 wee + 2/2 day - (2*12 hou 3*20 min 80 sec) g@��Az(2*.5y+1*1mo-3*1/3w+2/2d-(2*12h3*20m80s) z!1ye -2mo -3we -4da -5ho -6mi -7seiQ	pz1 month�<�gp>@z1 yearg�v@)r�str2secondsr�float)r�str2secrrr�testStr2Seconds�s $zMyTimeTest.testStr2SecondsN)r%r&r'rrrrrr�sr)%�
__author__�
__copyright__�__license__rPr>rEr;rMrVrlr�ior�utilsrrr��helpersr	r
rrr
rrrr�
server.mytimer�TestCaserrFr1r6r8r�rrrrr�<module>s2,
 
d

https://t.me/RX1948 - 2025