%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__xxsubinterpreters.cpython-39.opt-1.pyc
a

�_g�9�@sPddlmZddlZddlZddlZddlZddlZddlmZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZe
�d�Zdd�ZdId	d
�Zejdd��Zd
d�Zifdd�ZGdd�dedd��Zejdd��ZGdd�dedd��ZGdd�dedd��Zdd�dd�Zd d!�Zd"d#�Zd$d%�ZGd&d'�d'ej �Z!Gd(d)�d)ej �Z"Gd*d+�d+ej �Z#Gd,d-�d-e!�Z$Gd.d/�d/e!�Z%Gd0d1�d1e!�Z&Gd2d3�d3e!�Z'Gd4d5�d5e!�Z(Gd6d7�d7e!�Z)Gd8d9�d9e!�Z*Gd:d;�d;e!�Z+Gd<d=�d=e!�Z,Gd>d?�d?e!�Z-Gd@dA�dAe!�Z.GdBdC�dCedCdD��Z/e�0dE�GdFdG�dGe!��Z1e2dHk�rLe�3�dS)J�)�
namedtupleN)�dedent)�support)�
script_helperZ_xxsubinterpreterscCs:t��\}}|�dd�}td|�d|�d��}|t|�fS)N�
z
                z-
        import contextlib
        with open(zU, 'w') as spipe:
            with contextlib.redirect_stdout(spipe):
                z	
        )�os�pipe�replacer�open)�script�r�wZindented�wrapped�r�;/vddos/python/lib/python3.9/test/test__xxsubinterpreters.py�_captured_scripts��
rcCsJt|�\}}|�&t�|||�|��Wd�S1s<0YdS�N)r�interpreters�
run_string�read)�interpZrequest�sharedrZrpiperrr�_run_output"src#stt��\�}��fdd�}tj|d�}|��dVt|d��}|�d�Wd�n1s^0Y|��dS)Ncst��td��d���dS)Nz7
            # wait for "signal"
            with open(z5) as rpipe:
                rpipe.read()
            )rrrr�rrrr�run,s
�z_running.<locals>.run��targetr
�done)rr�	threading�Thread�startr
�write�join)rr
r�tZspiperrr�_running)s(r$cKst|||�dSr)�_run_interp)�id�sourcerrrr�
run_interpGsr(cCsFt|�}t��}||kr4t��|kr(t�t||�nt�|||�dSr)rr�get_main�get_current�RuntimeError�execr)r&r'rZ_mainns�mainrrrr%Ksr%cs*eZdZedd��Zd�fdd�	Z�ZS)�InterpretercCs(t||�r|St|t�r ||�St�dSr)�
isinstance�str�NotImplementedError)�cls�rawrrr�from_rawYs


zInterpreter.from_rawNcs�t��}||kr6|sd}n|dkr0td�|���|}nX|durp|sHd}n|dkrXtd��t|tj�s�t�|�}n|r||dkr�d}|}nt��}t��|||�}|S)Nr-z)name mismatch (expected "main", got "{}")rz!name mismatch (unexpected "main"))	rr)�
ValueError�formatr/�
InterpreterID�create�super�__new__)r2�namer&r-�self��	__class__rrr:bs,�zInterpreter.__new__)NN)�__name__�
__module__�__qualname__�classmethodr4r:�
__classcell__rrr=rr.Ws
r.zname idccs$z
dVWntjyYn0dSr)r�ChannelClosedErrorrrrr�expect_channel_closed}s

rEcs6eZdZd
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�
ChannelActionNcs&|sd}|sd}t��||||�}|S)N�bothr-�r9r:)r2�action�endrr<r=rrr:�szChannelAction.__new__cOsb|jdkr |jdvrJt|j��n*|jdvr@|jdvrJt|j��n
t|j��|jdvr^t|j��dS)N�use)�same�opposite�send�recv��close�force-close)rGrLrMrNrO)r-rL�other�extra)rIrJr5r)r<�args�kwargsrrr�__init__�s





zChannelAction.__init__cCs2|jdkr|S|jdkr(|dkr$dSdS|jSdS)NrLrMrNrO�rJ�r<rJrrr�resolve_end�s


zChannelAction.resolve_endcCst|jdkr|S|jdkr(|dur$t�|S|jdkrB|dur>t�|S|jdkrp|jdkrZ|S|rl|jdkrl|St�dS)NrLrSrTr-)rr+r;)r<rrSrTrrr�resolve_interp�s 




