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/local/lib/python3.10/test/__pycache__/test_finalization.cpython-310.opt-1.pyc
o

�i�:�@sBdZddlZddlZddlZddlZzddlmZWn
ey'dd�ZYnwzddlmZWn
ey=dd�ZYnwdd	l	m
Z
Gd
d�d�ZGdd
�d
e�ZeGdd�de��Z
eGdd�de��ZGdd�de�ZGdd�de�ZGdd�d�ZGdd�deej�ZGdd�d�ZGdd�dee�ZGdd�dee�ZGd d!�d!ee�ZGd"d#�d#eej�ZGd$d%�d%�ZGd&d'�d'ee�ZGd(d)�d)ee�ZGd*d+�d+ee�ZGd,d-�d-eej�ZGd.d/�d/e�ZeGd0d1�d1e��ZeGd2d3�d3e��Z eGd4d5�d5ee��Z!e
j"Gd6d7�d7eej��Z#e$d8k�re�%�dSdS)9zB
Tests for object finalization semantics, as outlined in PEP 442.
�N)�with_tp_delcCsGdd�dt�}|S)Nc@�eZdZdd�ZdS)zwith_tp_del.<locals>.Cc_�td��)Nzrequires _testcapi.with_tp_del��	TypeError��cls�args�kwargs�r�3/usr/local/lib/python3.10/test/test_finalization.py�__new__�zwith_tp_del.<locals>.C.__new__N��__name__�
__module__�__qualname__r
rrrr�C�r)�object�rrrrrr
sr)�
without_gccCsGdd�d�}|S)Nc@r)zwithout_gc.<locals>.Cc_r)Nzrequires _testcapi.without_gcrrrrrr
rzwithout_gc.<locals>.C.__new__Nrrrrrrrrrrrrrrsr)�supportc@s^eZdZdZgZgZgZgZdZdZ	e
dd��Ze
ej
dd���Zdd	�Zd
d�Zdd
�ZdS)�NonGCSimpleBasezd
    The base class for all the objects under test, equipped with various
    testing features.
    FrcCs>|j��|j��tj��t��|j��|j��dS�N)�	survivors�clear�errors�gc�garbage�collect�	del_calls�tp_del_calls�rrrr�_cleanup.s



zNonGCSimpleBase._cleanupc	cs��t���3|j��|j��dt_zdV|jr|jd�Wdt_|��ndt_|��wWd�dS1s;wYdS)zI
        A context manager to use around all finalization tests.
        FNrT)	rZ
disable_gcr!rr"r�	_cleaningrr$r#rrr�test7s�



�
�"�zNonGCSimpleBase.testcC�dS)z8
        Check the object is sane (non-broken).
        Nr��selfrrr�check_sanityI�zNonGCSimpleBase.check_sanityc
