Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_peepholer.cpython-38.opt-1.pyc
U

>��g�M�@sZddlZddlZddlmZdd�ZGdd�de�ZGdd�dej�Zed	krVe�	�dS)
�N)�BytecodeTestCasecCs^d}t�|�D]}|j|kr|d7}qt|d�r6|j}|jD]}t|d�r<|t||�7}q<|S)Nr��__code__�co_code)�dis�get_instructions�opname�hasattrr�	co_consts�count_instr_recursively)�fr�count�instr�c�r�2/opt/cppython/lib/python3.8/test/test_peepholer.pyrs




rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7S)8�
TestTranformsc
Cs�tt�|��}dd�|D�}|D]�}d|jkr0q ||j}|jdkrl|�|j�d|j�d|j�d|j���|jdkr�|jdkr�|�|j�d|j�d|j�d|j���d|jkr d	|jkr |�|j�d|j�d|j�d|j���q dS)
NcSsi|]}|j|�qSr)�offset��.0rrrr�
<dictcomp>sz4TestTranforms.check_jump_targets.<locals>.<dictcomp>ZJUMP_)�
JUMP_ABSOLUTE�JUMP_FORWARDz at z
 jumps to �RETURN_VALUEZ_OR_POPZJUMP_IF_)�listrrrZargvalZfailr)�self�codeZinstructionsZtargetsrZtgtrrr�check_jump_targetss