zChannelAction.resolve_interp)NN)r?r@rAr:rWrZr[rCrrr=rrF�srFzaction end interpcsBeZdZddd��fdd�Zdd�Zdd	�Zd
d�dd
�Z�ZS)�ChannelStaterF��closedcst��|||�}|SrrH)r2�pendingr^r<r=rrr:�szChannelState.__new__cCst|�|jd|jd�S�N�r]��typer_r^�r<rrr�incr�szChannelState.incrcCst|�|jd|jd�Sr`rbrdrrr�decr�szChannelState.decrT��forcecCs2|jr|r|jdkr|St|�|r&dn|jdd�S)NrTr])r^r_rc)r<rhrrrrQ�szChannelState.close)r)r?r@rAr:rerfrQrCrrr=rr\�sr\zpending closedT��
hideclosedcCsr|jr(|dkr"|dkr"|jr"d}q,d}nd}zt||||�}Wn&tjyd|sX|sX�|��}Yn
0|rnd�|S)NrKrOFT.)r^r_�_run_actionrrDrQ)�cidrIrJ�staterjZ
expectfail�resultrrr�
run_action�srocCs|dkr�|dkr$t�|d�|��S|dkrx|jsdzt�|�WntjyX|YS0td��q�t�|�|��Snt|��n~|dkr�i}|dvr�d||<tj	|fi|��|�
�S|d	k�r�d
di}|dvr�d||<tj	|fi|��|j
dd�St|��dS)NrKrN�spamrOzexpected ChannelEmptyErrorrQ�rOrNTrRrhrg)r�channel_sendrer_�channel_recv�ChannelEmptyError�	Exceptionrfr5�
channel_closerQ)rlrIrJrmrVrrrrk�s8





�rkc	Cs>t��D]0}|dkrqzt�|�Wqty6Yq0qdS)Nr)r�list_all�destroyr+�r&rrr�clean_up_interpreterssrzc	Cs6t��D](}zt�|�Wqtjy.Yq0qdSr)r�channel_list_all�channel_destroy�ChannelNotFoundError�rlrrr�clean_up_channelss
rc@seZdZdd�ZdS)�TestBasecCst�t�dSr�rzrrdrrr�tearDownszTestBase.tearDownN)r?r@rAr�rrrrr�sr�c@seZdZdd�Zdd�ZdS)�IsShareableTestsc	CsPgd�}|D]>}|�|�� |�t�|��Wd�q1s@0YqdS)N)Nrp�spam�
i����)�subTest�
assertTruer�is_shareable)r<Z
shareables�objrrr�test_default_shareables$s	�z(IsShareableTests.test_default_shareablesc
Cs�Gdd�d�}Gdd�dt�}ddtdttt�t�d||d	�|d
�g}|D]B}|�t|��� |�t�	|��Wd�qJ1s�0YqJdS)Nc@seZdZdd�Zdd�ZdS)z3IsShareableTests.test_not_shareable.<locals>.CheesecSs
||_dSr�r;)r<r;rrrrW5sz<IsShareableTests.test_not_shareable.<locals>.Cheese.__init__cSs|jSrr�rdrrr�__str__7sz;IsShareableTests.test_not_shareable.<locals>.Cheese.__str__N)r?r@rArWr�rrrr�Cheese4sr�c@seZdZdZdS)z5IsShareableTests.test_not_shareable.<locals>.SubByteszA subclass of a shareable type.N)r?r@rA�__doc__rrrr�SubBytes:sr�TF.gY@ZWensleydalerp)
�bytes�NotImplementedrc�objectrur��repr�assertFalserr�)r<r�r�Znot_shareablesr�rrr�test_not_shareable3s(��z#IsShareableTests.test_not_shareableN)r?r@rAr�r�rrrrr�"sr�cs`eZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Z�ZS)�ShareableTypeTestscst���t��|_dSr)r9�setUpr�channel_createrlrdr=rrr�Vs
zShareableTypeTests.setUpcst�|j�t���dSr)rr|rlr9r�rdr=rrr�ZszShareableTypeTests.tearDownc	Csr|D]h}|�|��Jt�|j|�t�|j�}|�||�|�t|�t|��Wd�q1sb0YqdSr)r�rrrrlrs�assertEqual�assertIsrc)r<�valuesr��gotrrr�_assert_values^sz!ShareableTypeTests._assert_valuesc	Cs^dD]T}|�|��6t�|j|�t�|j�}|�||�Wd�q1sN0YqdS)Nr)r�rrrrlrsr�)r<r�r�rrr�test_singletonsis
z"ShareableTypeTests.test_singletonscCs|�dd|jg�dS)Nrpi')r�rlrdrrr�
test_typesrs
�zShareableTypeTests.test_typescCs|�dd�tdd�D��dS)Ncss|]}|jdddd�VqdS)��littleT)�signedN)�to_bytes)�.0�irrr�	<genexpr>zs�z0ShareableTypeTests.test_bytes.<locals>.<genexpr>����)r��rangerdrrr�
test_bytesys
�zShareableTypeTests.test_bytescCs|�gd��dS)N)zhello worldu你好世界�)r�rdrrr�	test_strs}szShareableTypeTests.test_strscCs*|�t�tdd�tjtjdg��dS)Nr�r�ra)r��	itertools�chainr��sys�maxsizerdrrr�test_int�s�zShareableTypeTests.test_intc
Cs�tjdtjdddg}|D]f}|�|��H|�t��t�|j|�Wd�n1s^0YWd�q 1s|0Yq dS)Nrar���)r�r�r��assertRaises�
OverflowErrorrrrrl)r<Zintsr�rrr�test_non_shareable_int�s
�z)ShareableTypeTests.test_non_shareable_int)
r?r@rAr�r�r�r�r�r�r�r�r�rCrrr=rr�Ts	r�c@s$eZdZdd�Zdd�Zdd�ZdS)�ListAllTestscCs"t��}t��}|�||g�dSr)rr)rwr�)r<r-�idsrrr�test_initial�szListAllTests.test_initialcCs6t��}t��}t��}t��}|�||||g�dSr)rr)r8rwr��r<r-�first�secondr�rrr�test_after_creating�s
z ListAllTests.test_after_creatingcCs>t��}t��}t��}t�|�t��}|�|||g�dSr)rr)r8rxrwr�r�rrr�test_after_destroying�s
z"ListAllTests.test_after_destroyingN)r?r@rAr�r�r�rrrrr��sr�c@seZdZdd�Zdd�ZdS)�GetCurrentTestscCs.t��}t��}|�||�|�|tj�dSr)rr)r*r��assertIsInstancer7)r<r-�currrr�	test_main�szGetCurrentTests.test_maincCsRt��}t��}t|td��}t|���}t��\}}|�||�|�	||�dS)Nz�
            import _xxsubinterpreters as _interpreters
            cur = _interpreters.get_current()
            print(cur)
            assert isinstance(cur, _interpreters.InterpreterID)
            )
rr)r8rr�int�striprwr�ZassertNotEqual)r<r-r�outr��_�expectedrrr�test_subinterpreter�sz#GetCurrentTests.test_subinterpreterN)r?r@rAr�r�rrrrr��sr�c@seZdZdd�Zdd�ZdS)�GetMainTestscCs0t��\}t��}|�||�|�|tj�dSr)rrwr)r�r�r7)r<r�r-rrr�test_from_main�s
zGetMainTests.test_from_maincCs<t��\}t��}t|td��}t|���}|�||�dS)Nz�
            import _xxsubinterpreters as _interpreters
            main = _interpreters.get_main()
            print(main)
            assert isinstance(main, _interpreters.InterpreterID)
            )rrwr8rrr�r�r�)r<r�rr�r-rrr�test_from_subinterpreter�s

z%GetMainTests.test_from_subinterpreterN)r?r@rAr�r�rrrrr��sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�IsRunningTestscCst��}|�t�|��dSr)rr)r��
is_running)r<r-rrrr��szIsRunningTests.test_maincCsdt��}|�t�|��t|�� |�t�|��Wd�n1sF0Y|�t�|��dSr)rr8r�r�r$r��r<rrrrr��s

.z"IsRunningTests.test_subinterpretercCs2t��}t|td|�d���}|�|��d�dS)Nz`
            import _xxsubinterpreters as _interpreters
            if _interpreters.is_running(zZ):
                print(True)
            else:
                print(False)
            �True)rr8rrr�r�)r<rr�rrrr��s