C�fz|js|j�t|��|��|��WdSWdSty2}z
|j�|�WYd}~dSd}~ww)z�
        PEP 442 finalizer.  Record that this was called, check the
        object is in a sane state, and invoke a side effect.
        N)r%r!�append�idr*�side_effect�	Exceptionr�r)�errr�__del__Ns���zNonGCSimpleBase.__del__cCr')z6
        A side effect called on destruction.
        Nrr(rrrr/[r+zNonGCSimpleBase.side_effectN)rrr�__doc__rr!r"rr%�	__slots__�classmethodr$�
contextlib�contextmanagerr&r*r3r/rrrrrs 

rc@�eZdZdd�Zdd�ZdS)�
SimpleBasecCst|�|_dSr)r.Zid_r(rrr�__init__c�zSimpleBase.__init__cCsdSrrr(rrrr*fr+zSimpleBase.check_sanityN)rrrr;r*rrrrr:asr:c@seZdZdZdS)�NonGCrN)rrrr5rrrrr=jsr=c@seZdZdZdd�ZdS)�NonGCResurrectorrcC�|j�|�dS�zF
        Resurrect self by storing self in a class-wide list.
        N�rr-r(rrrr/r�zNonGCResurrector.side_effectN)rrrr5r/rrrrr>nsr>c@�eZdZdS)�SimpleN�rrrrrrrrDx�rDc@r)�SimpleResurrectorcCr?r@rAr(rrrr/~rBzSimpleResurrector.side_effectN�rrrr/rrrrrG|�rGc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestBasecCs"tjdd�|_gtjdd�<dSr)rr�old_garbager(rrr�setUp�szTestBase.setUpcCs0z|�tjg�W|`t��dS|`t��wr)�assertEqualrrrKr r(rrr�tearDown�s�
zTestBase.tearDowncC�|�ttj�t|��dSr)rM�sortedr:r!�r)�idsrrr�assert_del_calls��zTestBase.assert_del_callscCrOr)rMrPr:r"rQrrr�assert_tp_del_calls�rTzTestBase.assert_tp_del_callscC�$|�tdd�tjD��t|��dS)Ncs��|]}t|�VqdSr�r.��.0�xrrr�	<genexpr>���z,TestBase.assert_survivors.<locals>.<genexpr>)rMrPr:rrQrrr�assert_survivors��$zTestBase.assert_survivorscCrV)NcsrWrrXrYrrrr\�r]z*TestBase.assert_garbage.<locals>.<genexpr>)rMrPrrrQrrr�assert_garbage�r_zTestBase.assert_garbagecCstj��dSr)r:rrr(rrr�clear_survivors�r<zTestBase.clear_survivorsN)
rrrrLrNrSrUr^r`rarrrrrJ�srJc@s<eZdZdZdd�Zdd�Zejdd��Zejdd	��Z	d
S)�SimpleFinalizationTestz.
    Test finalization without refcycles.
    cC�t���:t�}t|�g}t�|�}~t��|�|�|�	g�|�
|�d�t��|�|�|�	g�Wd�dS1sAwYdSr)r:r&rDr.�weakref�refrr rSr^�assertIs�r)�srR�wrrrr�test_simple��





"�z"SimpleFinalizationTest.test_simplecCs�t���=t�}t|�g}t�|�}~t��|�|�|�	|�|�
|�d�|��t��|�|�|�	g�Wd�n1sDwY|�|�d�dSr)
r:r&rGr.rdrerr rSr^�assertIsNotrarfrgrrr�test_simple_resurrect�s





�
z,SimpleFinalizationTest.test_simple_resurrectcCs�t���6t�}|�t�|��t|�g}~t��|�|�|�	g�t��|�|�|�	g�Wd�dS1s=wYdSr)
r:r&r=�assertFalser�
is_trackedr.r rSr^�r)rhrRrrr�test_non_gc�s




"�z"SimpleFinalizationTest.test_non_gccCs�t���<t�}|�t�|��t|�g}~t��|�|�|�	|�|�
�t��|�|d�|�	|�Wd�dS1sCwYdS�N�)r:r&r>rnrror.r rSr^rarprrr�test_non_gc_resurrect�s



"�z,SimpleFinalizationTest.test_non_gc_resurrectN)
rrrr4rjrmr�cpython_onlyrqrtrrrrrb�s

rbcs(eZdZ�fdd�Z�fdd�Z�ZS)�
SelfCycleBasecst���||_dSr)�superr;rer(��	__class__rrr;�s

zSelfCycleBase.__init__cst���dSr)rwr*r(rxrrr*�r<zSelfCycleBase.check_sanity)rrrr;r*�
__classcell__rrrxrrv�srvc@rC)�SimpleSelfCycleNrErrrrr{�rFr{c@rC)�SelfCycleResurrectorNrErrrrr|�rFr|c@r)�SuicidalSelfCyclecCs
d|_dS)�7
        Explicitly break the reference cycle.
        N)rer(rrrr/�s
zSuicidalSelfCycle.side_effectNrHrrrrr}�rIr}c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�SelfCycleFinalizationTestzX
    Test finalization of an object having a single cyclic reference to
    itself.
    cCrcr)r:r&r{r.rdrerr rSr^rfrgrrrrjrkz%SelfCycleFinalizationTest.test_simplecCs�t���Et�}t|�g}t�|�}~t��|�|�|�	|�|�
|�d�|��t��|�|�|�	g�|�
|�d�Wd�dS1sLwYdSr)r:r&r|r.rdrerr rSr^rfrargrrrrms






"�z/SelfCycleFinalizationTest.test_simple_resurrectcCs�t���At�}t|�g}t�|�}~t��|�|�|�	g�|�
|�d�t��|�|�|�	g�|�
|�d�Wd�dS1sHwYdSr)r:r&r}r.rdrerr rSr^rfrgrrr�test_simple_suicide%s






"�z-SelfCycleFinalizationTest.test_simple_suicideN)rrrr4rjrmr�rrrrr�s
rcs$eZdZdd�Z�fdd�Z�ZS)�ChainedBasecCsd|_||_||_dS)NF��suicided�left�right)r)r�rrr�chain9s
zChainedBase.chaincs4t���|jr
dS|j}|jr|j}|jrdSdSr)rwr*r�r�r�)r)r�r�rxrrr*>s

zChainedBase.check_sanity)rrrr�r*rzrrrxrr�7sr�c@rC)�
SimpleChainedNrErrrrr�OrFr�c@rC)�ChainedResurrectorNrErrrrr�RrFr�c@r)�SuicidalChainedcCsd|_d|_d|_dS)r~TNr�r(rrrr/Ws
zSuicidalChained.side_effectNrHrrrrr�UrIr�c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�CycleChainFinalizationTestz�
    Test finalization of a cyclic chain.  These tests are similar in
    spirit to the self-cycle tests above, but the collectable object
    graph isn't trivial anymore.
    cCs:dd�|D�}tt|��D]
}||�||d�q
|S)NcS�g|]}|��qSrr)rZrrrr�
<listcomp>h�z:CycleChainFinalizationTest.build_chain.<locals>.<listcomp>�)�range�lenr�)r)�classes�nodes�irrr�build_chaingsz&CycleChainFinalizationTest.build_chaincCs�t|�}t���B|�|�}dd�|D�}dd�|D�}~t��|�|�|�g�|�dd�|D�dg|�t��|�|�Wd�dS1sMwYdS)NcS�g|]}t|��qSrrX�rZrhrrrr�q�zKCycleChainFinalizationTest.check_non_resurrecting_chain.<locals>.<listcomp>cS�g|]}t�|��qSr�rdrer�rrrr�r�cSr�rr�rZrirrrr�wr�)	r�r:r&r�rr rSr^rM)r)r��Nr�rR�wrsrrr�check_non_resurrecting_chainms



"�z7CycleChainFinalizationTest.check_non_resurrecting_chaincCs�t|�}t���V|�|�}t|�}dd�|D�}dd�|D�}dd�|D�}~t��|�|�|�|�|�dd�|D�dg|�|�	�t��|�|�|�g�Wd�dS1sawYdS)NcSr�rrXr�rrrr��r�zGCycleChainFinalizationTest.check_resurrecting_chain.<locals>.<listcomp>cSsg|]}t|t�rt|��qSr)�
isinstancerGr.r�rrrr��scSr�rr�r�rrrr��r�cSr�rrr�rrrr��r�)
r�r:r&r�rr rSr^rMra)r)r�r�r�rRZsurvivor_idsr�rrr�check_resurrecting_chain{s"




"�z3CycleChainFinalizationTest.check_resurrecting_chaincC�|�tgd�dS�N�)r�r�r(rrr�test_homogenous��z*CycleChainFinalizationTest.test_homogenouscCr�r�)r�r�r(rrr�test_homogenous_resurrect�r�z4CycleChainFinalizationTest.test_homogenous_resurrectcCr�r�)r�r�r(rrr�test_homogenous_suicidal�r�z3CycleChainFinalizationTest.test_homogenous_suicidalcC�|�ttgd�dSrr�r�r�r�r(rrr�test_heterogenous_suicidal_one��z9CycleChainFinalizationTest.test_heterogenous_suicidal_onecCs|�tgdtgd�dSrrr�r(rrr�test_heterogenous_suicidal_two�s�z9CycleChainFinalizationTest.test_heterogenous_suicidal_twocCr�rr)r�r�r�r(rrr�test_heterogenous_resurrect_one�r�z:CycleChainFinalizationTest.test_heterogenous_resurrect_onecCs|�tttgd�dSrr�r�r�r�r�r(rrr�test_heterogenous_resurrect_two�s�z:CycleChainFinalizationTest.test_heterogenous_resurrect_twocCs(|�tgdtgdtgd�dSrrr�r(rrr�!test_heterogenous_resurrect_three�s�z<CycleChainFinalizationTest.test_heterogenous_resurrect_threeN)rrrr4r�r�r�r�r�r�r�r�r�r�r�rrrrr�`sr�c@r9)�
LegacyBasec
Cs^z|js|j�t|��|��WdSWdSty.}z
|j�|�WYd}~dSd}~wwr)r%r!r-r.r*r0rr1rrrr3�s���zLegacyBase.__del__c
Cr,)zJ
        Legacy (pre-PEP 442) finalizer, mapped to a tp_del slot.
        N)r%r"r-r.r*r/r0rr1rrr�
__tp_del__�s���zLegacyBase.__tp_del__N)rrrr3r�rrrrr��s
r�c@rC)�LegacyNrErrrrr���r�c@r)�LegacyResurrectorcCr?r@rAr(rrrr/�rBzLegacyResurrector.side_effectNrHrrrrr��sr�c@rC)�LegacySelfCycleNrErrrrr��r�r�cs8eZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�ZS)
�LegacyFinalizationTestz5
    Test finalization of objects with a tp_del.
    cs tj��t��t���dSr)rrrr rwrNr(rxrrrN�s
zLegacyFinalizationTest.tearDowncCs�t���?t�}t|�g}t�|�}~t��|�|�|�	|�|�
g�|�|�d�t��|�|�|�	|�Wd�dS1sFwYdSr)r:r&r�r.rdrerr rSrUr^rfrgrrr�test_legacy�s






"�z"LegacyFinalizationTest.test_legacycCs�t���It�}t|�g}t�|�}~t��|�|�|�	|�|�
|�|�|�d�|��t��|�|�|�	|d�|�
|�Wd�n1sPwY|�|�d�dSrr)
r:r&r�r.rdrerr rSrUr^rfrargrrr�test_legacy_resurrect�s"






�z,LegacyFinalizationTest.test_legacy_resurrectcCs�t���;t�}t|�g}t�|�}~t��|�g�|�	g�|�
g�|�|�|�|�d�dtj
d_Wd�n1sBwY|�g�|�|�d�dS)Nr)r:r&r�r.rdrerr rSrUr^r`rlrrfrgrrr�test_legacy_self_cycles






�

z-LegacyFinalizationTest.test_legacy_self_cycle)	rrrr4rNr�r�r�rzrrrxrr��sr��__main__)&r4r7rZunittestrdZ	_testcapir�ImportErrorrr&rrr:r=r>rDrGrJZTestCaserbrvr{r|r}rr�r�r�r�r�r�r�r�r�rur�r�mainrrrr�<module>s`��B			A
	:M
A