(
�(z TestTranforms.check_jump_targetscCs^t�|�}tt�|��}tdd�|D��}tdd�|D��}|�|d�|�|t|j	��dS)z0Check that the lnotab byte offsets are sensible.css|]}|dVqdS�rNr�r�trrr�	<genexpr>1sz-TestTranforms.check_lnotab.<locals>.<genexpr>css|]}|dVqdSrrrrrrr!2srN)
rZ_get_code_objectrZfindlinestarts�min�maxZassertGreaterEqualZ
assertLess�lenr)rrZlnotabZmin_bytecodeZmax_bytecoderrr�check_lnotab+s
zTestTranforms.check_lnotabcCs:dd�}|�|d�|�|d�|�|d�|�|�dS)NcSs|dks
~dS)N�r��xrrr�unot;sz%TestTranforms.test_unot.<locals>.unotZ	UNARY_NOT�POP_JUMP_IF_FALSE�POP_JUMP_IF_TRUE��assertNotInBytecode�assertInBytecoder%)rr)rrr�	test_unot9s
zTestTranforms.test_unotcCs6dD],\}}t|dd�}|�|d|�|�|�qdS)N))z
not a is bzis not)z
not a in bznot in)znot a is not b�is)znot a not in b�in��singleZ
COMPARE_OP)�compiler.r%)r�lineZcmp_oprrrr�test_elim_inversion_of_is_or_inCsz-TestTranforms.test_elim_inversion_of_is_or_incCs�dd�}dd�}dd�}|df|df|dffD],\}}|�|d	�|�|d
|�|�|�q.dd�}|�|d	�|�|d
d�|�|�dS)NcSsd}d}|S�Nrr'rrrrPsz0TestTranforms.test_global_as_constant.<locals>.fcSsd}|S)NTrr'rrr�gTsz0TestTranforms.test_global_as_constant.<locals>.gcSsd}|S)NFrr'rrr�hWsz0TestTranforms.test_global_as_constant.<locals>.hTFZLOAD_GLOBAL�
LOAD_CONSTcSsdS)z1Adding a docstring made this test fail in Py2.5.0Nrrrrrr`sr,)rrr8r9�func�elemrrr�test_global_as_constantNsz%TestTranforms.test_global_as_constantcCsBdd�}dD]}|�||�qdD]}|�||�q"|�|�dS)NcSsqtSr7)rrrrrrjsz'TestTranforms.test_while_one.<locals>.f)r:r*�rr,)rrr<rrr�test_while_onehszTestTranforms.test_while_onecCsLdD]B\}}t|dd�}|�||�|�|d�|�|d�|�|�qdS)N))za, = a,r:)za, b = a, bZROT_TWO)za, b, c = a, b, cZ	ROT_THREEr2r3�BUILD_TUPLEZUNPACK_TUPLE�r4r.r-r%�rr5r<rrrr�test_pack_unpacktszTestTranforms.test_pack_unpackcCs�dD]8\}}t|dd�}|�|d|�|�|d�|�|�qttttd���dd�}|�|d�dd�t�|�D�}|�	t
|�d	�|�|�d
d�}|�|�dS)N))z	a = 1,2,3�rr&�)z
("a","b","c")��a�br)z
a,b,c = 1,2,3rD)z(None, 1, None)�NrN)z((1, 2), 3, 4)��rr&rE�r2r3r:r@�'cSsg|]}|jdkr|�qS)r:�rrrrr�
<listcomp>�s
�zETestTranforms.test_folding_of_tuples_of_constants.<locals>.<listcomp>r&cdSs�ddddddddd	d
ddddddddd	d
ddddddddd	d
ddddddddd	d
ddddddddd	d
ddddddddd	d
ddddddddd	d
ddddddddd	d
ddddddddd	d
ddddddddd	d
gdfdS)Nrrr&rErL�����	rrrrr�crater�s��zATestTranforms.test_folding_of_tuples_of_constants.<locals>.crater)r4r.r-r%�repr�tuple�rangerr�assertEqualr$)rr5r<rZload_constsrUrrr�#test_folding_of_tuples_of_constants�s

z1TestTranforms.test_folding_of_tuples_of_constantscCsBdD]8\}}t|dd�}|�|d|�|�|d�|�|�qdS)N))za in [1,2,3]rD)za not in ["a","b","c"]rF)za in [None, 1, None]rI)za not in [(1, 2), 3, 4]rJr2r3r:�
BUILD_LISTrArBrrr�"test_folding_of_lists_of_constants�s
z0TestTranforms.test_folding_of_lists_of_constantsc	Cs�dtdddh�fdtdddh�fd	tddh�fd
tdddh�fd
tdddh�ffD]8\}}t|dd�}|�|d�|�|d|�|�|�qRdd�}dd�}|�|d��|�|d��|�|�|�|d��|�|d��|�|�dS)Nza in {1,2,3}rr&rEza not in {"a","b","c"}rGrrHza in {None, 1, None}za not in {(1, 2), 3, 4}rKrLza in {1, 2, 3, 3, 2, 1}r2r3Z	BUILD_SETr:cSs|dkS�N>rr&rEr�rGrrrr�sz:TestTranforms.test_folding_of_sets_of_constants.<locals>.fcSs|dkSr]rr^rrrr8�sz:TestTranforms.test_folding_of_sets_of_constants.<locals>.g)�	frozensetr4r-r.r%�
assertTrue)rr5r<rrr8rrr�!test_folding_of_sets_of_constants�s$�
z/TestTranforms.test_folding_of_sets_of_constantscCs,dD]N\}}t|dd�}|�|d|�t�|�D]}|�|j�d��q0|�|�qtddd�}|�|dd�|�|dd�|�|�td	dd�}|�|dd
�|�dd
|j	�|�|�tddd�}|�|dd
�|�dd
>|j	�|�|�tddd�}|�|dd
�|�dd
|j	�|�|�dS)N))z	a = 2+3+4rT)z"@"*4z@@@@)za="abc" + "def"Zabcdef)za = 3**4�Q)za = 3*4�)z	a = 13//4rE)za = 14%4r&)za = 2+3rP)za = 13-4rT)za = (12,13)[1]�
)za = 13 << 2�4)za = 13 >> 2rE)z
a = 13 & 7rP)z
a = 13 ^ 7�
)z
a = 13 | 7�r2r3r:�BINARY_za=2+"b"r&rHza="x"*10000rMr(z	a=1<<1000i�rz	a=2**1000)
r4r.rr�assertFalser�
startswithr%ZassertNotInr
)rr5r<rrrrr�#test_folding_of_binops_on_constants�s,


z1TestTranforms.test_folding_of_binops_on_constantscCs�tddd�}|�|dd�|�|d�|�|�tddd�}|�|dd�|�|d�|�|�td	dd�}|�|dd
�|�|d�|�|�tddd�}|�|d�|�|�dS)Nz"foo"[0]r2r3r:rZ
BINARY_SUBSCRu	"a￿"[1]u￿u	"𒍅"[0]u𒍅z	"fuu"[10]rA)rrrrr�test_binary_subscr_on_unicode�s


z+TestTranforms.test_binary_subscr_on_unicodecCs�dD]N\}}t|dd�}|�|d|�t�|�D]}|�|j�d��q0|�|�qdd�}t�|�D]}|�|j�d��qf|�|�dD]:\}}}t|dd�}|�|d|�|�||�|�|�q�dS)	N))z-0.5g�)z-0.0��)z
-(1.0-1.0)rm)z-0r)z~-2r)z+1rr2r3r:�UNARY_cSsdS)Nrmrrrrr�negzero&szDTestTranforms.test_folding_of_unaryops_on_constants.<locals>.negzero))z-"abc"�abcZUNARY_NEGATIVE)z~"abc"rpZUNARY_INVERT)r4r.rrrirrjr%)rr5r<rrrorrrr�%test_folding_of_unaryops_on_constantss
z3TestTranforms.test_folding_of_unaryops_on_constantscCsHdd�}|�|dd�dd�t�|�D�}|�t|�d�|�|�dS)NcSs|Sr7rr'rrrr9sz/TestTranforms.test_elim_extra_return.<locals>.fr:cSsg|]}|jdkr|�qS�rrNrrrrrO<s
�z8TestTranforms.test_elim_extra_return.<locals>.<listcomp>r)r-rrrYr$r%�rrZreturnsrrr�test_elim_extra_return7s
z$TestTranforms.test_elim_extra_returncCs\dd�}|�|�|�|d�|�|d�dd�t�|�D�}|�t|�d�|�|�dS)NcSs|r|S|Sr7r)�condZ
true_valueZfalse_valuerrrrCs�z1TestTranforms.test_elim_jump_to_return.<locals>.frrcSsg|]}|jdkr|�qSrrrNrrrrrOJs
�z:TestTranforms.test_elim_jump_to_return.<locals>.<listcomp>r&)rr-rrrYr$r%rsrrr�test_elim_jump_to_returnAs
z&TestTranforms.test_elim_jump_to_returncCs dd�}|�|�|�|�dS)NcSstrtstrt�nt�dSr7)rGr�d�fooZbazrrrrrQs�z6TestTranforms.test_elim_jump_to_uncond_jump.<locals>.f�rr%�rrrrr�test_elim_jump_to_uncond_jumpOs
z+TestTranforms.test_elim_jump_to_uncond_jumpcCs dd�}|�|�|�|�dS)NcSs|rtstrt�}qdSr7)rrwrxr^rrrr^s
�z7TestTranforms.test_elim_jump_to_uncond_jump2.<locals>.fryrzrrr�test_elim_jump_to_uncond_jump2\s
z,TestTranforms.test_elim_jump_to_uncond_jump2cCs�dd�}|�|�|�|�|�t|d�d�dd�}|�|�|�|�|�t|d�d�dd�}|�|�|�|�|�|d�|�|d�|�|d�d	d�}|�|�|�|�|�|d�|�|d�|�|d
�dS)NcSs|o
|o
|Sr7rrFrrrrjs�z7TestTranforms.test_elim_jump_to_uncond_jump3.<locals>.fZJUMP_IF_FALSE_OR_POPr&cSs|p
|p
|Sr7rrFrrrrqs�ZJUMP_IF_TRUE_OR_POPcSs|r|p
|Sr7rrFrrrrxs�r*cSs|s|o
|Sr7rrFrrrr�s�r+)rr%rYrr-r.rzrrr�test_elim_jump_to_uncond_jump3gs(







z,TestTranforms.test_elim_jump_to_uncond_jump3cCsRdd�}|�|d�|�|d�dd�t�|�D�}|�t|�d�|�|�dS)NcSs |rdS|rdSdS|rdSdS)Nrr&rErLrPrQr�Zcond1Zcond2rrrr�sz5TestTranforms.test_elim_jump_after_return1.<locals>.frrcSsg|]}|jdkr|�qSrrrNrrrrrO�s
�z>TestTranforms.test_elim_jump_after_return1.<locals>.<listcomp>rQ)r-rr�assertLessEqualr$r%rsrrr�test_elim_jump_after_return1�s	z*TestTranforms.test_elim_jump_after_return1cCsjdd�}|�|d�dd�t�|�D�}|�t|�d�dd�t�|�D�}|�t|�d�|�|�dS)	NcSs|rdSqdS)NrLrr~rrrr�sz5TestTranforms.test_elim_jump_after_return2.<locals>.frcSsg|]}|jdkr|�qSr>rNrrrrrO�s
�z>TestTranforms.test_elim_jump_after_return2.<locals>.<listcomp>rcSsg|]}|jdkr|�qSrrrNrrrrrO�s
�r&)r-rrrYr$rr%rsrrr�test_elim_jump_after_return2�sz*TestTranforms.test_elim_jump_after_return2cCs"dd�}|�|d�|�|�dS)NcSsdd�dd�}|S)Nr&)�returncSsdSr7rrrrrr8�szBTestTranforms.test_make_function_doesnt_bail.<locals>.f.<locals>.gr)r8rrrr�sz7TestTranforms.test_make_function_doesnt_bail.<locals>.fZ
BINARY_ADD)r-r%rzrrr�test_make_function_doesnt_bail�sz,TestTranforms.test_make_function_doesnt_bailc	Cs�ddddddddd	g	}|D]`}t|d
d�}t�|�D]:}|�|j�d��|�|j�d
��|�|j�d��q4|�|�qdS)Nz3 * -5z-3 * 5z2 * (3 * 4)z(2 * 3) * 4z
(-1, 2, 3)z
(1, -2, 3)z
(1, 2, -3)z(1, 2, -3) * 6z:lambda x: x in {(3 * -5) + (-1 - 6), (1, -2, 3) * 2, None}r2r3rnrhZBUILD_)r4rrrirrjr%)rZexprs�errrrr�test_constant_folding�s"�z#TestTranforms.test_constant_foldingcCs(dd�}|�t|d�d�|�|�dS)NcSstttfkSr7)r(rGrHrrrr�containtest�sz7TestTranforms.test_in_literal_list.<locals>.containtestr[r�rYrr%)rr�rrr�test_in_literal_list�sz"TestTranforms.test_in_literal_listcCs(dd�}|�t|d�d�|�|�dS)NcSsttfD]}qdSr7)rGrHr'rrr�forloop�sz8TestTranforms.test_iterate_literal_list.<locals>.forloopr[rr�)rr�rrr�test_iterate_literal_list�sz'TestTranforms.test_iterate_literal_listcCs$dd�}|�|�d�|�|�dS)NcSsdsdrdSdS)NTFrrrrrrrr�sz=TestTranforms.test_condition_with_binop_with_bools.<locals>.fr)rYr%rzrrr�$test_condition_with_binop_with_bools�sz2TestTranforms.test_condition_with_binop_with_boolscCs$dd�}|�|d��|�|�dS)NcSs|rndrdSdS)NTFrr'rrrr�s
z3TestTranforms.test_if_with_if_expression.<locals>.fT)r`r%rzrrr�test_if_with_if_expression�sz(TestTranforms.test_if_with_if_expressioncCsdd�}|�|�dS)NcSsdSdS)NrErPrQrr'rrrr�sz+TestTranforms.test_trailing_nops.<locals>.f)r%rzrrr�test_trailing_nops�sz TestTranforms.test_trailing_nopsN)�__name__�
__module__�__qualname__rr%r/r6r=r?rCrZr\rarkrlrqrtrvr{r|r}r�r�r�r�r�r�r�r�r�rrrrrs6
(
,!

#	rc@seZdZdd�ZdS)�TestBugletsc	Cs(dd�}|�t��|�W5QRXdS)NcSsddh\}}||fS)Nrr)r(�yrrrr�sz%TestBuglets.test_bug_11510.<locals>.f)ZassertRaises�
ValueErrorrzrrr�test_bug_11510�szTestBuglets.test_bug_11510N)r�r�r�r�rrrrr��sr��__main__)
rZunittestZtest.bytecode_helperrrrZTestCaser�r��mainrrrr�<module>s
b


F1le Man4ger