�z'IsRunningTests.test_from_subinterpretercCsJt��}t�|�|�t��t�|�Wd�n1s<0YdSr)rr8rxr�r+r�r�rrr�test_already_destroyed�s
z%IsRunningTests.test_already_destroyedcCs8|�t��t�d�Wd�n1s*0YdS�Ni@B)r�r+rr�rdrrr�test_does_not_exist�sz"IsRunningTests.test_does_not_existcCs8|�t��t�d�Wd�n1s*0YdS�Nr�)r�r5rr�rdrrr�test_bad_id�szIsRunningTests.test_bad_idN)	r?r@rAr�r�r�r�r�r�rrrrr��sr�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�InterpreterIDTestscCs"tjddd�}|�t|�d�dS)Nr�Trg)rr7r�r��r<r&rrr�
test_with_intsz InterpreterIDTests.test_with_intcCs4Gdd�dt�}tj|�dd�}|�t|�d�dS)Nc@seZdZdd�ZdS)z.InterpreterIDTests.test_coerce_id.<locals>.IntcSsdS�Nr�rrdrrr�	__index__sz8InterpreterIDTests.test_coerce_id.<locals>.Int.__index__N�r?r@rAr�rrrr�Intsr�Trgr�)r0rr7r�r�)r<r�r&rrr�test_coerce_idsz!InterpreterIDTests.test_coerce_idcCsf|�ttjt��|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�dS�Ng$@�10s10r�l)r��	TypeErrorrr7r�r5r�rdrrrr�
szInterpreterIDTests.test_bad_idcCsHt��}|�t��"t�t|�d�Wd�n1s:0YdS�Nra)rr�r�r+r7r�r�rrrr�sz&InterpreterIDTests.test_does_not_existcCs"tjddd�}|�t|�d�dS�Nr�Trgr�)rr7r�r0r�rrr�test_strszInterpreterIDTests.test_strcCs"tjddd�}|�t|�d�dS)Nr�TrgzInterpreterID(10))rr7r�r�r�rrr�	test_reprszInterpreterIDTests.test_reprcCs(t��}t�t|��}t��}|�||k�|�||k�|�|t|�k�|�t|�|k�|�|tt|��k�|�tt|��|k�|�|tt|��dk�|�|tt|��k�|�|ddk�|�|td�k�|�|dk�|�||k�|�||k�|�||k�|�||k�dS�N皙�����?r�r��infr�)rr8r7r�r��floatr�r0�r<�id1�id2�id3rrr�
test_equality"s$z InterpreterIDTests.test_equalityN)
r?r@rAr�r�r�r�r�r�r�rrrrr��sr�c@sNeZdZdd�Ze�d�dd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdS)�CreateTestscCs*t��}|�|tj�|�|t���dSr)rr8r�r7�assertInrwr�rrr�test_in_main;szCreateTests.test_in_mainz*enable this test when working on pystate.ccCsDt�}td�D] }t��}t�|�|�|�q|�t|�d�dS)N�d)�setr�rr8rx�addr��len)r<�seenr�r&rrr�test_unique_idAs
zCreateTests.test_unique_idcsnt���d���fdd�}tj|d�}��|��Wd�n1sH0Y|��|��t���dS)Ncst���������dSr)rr8�acquire�releaser�r&�lockrr�fNsz%CreateTests.test_in_thread.<locals>.fr)r�Lockrr r"r�rrw�r<r�r#rr�r�test_in_threadKs&zCreateTests.test_in_threadcCsJt��\}t��}t|td��}t|���}|�tt���|||h�dS)Nz�
            import _xxsubinterpreters as _interpreters
            id = _interpreters.create()
            print(id)
            assert isinstance(id, _interpreters.InterpreterID)
            )	rrwr8rrr�r�r�r�)r<r-r�r�r�rrr�test_in_subinterpreterZs

z"CreateTests.test_in_subinterpretercs^t��\}t���d���fdd�}tj|d�}|��|��|�tt���|��h�dS)Ncst�td��}t|����dS)Nz�
                import _xxsubinterpreters as _interpreters
                id = _interpreters.create()
                print(id)
                )rrr�r�)r��r�r�rrr�ksz6CreateTests.test_in_threaded_subinterpreter.<locals>.fr)	rrwr8rrr r"r�r�)r<r-r�r#rr�r�test_in_threaded_subinterpretergs
	z+CreateTests.test_in_threaded_subinterpretercCsjtt���}g}td�D]}t��}|�|�q|D]}t�|�q4t��}|�tt���||hB�dS�N�)r�rrwr�r8�appendrxr��r<�beforer�r�r&rrr�test_after_destroy_allzsz"CreateTests.test_after_destroy_allcCs`tt���}t��}t��}t��}t�|�t�|�t��}|�tt���|||hB�dSr)r�rrwr8rxr�)r<rr�r�r�r&rrr�test_after_destroy_some�s

z#CreateTests.test_after_destroy_someN)r?r@rAr��unittest�skipr�r�r�r�rrrrrrr�9s
	
r�c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�DestroyTestscCsft��}t��}t��}|�|t���t�|�|�|t���|�|t���|�|t���dSr)rr8r�rwrx�assertNotInr�rrr�test_one�s
zDestroyTests.test_onecCsvtt���}t�}td�D]}t��}|�|�q|�tt���||B�|D]}t�|�qN|�tt���|�dSr)r�rrwr�r8r�r�rxrrrr�test_all�szDestroyTests.test_allcslt��\���t��t���Wd�n1s40Y��fdd�}tj|d�}|��|��dS)Ncs8��t��t���Wd�n1s*0YdSr�r�r+rrxr�r-r<rrr��sz!DestroyTests.test_main.<locals>.fr)	rrwr�r+rxrrr r"r�rrrr��s
(zDestroyTests.test_maincCsJt��}t�|�|�t��t�|�Wd�n1s<0YdSr)rr8rxr�r+r�rrrr��s
z#DestroyTests.test_already_destroyedcCs8|�t��t�d�Wd�n1s*0YdSr�r
rdrrrr��sz DestroyTests.test_does_not_existcCs8|�t��t�d�Wd�n1s*0YdSr�)r�r5rrxrdrrrr��szDestroyTests.test_bad_idcCsJt��\}t��}td|�d��}t�||�|�tt���||h�dS)Nzo
            import _xxsubinterpreters as _interpreters
            try:
                _interpreters.destroy(zD)
            except RuntimeError:
                pass
            �rrwr8rrr�r�)r<r-r&rrrr�test_from_current�s
�
zDestroyTests.test_from_currentcCsRt��\}t��}t��}td|�d��}t�||�|�tt���||h�dS)NzZ
            import _xxsubinterpreters as _interpreters
            _interpreters.destroy(�)
            r)r<r-r�r�rrrr�test_from_sibling�s
�
zDestroyTests.test_from_siblingcs4t����fdd�}tj|d�}|��|��dS)Ncst���dSr)rrxrryrrr��sz.DestroyTests.test_from_other_thread.<locals>.fr)rr8rrr r"r�rryr�test_from_other_thread�s
z#DestroyTests.test_from_other_threadc	Cs�t��\}t��}t|��||jt�|�d|�d�d�|jtd|�d�d��t�|�Wd�n1sn0Y|�t�|��Wd�n1s�0YdS)NzInterp z& should be running before destruction.)�msgz%Should not be able to destroy interp z while it's still running.)	rrwr8r$r�r�r�r+rx)r<r-rrrr�test_still_running�s


�
�(zDestroyTests.test_still_runningN)
r?r@rArrr�r�r�r�rrrrrrrrr	�s

	r	cseZdZed�ZdZ�fdd�Z�fdd�Zdd�Zd	d
�Z	dd�Z
e�e
ed
�d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zejd5dd��Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Z d0d1�Z!e�"d2�d3d4��Z#�Z$S)6�RunStringTestszJ
        with open('{}', 'w') as out:
            out.write('{}')
        r�cst���t��|_d|_dSr)r9r�rr8r&�_fsrdr=rrr�s

zRunStringTests.setUpcs"|jdur|j��t���dSr)rrQr9r�rdr=rrr�s

zRunStringTests.tearDowncCsVtd�\}}|�&t�|j|�|��}Wd�n1s<0Y|�|d�dS)N�print("it worked!", end="")�
it worked!)rrrr&rr�)r<r�filer�rrr�test_success
s
&zRunStringTests.test_successcsrtd�\�}|�B��fdd�}tj|d�}|��|��|��}Wd�n1sX0Y��|d�dS)Nrcst��j��dSr)rrr&r�rr<rrr�sz(RunStringTests.test_in_thread.<locals>.frr)rrrr r"rr�)r<rr�r#r�rrrr�s&zRunStringTests.test_in_threadcCs`tjdd�}td�\}}|�$t�||�|��}Wd�n1sF0Y|�|d�dS)NF)�isolatedz�
            import threading
            def f():
                print('it worked!', end='')

            t = threading.Thread(target=f)
            t.start()
            t.join()
            r)rr8rrrr�)r<Z	subinterprrr�rrr�test_create_threads	&z!RunStringTests.test_create_thread�forkztest needs os.fork()cCs�ddl}|�d��j}|�d�|��d}td|j�d|�d��}t�|j|�|�	d�|�
�}|�||�Wd�n1s�0YdS)Nrzw+r�zspam spam spam spam spamz�
                import os
                try:
                    os.fork()
                except RuntimeError:
                    with open('z3', 'w') as out:
                        out.write('z')
                )�tempfile�NamedTemporaryFiler!�flushrr;rrr&�seekrr�)r<r rr�rZcontentrrr�	test_fork0s
��

zRunStringTests.test_forkc	Csft|j��H|�t��t�|jd�Wd�n1s:0YWd�n1sX0YdS)N�
print("spam"))r$r&r�r+rrrdrrr�test_already_runningFsz#RunStringTests.test_already_runningcCsTd}|t��vr|d7}q|�t��t�|d�Wd�n1sF0YdS)Nrrar%)rrwr�r+rr�rrrr�Ks

z"RunStringTests.test_does_not_existcCs:|�t��t�dd�Wd�n1s,0YdS)Nr�r%)r�r5rrrdrrr�
test_error_idRszRunStringTests.test_error_idcCs:|�t��t�dd�Wd�n1s,0YdS)Nr�r%)r�r�rrrdrrrr�VszRunStringTests.test_bad_idcCs<|�t��t�|jd�Wd�n1s.0YdSr��r�r�rrr&rdrrr�test_bad_scriptZszRunStringTests.test_bad_scriptcCs<|�t��t�|jd�Wd�n1s.0YdS)Ns
print("spam")r(rdrrr�test_bytes_for_script^sz$RunStringTests.test_bytes_for_scriptNccsz|�tj��}dVWd�n1s(0Y|dur\|�t|j��d�dt|��n|�t|j�d�||��dS)N�:rz{}: {})r�r�RunFailedErrorr�r0�	exception�splitr6)r<�exctyperZcaughtrrr�assert_run_failedbs$�
�z RunStringTests.assert_run_failedcCs<|�t��t�|jd�Wd�n1s.0YdS)Nzprint("spam")r0�SyntaxErrorrrr&rdrrr�test_invalid_syntaxmsz"RunStringTests.test_invalid_syntaxcCs>|�td��t�|jd�Wd�n1s00YdS)Nr�zraise Exception("spam"))r0rurrr&rdrrr�test_failurerszRunStringTests.test_failurecCs>|�td��t�|jd�Wd�n1s00YdS)N�42zraise SystemExit(42))r0�
SystemExitrrr&rdrrr�test_SystemExitvszRunStringTests.test_SystemExitcCs~|�t��"t�|jtd��Wd�n1s20Y|�td��"t�|jtd��Wd�n1sp0YdS)NzG
                import sys
                sys.exit()
                r4zI
                import sys
                sys.exit(42)
                )r0r5rrr&rrdrrr�
test_sys_exitzs0zRunStringTests.test_sys_exitcCs�t��\}}dddd�}td|�d��}t�|j||�t|d��}t�|�}Wd�n1sb0Y|�	|dd�|�	|d	d
�|�	|dd�|�
|d
�dS)N�hams-1)r��eggs�cheddarz�
            eggs = int(eggs)
            spam = 42
            result = spam + eggs

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(�C, 'wb') as chan:
                pickle.dump(ns, chan)
            �rbr��*r9r�rn�)r:)rrrrrr&r
�pickle�loadr�ZassertIsNone�r<rr
rr�chan�nsrrr�test_with_shared�s��
(zRunStringTests.test_with_sharedcCs�t�|jtd��ddi}td�}t�|j||�t��\}}td|�d��}t�|j|�t|d��}t�|�}Wd�n1s�0Y|�	|ddd	�|�	|d
dd�|�	|dd�dS)Nzj
            spam = 'eggs'
            ns1 = dict(vars())
            del ns1['__builtins__']
            r�r8zL
            ns2 = dict(vars())
            del ns2['__builtins__']
        zr
            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(r;r<�ns1r9�ns2)
rrr&rrrr
r?r@r�)r<rrrr
rBrCrrr�test_shared_overwrites�s�
(z%RunStringTests.test_shared_overwritescCs|t��\}}ddi}td|�d��}t�|j||�t|d��}t�|�}Wd�n1s^0Y|�	|dd�dS)Nr?snot __main__z�
            spam = 42

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(r;r<)
rrrrrr&r
r?r@r�rArrr�#test_shared_overwrites_default_vars�s�
	(z2RunStringTests.test_shared_overwrites_default_varscCs�t��\}}t�|jtd|�d���t|d��}t�|�}Wd�n1sP0Yt��\}}t�|jtd|�d���t|d��}t�|�}Wd�n1s�0Y|�	d|�|�
d|�|�	d|�|�	d|�dS)Nz�
            spam = True

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(zd, 'wb') as chan:
                pickle.dump(ns, chan)
            del ns, pickle, chan
            r<z�
            eggs = False

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(r;r�r9)rrrrr&rr
r?r@r�r
)r<rr
rBrErFrrr�test_main_reused�s �
(�	(zRunStringTests.test_main_reusedc
Cs�t��\}}td|�d��}t�|j|�t|d��}t�|�}Wd�n1sT0Y|�	d�|�	d�|�
|diddddd��dS)	Nz�
            spam = 42

            ns = dict(vars())
            ns['__builtins__'] = str(ns['__builtins__'])
            import pickle
            with open(r;r<�__builtins__�
__loader__�__main__r=)r?�__annotations__r��__package__�__spec__r�)rrrrrr&r
r?r@�popr�)r<rr
rrBrCrrr� test_execution_namespace_is_main�s"�
	(

�z/RunStringTests.test_execution_namespace_is_mainzblocking foreverc	Cs�td�}t���P}t�|d|�}t�|��}|��}Wd�n1sH0YWd�n1sf0Y|�|d�dS)Na�
        from textwrap import dedent
        import threading
        import _xxsubinterpreters as _interpreters
        id = _interpreters.create()
        def f():
            _interpreters.run_string(id, dedent('''
                import time
                # Give plenty of time for the main interpreter to finish.
                time.sleep(1_000_000)
                '''))

        t = threading.Thread(target=f)
        t.start()
        rr)rrZtemp_dirrZmake_scriptZspawn_python�waitr�)r<r�dirname�filename�proc�retcoderrr�test_still_running_at_exits
Dz)RunStringTests.test_still_running_at_exit)N)%r?r@rArZSCRIPTZFILENAMEr�r�rr�rrZ
skipUnless�hasattrrr$r&r�r'r�r)r*�
contextlib�contextmanagerr0r2r3r6r7rDrGrHrIrQrrWrCrrr=rr�s8



!rc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ChannelIDTestscCs0tjddd�}|�t|�d�|�|jd�dS)Nr�TrgrG)r�_channel_idr�r�rJ�r<rlrrr�test_default_kwargs/sz"ChannelIDTests.test_default_kwargscCs�tjdddd�}|�|jd�tjddddd�}|�|jd�tjdddd�}|�|jd�tjddddd	�}|�|jd�tjddddd�}|�|jd
�dS)Nr�T�rNrhrNF�rNrOrh�rOrhrO)rOrNrhrG)rr\r�rJr]rrr�test_with_kwargs5szChannelIDTests.test_with_kwargscCs4Gdd�dt�}tj|�dd�}|�t|�d�dS)Nc@seZdZdd�ZdS)z*ChannelIDTests.test_coerce_id.<locals>.IntcSsdSr�rrdrrrr�Gsz4ChannelIDTests.test_coerce_id.<locals>.Int.__index__Nr�rrrrr�Fsr�Trgr�)r0rr\r�r�)r<r�rlrrrr�EszChannelIDTests.test_coerce_idcCsf|�ttjt��|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�dSr�)r�r�rr\r�r5r�rdrrrr�MszChannelIDTests.test_bad_idcCs>|�t�� tjdddd�Wd�n1s00YdS)Nr�F�rNrO)r�r5rr\rdrrr�test_bad_kwargsUszChannelIDTests.test_bad_kwargscCsJt��}|�tj��"t�t|�d�Wd�n1s<0YdSr�)rr�r�r}r\r�r]rrrr�Ysz"ChannelIDTests.test_does_not_existcCs"tjddd�}|�t|�d�dSr�)rr\r�r0r]rrrr�^szChannelIDTests.test_strcCs�tjddd�}|�t|�d�tjdddd�}|�t|�d�tjdddd�}|�t|�d�tjddddd	�}|�t|�d�dS)
Nr�Trgz
ChannelID(10)r_zChannelID(10, send=True)razChannelID(10, recv=True)r`)rr\r�r�r]rrrr�bszChannelIDTests.test_reprcCs(t��}t�t|��}t��}|�||k�|�||k�|�|t|�k�|�t|�|k�|�|tt|��k�|�tt|��|k�|�|tt|��dk�|�|tt|��k�|�|ddk�|�|td�k�|�|dk�|�||k�|�||k�|�||k�|�||k�dSr�)rr�r\r�r�r�r�r0)r<�cid1�cid2Zcid3rrrr�os$zChannelIDTests.test_equalityN)r?r@rAr^rbr�r�rdr�r�r�r�rrrrr[-s
r[c@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(�Ze�d)�d*d+��Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Z d:d;�Z!d<d=�Z"d>d?�Z#d@dA�Z$dBdC�Z%dDdE�Z&dFdG�Z'dHdI�Z(dJdK�Z)dLS)M�ChannelTestscCst��}|�|tj�dSr)rr�r�Z	ChannelIDr]rrr�test_create_cid�szChannelTests.test_create_cidcCsrt��}t��}t��}t��}t��}|�|t|�d�|�|t|�d�|�t|�t|�|||h�dSr�)rr{r�r�r�r�)r<rr�r�r�Zafterrrr�test_sequential_ids�sz ChannelTests.test_sequential_idscCs\t��}t|td��}t|���}t��}t|td��}t|���}|�|t|�d�dS)Nz�
            import _xxsubinterpreters as _interpreters
            cid = _interpreters.channel_create()
            print(cid)
            ra)rr8rrr�r�r�)r<r�r�rer�rfrrr�test_ids_global�szChannelTests.test_ids_globalcCs@t��}tj|dd�}tj|dd�}|�|g�|�|g�dS)z=Test listing interpreters for a channel with no associations.T�rNFN)rr��channel_list_interpretersr�)r<rl�send_interps�recv_interpsrrr�#test_channel_list_interpreters_none�s
z0ChannelTests.test_channel_list_interpreters_nonecCs�t��}t��}t�|d�tj|dd�}tj|dd�}|�||g�|�|g�t��}t|td|�d���tj|dd�}tj|dd�}|�||g�|�||g�dS)z(Test basic listing channel interpreters.rNTrkF�e
            import _xxsubinterpreters as _interpreters
            obj = _interpreters.channel_recv(rN)	rr)r�rrrlr�r8rr)r<�interp0rlrmrn�interp1rrr�$test_channel_list_interpreters_basic�s�z1ChannelTests.test_channel_list_interpreters_basiccCs�t��}t��}t��}t��}t��}t�|d�t|td|�d���t|td|�d���t|td|�d���tj|dd�}tj|dd�}|�t	|�||h�|�t	|�||h�d	S)
z?Test listing interpreters for a channel with many associations.rN�_
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_send(z, "send")
            rprTrkFN)
rr)r8r�rrrrrlr�r�)r<rqrr�interp2�interp3rlrmrnrrr�'test_channel_list_interpreters_multiple�s&���z4ChannelTests.test_channel_list_interpreters_multiplecCs�t��}t��}t��}t�|d�t|td|�d���tj|dd�}tj|dd�}|�||g�|�||g�t�	|�tj|dd�}tj|dd�}|�||g�|�|g�dS)z?Test listing channel interpreters with a destroyed interpreter.rNrprTrkFN)
rr)r8r�rrrrrlr�rx�r<rqrrrlrmrnrrr�(test_channel_list_interpreters_destroyed�s �
z5ChannelTests.test_channel_list_interpreters_destroyedcCs>t��}t��}t��}t��}t�|d�t|td|�d���t�|d�t|td|�d���tj|dd�}tj|dd�}|�t	|�d�|�t	|�d�tj
|dd�tj|dd�}tj|dd�}|�t	|�d	�|�t	|�d�t|td
|�d���tj|dd�}tj|dd�}|�t	|�d	�|�||g�dS)z:Test listing channel interpreters with a released channel.�datarprTrkFrar�r�b
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_release(N)rr)r8r�rrrrrlr�r��channel_release)r<rqrrrurlrmrnrrr�'test_channel_list_interpreters_released�s8���z4ChannelTests.test_channel_list_interpreters_releasedcCs�t��}t��}t��}t�|d�tj|dd�}tj|dd�}|�t|�d�|�t|�d�tj|dd�|�	tj
��tj|dd�Wd�n1s�0Y|�	tj
��tj|dd�Wd�n1s�0YdS)	z8Test listing channel interpreters with a closed channel.rNTrkFrarrgN)rr)r8r�rrrlr�r�rvr�rDrxrrr�%test_channel_list_interpreters_closed%s,z2ChannelTests.test_channel_list_interpreters_closedcCsXt��}t��}t��}t�|d�tj|dd�}tj|dd�}|�t|�d�|�t|�d�tj|dd�|�	tj
��tj|dd�Wd�n1s�0Ytj|dd�}|�t|�d�t|td|�d	���|�	tj
��tj|dd�Wd�n1�s0Y|�	tj
��tj|dd�Wd�n1�sJ0YdS)
zCTest listing channel interpreters with a channel's send end closed.rNTrkFrarN�`
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_close(�, force=True)
            )
rr)r8r�rrrlr�r�rvr�rDrrrxrrr�.test_channel_list_interpreters_closed_send_end;s(,�.z;ChannelTests.test_channel_list_interpreters_closed_send_endcCs>t��}d}t�||�t�|�}|�||�|�||�dS�Nrp)rr�rrrsr�ZassertIsNot)r<rlZorigr�rrr�test_send_recv_main_s
z ChannelTests.test_send_recv_maincCst��}t|td��}dS)Na6
            import _xxsubinterpreters as _interpreters
            cid = _interpreters.channel_create()
            orig = b'spam'
            _interpreters.channel_send(cid, orig)
            obj = _interpreters.channel_recv(cid)
            assert obj is not orig
            assert obj == orig
            )rr8rr)r<r�r�rrr�test_send_recv_same_interpreterhsz,ChannelTests.test_send_recv_same_interpretercCs@t��}t��}t|td|�d���}t�|�}|�|d�dS)Nrt�, b'spam')
            rp)rr�r8rrrsr�)r<rlr�r�r�rrr�%test_send_recv_different_interpretersts�
z2ChannelTests.test_send_recv_different_interpreterscsVt����fdd�}tj|d�}|��t��d�|��t���}|�|d�dS)NcsDzt���}Wq4Wqtjy0t�d�Yq0qt��|�dS)Nr�)rrsrt�time�sleeprr)r�r~rrr��s
z8ChannelTests.test_send_recv_different_threads.<locals>.frrp)	rr�rrr rrr"rsr��r<r�r#r�rr~r� test_send_recv_different_threadss
z-ChannelTests.test_send_recv_different_threadscsft���t���d����fdd�}tj|d�}|��t��d�|��t���}|�	|d�dS)Ncs t�td��d��d����dS)Nz�
                import time
                import _xxsubinterpreters as _interpreters
                while True:
                    try:
                        obj = _interpreters.channel_recv(z�)
                        break
                    except _interpreters.ChannelEmptyError:
                        time.sleep(0.1)
                assert(obj == b'spam')
                _interpreters.channel_send(z, b'eggs')
                )rrr�rlr�r�rrr��s
��zIChannelTests.test_send_recv_different_interpreters_and_threads.<locals>.frrp�eggs)
rr�r8rrr rrr"rsr�r�rr�r�1test_send_recv_different_interpreters_and_threads�s
z>ChannelTests.test_send_recv_different_interpreters_and_threadscCs<|�tj��t�dd�Wd�n1s.0YdS)Nr�rp)r�rr}rrrdrrr�test_send_not_found�sz ChannelTests.test_send_not_foundcCs:|�tj��t�d�Wd�n1s,0YdSr�)r�rr}rsrdrrr�test_recv_not_found�sz ChannelTests.test_recv_not_foundcCsBt��}|�tj��t�|�Wd�n1s40YdSr)rr�r�rtrsr]rrr�test_recv_empty�szChannelTests.test_recv_emptyc	Cs�t�}t��}t�||�}t�|d�t�|d�t�|d�t�|d�t�||�}t�||�}t�|�}t�||�}t�||�}|�||�|�|d�|�|d�|�|d�|�|d�|�||�dS)Nrarpr�)r�rr�rsrrr�r�)	r<�defaultrlZobj1�obj2Zobj3Zobj4Zobj5Zobj6rrr�test_recv_default�s$
zChannelTests.test_recv_defaultcCsRt��}t��}t|td�t|jd��}t�|�}|�|d�|�|�	�d�dS)Nz�
            import _xxsubinterpreters as _interpreters
            print(cid.end)
            _interpreters.channel_send(cid, b'spam')
            r~rprN)
rr�r8rr�dictrNrsr�r��r<rlrr�r�rrr�test_run_string_arg_unresolved�s

�
z+ChannelTests.test_run_string_arg_unresolvedz(disabled until high-level channels existcCs`t��}tj|dd�}t��}t|td�t|jd��}t�|�}|�	|d�|�	|�
�d�dS)NT)�_resolvez�
            import _xxsubinterpreters as _interpreters
            print(chan.id.end)
            _interpreters.channel_send(chan.id, b'spam')
            )rBrprN)rr�r\r8rrr�rNrsr�r�r�rrr�test_run_string_arg_resolved�s

�
z)ChannelTests.test_run_string_arg_resolvedcCs�t��}t�|d�t�|�t�|�|�tj��t�|d�Wd�n1sV0Y|�tj��t�|�Wd�n1s�0YdS�Nrpr��rr�rrrsrvr�rDr]rrr�test_close_single_user�s

*z#ChannelTests.test_close_single_usercCst��}t��}t��}t�|td|�d���t�|td|�d���t�|�|�tj��(}t�|td|�d���Wd�n1s�0Y|�dt	|j
��|�tj��(}t�|td|�d���Wd�n1s�0Y|�dt	|j
��dS)Nrtr�z_
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_recv(rz,
                _interpreters.channel_send(z, b'spam')
                rD)rr�r8rrrvr�r,r�r0r-)r<rlr�r��cmrrr�test_close_multiple_userss(
�
�

�*
�*z&ChannelTests.test_close_multiple_userscCsbt��}t�|d�t�|�t�|�|�tj��t�|�Wd�n1sT0YdSr�r�r]rrr�test_close_multiple_timess

z&ChannelTests.test_close_multiple_timesc
Cs�gd�}|D]�\}}|�||f���t��}t�|d�t�|�tj|||d�|�tj��t�|d�Wd�n1s�0Y|�tj��t�|�Wd�n1s�0YWd�q1s�0YqdS)N))FF�TF)FT)TTrprcr�)r�rr�rrrsrvr�rD)r<ZtestsrNrOrlrrr�test_close_empty"s
*zChannelTests.test_close_emptycCspt��}t�|d�t�|d�|�tj��t�|�Wd�n1sL0Yt�|�t�|d�dS)Nrpr8r��rr�rrr�ZChannelNotEmptyErrorrvrsr]rrr�%test_close_defaults_with_unused_items5s(
z2ChannelTests.test_close_defaults_with_unused_itemscCs�t��}t�|d�t�|d�|�tj��tj|dd�Wd�n1sP0Yt�|�t�|d�t�|�t�|�tj|dd�dS)Nrpr8T�rOr�r�r]rrr�*test_close_recv_with_unused_items_unforced?s,


z7ChannelTests.test_close_recv_with_unused_items_unforcedcCs�t��}t�|d�t�|d�tj|dd�|�tj��t�|d�Wd�n1s\0Yt�|�t�|�|�tj��t�|�Wd�n1s�0YdS)Nrpr8Trkr��rr�rrrvr�rDrsr]rrr�*test_close_send_with_unused_items_unforcedLs*

z7ChannelTests.test_close_send_with_unused_items_unforcedcCs�t��}t�|d�t�|d�|�tj�� tj|ddd�Wd�n1sR0Yt�|�t�|d�t�|�t�|�tj|dd�dS)Nrpr8Trqr�r�r�r]rrr�*test_close_both_with_unused_items_unforcedYs.


z7ChannelTests.test_close_both_with_unused_items_unforcedcCs�t��}t�|d�t�|d�tj|ddd�|�tj��t�|d�Wd�n1s^0Y|�tj��t�|�Wd�n1s�0YdS)Nrpr8Trar�r�r]rrr�(test_close_recv_with_unused_items_forcedfs*z5ChannelTests.test_close_recv_with_unused_items_forcedcCs�t��}t�|d�t�|d�tj|ddd�|�tj��t�|d�Wd�n1s^0Y|�tj��t�|�Wd�n1s�0YdS)Nrpr8Tr_r�r�r]rrr�(test_close_send_with_unused_items_forcedqs*z5ChannelTests.test_close_send_with_unused_items_forcedcCs�t��}t�|d�t�|d�tj|dddd�|�tj��t�|d�Wd�n1s`0Y|�tj��t�|�Wd�n1s�0YdS)Nrpr8Tr`r�r�r]rrr�(test_close_both_with_unused_items_forced|s*z5ChannelTests.test_close_both_with_unused_items_forcedcCs�t��}t�|�|�tj��t�|d�Wd�n1s@0Y|�tj��t�|�Wd�n1sv0YdSr�)rr�rvr�rDrrrsr]rrr�test_close_never_used�s
*z"ChannelTests.test_close_never_usedcCs�t��}t�|d�t��}t�|td|�d���|�tj��t�|�Wd�n1s`0Y|�tj��t�	|�Wd�n1s�0YdS)Nrprr�)
rr�rrr8rrr�rDrsrv�r<rlrrrr�!test_close_by_unassociated_interp�s
�(z.ChannelTests.test_close_by_unassociated_interpcCs�t��}t�|d�t�|d�t�|d�t�|�tj|dd�|�tj��t�|d�Wd�n1sr0Y|�tj��t�|�Wd�n1s�0YdS)NrpTrgr�r�r]rrr�-test_close_used_multiple_times_by_single_user�s
*z:ChannelTests.test_close_used_multiple_times_by_single_usercCs�t��}|�tj��tjddd�Wd�n1s80Yt�|�|�tj��tj|dd�Wd�n1s|0YdS)Nr�Trk)rr�r�r}rlrvrDr]rrr�.test_channel_list_interpreters_invalid_channel�s,
z;ChannelTests.test_channel_list_interpreters_invalid_channelcCs@t��}|�t��t�|�Wd�n1s20YdSr)rr�r�r�rlr]rrr�+test_channel_list_interpreters_invalid_args�sz8ChannelTests.test_channel_list_interpreters_invalid_argsN)*r?r@rArhrirjrorsrwryr}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�rrrrrg�sL	+$	
	



	

rgc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�ChannelReleaseTestsa�
    - main / interp / other
    - run in: current thread / new thread / other thread / different threads
    - end / opposite
    - force / no force
    - used / not used  (associated / not associated)
    - empty / emptied / never emptied / partly emptied
    - closed / not closed
    - released / not released
    - creator (interp) / other
    - associated interpreter not running
    - associated interpreter destroyed
    cCs�t��}t�|d�t�|�tj|ddd�|�tj��t�|d�Wd�n1s\0Y|�tj��t�|�Wd�n1s�0YdS�NrpTrcr��rr�rrrsr|r�rDr]rrr�test_single_user�s
*z$ChannelReleaseTests.test_single_usercCsxt��}t��}t��}t�|td|�d���t|td|�d|�d���}t�|td|�d���|�|��d�dS)	Nrtr�rpz,)
            _interpreters.channel_release(z+)
            print(repr(obj))
            z+
            _interpreters.channel_release(rzb'spam')rr�r8rrrr�r�)r<rlr�r�r�rrr�test_multiple_users�s
���
�z'ChannelReleaseTests.test_multiple_userscCs�t��}t�|d�t�|�t�|�|�tj��t�|d�Wd�n1sV0Y|�tj��t�|�Wd�n1s�0YdSr�r�r]rrr�test_no_kwargss

*z"ChannelReleaseTests.test_no_kwargscCsnt��}t�|d�t�|�tj|ddd�|�tj�� tj|ddd�Wd�n1s`0YdS)NrpTrcr�r]rrr�test_multiple_timess
z'ChannelReleaseTests.test_multiple_timescCsjt��}t�|d�t�|d�tj|ddd�|�tj��t�|�Wd�n1s\0YdS)Nrpr8Trc)rr�rrr|r�rDrsr]rrr�test_with_unused_itemssz*ChannelReleaseTests.test_with_unused_itemscCs�t��}t�|�|�tj��t�|d�Wd�n1s@0Y|�tj��t�|�Wd�n1sv0YdSr�)rr�r|r�rDrrrsr]rrr�test_never_used#s
*z#ChannelReleaseTests.test_never_usedcCs�t��}t�|d�t��}t�|td|�d���t�|�}t�|�|�tj	��t�|d�Wd�n1sv0Y|�
|d�dS)Nrpr{rr�)rr�rrr8rrrsr|r�rDr�)r<rlrr�rrr�test_by_unassociated_interp,s
�

*z/ChannelReleaseTests.test_by_unassociated_interpc	Csht��}t��}t�|td|�d|�d���|�tj��t�|�Wd�n1sZ0YdS)Nze
            import _xxsubinterpreters as _interpreters
            obj = _interpreters.channel_send(z5, b'spam')
            _interpreters.channel_release(r)rr�r8rrr�rDrsr�rrr�test_close_if_unassociated;s
��z.ChannelReleaseTests.test_close_if_unassociatedcCsRt��}t�|d�t�|�t�|d�tj|dd�t�|�}|�|d�dS)NrpTrk)rr�rrrsr|r�)r<rlr�rrr�test_partiallyHs

z"ChannelReleaseTests.test_partiallycCs�t��}t�|d�t�|d�t�|d�t�|�tj|ddd�|�tj��t�|d�Wd�n1st0Y|�tj��t�|�Wd�n1s�0YdSr�r�r]rrr�'test_used_multiple_times_by_single_userSs
*z;ChannelReleaseTests.test_used_multiple_times_by_single_userN)r?r@rAr�r�r�r�r�r�r�r�r�r�r�rrrrr��s'			
r�cszeZdZdZ�fdd�Zedd��Zedd��Zdd	�Zddd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Z�ZS)�ChannelCloseFixtureFcsx|jri}n4t�|�}t�|�}t�|�}|j||j||j|i}|sHd}t��||||||�}t�|_t�|_	||_
|S)NrL)�QUICKr.r4r;r9r:r��_preppedr\�_state�_known)r2rJrrSrT�creatorZknownr<r=rrr:hs 


�zChannelCloseFixture.__new__cCs|jSr�r�rdrrrrm}szChannelCloseFixture.statecCs>z|jWSty8|�|j�}|�|�|_|jYS0dSr)�_cid�AttributeError�_get_interpreterr��_new_channel)r<r�rrrrl�szChannelCloseFixture.cidcCs|�|�}|�|�|Sr)r��_prep_interpreterr�rrr�get_interpreter�s

z#ChannelCloseFixture.get_interpreterNcCs2|dur|j}|dkr&|jjdkr&dSt|jj�S)NrOrNF)rJrmr^�boolrYrrr�expect_closed_error�s
z'ChannelCloseFixture.expect_closed_errorcCs|�|�dSr)r�r�rrr�prep_interpreter�sz$ChannelCloseFixture.prep_interpretercCs
||_dSrr�)r<rIrnrrr�
record_action�sz!ChannelCloseFixture.record_actioncCst�t�dSrr�rdrrr�clean_up�szChannelCloseFixture.clean_upcCs@|jdkrt��St��}t|jd|�d��t�|�|_|jS)Nr-a
                import _xxsubinterpreters
                cid = _xxsubinterpreters.channel_create()
                # We purposefully send back an int to avoid tying the
                # channel to the other interpreter.
                _xxsubinterpreters.channel_send(zC, int(cid))
                del _xxsubinterpreters
                )r;rr�r(r&rsr�)r<r�Zchrrrr��s
�
z ChannelCloseFixture._new_channelcCsj|dvr|jS|dkr|jS|dkr*|jS|}z|j|}Wn$ty`t|�}|j|<Yn0|SdS)N)rLrrSrT)rrSrTr��KeyErrorr.)r<rr;rrrr��sz$ChannelCloseFixture._get_interpretercCsF|j|jvrdS|j�|j�|jdkr,dSt|jd|j�d��dS)Nr-a
            import _xxsubinterpreters as interpreters
            import test.test__xxsubinterpreters as helpers
            ChannelState = helpers.ChannelState
            try:
                cid
            except NameError:
                cid = interpreters._channel_id(r)r&r�r�r;r(rlr�rrrr��s
�z%ChannelCloseFixture._prep_interpreter)N)r?r@rAr�r:�propertyrmrlr�r�r�r�r�r�r�r�rCrrr=rr�as


r�zend interp other extra creatorz%these tests take several hours to runc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�dd�Z	dd�Z
dd�Zd"dd�Zdd�Z
d#dd�Zdd�Zdd�Zd d!�ZdS)$�ExhaustiveChannelTestsa�
    - main / interp / other
    - run in: current thread / new thread / other thread / different threads
    - end / opposite
    - force / no force
    - used / not used  (associated / not associated)
    - empty / emptied / never emptied / partly emptied
    - closed / not closed
    - released / not released
    - creator (interp) / other
    - associated interpreter not running
    - associated interpreter destroyed

    - close after unbound
    ccs�gV|�dd�D]"}|V|��D]}||Vq$q|�dd�D]"}|V|��D]}||VqTqB|�dd�D]z}|V|�dd�D]*}||}|V|��D]}||Vq�q�|�dd�D]*}||}|V|��D]}||Vq�q�qr|�dd�D]�}|V|�dd�D].}||}|V|��D]}||V�q*�q|�dd�D].}||}|V|��D]}||V�qf�qLq�dS)NrLrSrT)�_iter_close_action_sets�_iter_post_close_action_sets�_iter_use_action_sets)r<ZcloseactionsZpostactionsZ
useactions�actionsrrr�iter_action_sets�sBz'ExhaustiveChannelTests.iter_action_setsccs||f}tdd|�gVtdd|�gVtdd|�tdd|�gVtdd|�gVtdd|�gVtdd|�tdd|�gV|D]<}|D]2}|D](}tdd|�tdd|�tdd|�gVq�q�q�|D]P}|D]F}|D]<}|D]2}tdd|�tdd|�tdd|�tdd|�gVq�q�q�q�dS)NrKrOrN�rF)r<rrru�interpsrvZinterp4rrrr�*s>
�
�

�
�
�

�


�



�z,ExhaustiveChannelTests._iter_use_action_setsc
	cs�d}||f}dD]4}|rdnd}|D]}|D]}t|||�gVq,q$qdD]<}	dD]2}
|D](}|D]}t|	d|�t|
d|�gVqbqZqRqJdS)Nrqr�rRrQrPrOrNr�)
r<rrruZendsr�rh�oprrJZrecvopZsendoprOrNrrrr�[s
�

�z.ExhaustiveChannelTests._iter_close_action_setsccs.dD]$}tdd|�gVtdd|�gVqdS)N)rLrTrSrKrOrNr�r�rrrr�ns

�
�z3ExhaustiveChannelTests._iter_post_close_action_setscCs|D]}|�||�qdSr)ro)r<�fixr�rIrrr�run_actionswsz"ExhaustiveChannelTests.run_actionsTricCs�|�|j�}|�|j|j|j�}|�|�|jdkrZt|j	|j
||j|d�}|�||�n�t
��}t|jd|j	�dt|j
��dt|��dt|j��d|�d|�d|�d��tt�t
�|�d	�tt
�|��d
�}|�||�dS)Nr-rizB
                result = helpers.run_action(
                    z,
                    z!,
                    hideclosed=zB,
                    )
                interpreters.channel_send(zR, result.pending.to_bytes(1, 'little'))
                interpreters.channel_send(z2, b'X' if result.closed else b'')
                r�)r_r^)rZrJr[rrSrTr�r;rorlrIrmr�rr�r(r&r�r\r��
from_bytesrsr�)r<r�rIrjrJrrnr�rrrro{sB

��������
�z!ExhaustiveChannelTests.run_actionc	csBgd�}|D]0\}}}dD] }dD]}t|||||�Vq"qqdS)N))r-rrT)rr-rT)rrrurT)rrrur-)rLrSr�rc)r�)r<rrrSrTr�rJrrr�
iter_fixtures�s
z$ExhaustiveChannelTests.iter_fixturescCst|rdnd}t||jd�}|��s4|j||dd�n<|�tj�� |j||dd�Wd�n1sf0YdS)NrRrQrLFri)rFrJr�ror�rrD)r<r�rhr�rQrrr�_close�szExhaustiveChannelTests._closeNcCs.|dus|jdkr�|�tj��t�|j�Wd�n1s@0Y|�tj��t�|jd�Wd�n1sz0Y|�tj��t�|j�Wd�n1s�0Y|�tj�� tj|jdd�Wd�n1s�0Yn0t|j	d�t|j	d�t|j	d�t|j	d�dS)	Nr-rpTrgzz
                with helpers.expect_channel_closed():
                    interpreters.channel_recv(cid)
                z�
                with helpers.expect_channel_closed():
                    interpreters.channel_send(cid, b'spam')
                z{
                with helpers.expect_channel_closed():
                    interpreters.channel_close(cid)
                z�
                with helpers.expect_channel_closed():
                    interpreters.channel_close(cid, force=True)
                )
r;r�rrDrsrlrrrvr(r&)r<r�rrrr�_assert_closed_in_interp�s*,*0z/ExhaustiveChannelTests._assert_closed_in_interpcCs||�|jj�t|jj�D]}t�|j�q|�|�dD]&}|�	|�}|j
dkrTq:|�||�q:|�	d�}|�||�dS)N)rLrSr-Zfresh)r�rmr^r�r_rrsrlr�r�r;)r<r�r�rrrr�_assert_closed�s



z%ExhaustiveChannelTests._assert_closedFc	cs�d}|��D]�}t�|��D]�}|d7}|dkr:dS|rl|dddkrTt�t||d�t|���n2|dddkr�tddd�td	dd�tj��|||fVq|rtd
�qt�dS)Nrrar��z({} actions)� r�rX�.z---)r��printr�r6r�r��stdoutr")r<�verboser�r�r�rrr�_iter_close_tests�s$
z(ExhaustiveChannelTests._iter_close_testscCsdt_|��D]
\}}}qdS)NT)r�r�r��r<r�r�r�rrr�_skim_close_tests�sz(ExhaustiveChannelTests._skim_close_testsc	Cs�|��D]v\}}}|�d�|||���@|�|j�|�||�|j|dd�|�|�Wd�n1sl0Y|��qdS)N�	{} {}  {}Frg�	r�r�r6r�rr�r�r�r�r�rrr�
test_close�s(z!ExhaustiveChannelTests.test_closec	Cs�|��D]v\}}}|�d�|||���@|�|j�|�||�|j|dd�|�|�Wd�n1sl0Y|��qdS)Nr�Trgr�r�rrr�test_force_close	s(z'ExhaustiveChannelTests.test_force_close)N)F)r?r@rAr�r�r�r�r�r�ror�r�r�r�r�r�r�r�rrrrr��s(-1	 
	

r�rL)N)4�collectionsrrYr�rr?r��textwraprrr�r�testrZtest.supportr�
import_modulerrrrZr$r(r%r.rErFr\rorkrzrZTestCaser�r�r�r�r�r�r�r�r�r	rr[rgr�r�rr�r?r-rrrr�<module>sr


&
	3$

2?(;]b7Y:&�q@


Kontol Shell Bypass