403Webshell
Server IP : 118.27.122.248  /  Your IP : 216.73.216.238
Web Server : Apache
System : Linux web0264.sh.tyo1 4.18.0-553.79.1.lve.el7h.x86_64 #1 SMP Wed Oct 15 16:34:46 UTC 2025 x86_64
User : c9415830 ( 11735)
PHP Version : 8.4.17
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python36/lib64/python3.6/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python36/lib64/python3.6/test/__pycache__/test_contextlib.cpython-36.pyc
3

�w2_{�
@sVdZddlZddlZddlZddlZddlTddlmZyddlZWne	k
r\dZYnXGdd�dej
�ZGdd�dej
�ZGd	d
�d
ej
�Z
Gdd�dej
�Zejed
�Gdd�dej
��ZGdd�de�ZGdd�dej
�ZGdd�dej
�ZGdd�d�ZGdd�deej
�ZGdd�deej
�ZGdd�dej
�Zedk�rRej�dS)z9Unit tests for contextlib.py, and other context managers.�N)�*)�supportc@s$eZdZdd�Zdd�Zdd�ZdS)�TestAbstractContextManagercCs*Gdd�dt�}|�}|j|j�|�dS)NcseZdZ�fdd�Z�ZS)z;TestAbstractContextManager.test_enter.<locals>.DefaultEntercst�j|�dS)N)�super�__exit__)�self�args)�	__class__��9/opt/alt/python36/lib64/python3.6/test/test_contextlib.pyrszDTestAbstractContextManager.test_enter.<locals>.DefaultEnter.__exit__)�__name__�
__module__�__qualname__r�
__classcell__r
r
)r	r�DefaultEntersr)�AbstractContextManager�assertIs�	__enter__)rrZmanagerr
r
r�
test_entersz%TestAbstractContextManager.test_enterc	Cs0Gdd�dt�}|jt��|�WdQRXdS)Nc@seZdZdS)zETestAbstractContextManager.test_exit_is_abstract.<locals>.MissingExitN)rr
rr
r
r
r�MissingExitsr)r�assertRaises�	TypeError)rrr
r
r�test_exit_is_abstractsz0TestAbstractContextManager.test_exit_is_abstractcCs�Gdd�d�}|jt|t��Gdd�dt�}|jt|t��Gdd�d|�}|jt|t��Gdd�d|�}|jt|t��dS)	Nc@seZdZdd�Zdd�ZdS)zRTestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratchcSs|S)Nr
)rr
r
rr"sz\TestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__enter__cSsdS)Nr
)r�exc_type�	exc_value�	tracebackr
r
rr$sz[TestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__exit__N)rr
rrrr
r
r
r�ManagerFromScratch!srcseZdZ�fdd�Z�ZS)zLTestAbstractContextManager.test_structural_subclassing.<locals>.DefaultEntercst�j|�dS)N)rr)rr)r	r
rr*szUTestAbstractContextManager.test_structural_subclassing.<locals>.DefaultEnter.__exit__)rr
rrrr
r
)r	rr)src@seZdZdZdS)zGTestAbstractContextManager.test_structural_subclassing.<locals>.NoEnterN)rr
rrr
r
r
r�NoEnter/src@seZdZdZdS)zFTestAbstractContextManager.test_structural_subclassing.<locals>.NoExitN)rr
rrr
r
r
r�NoExit4sr)�
assertTrue�
issubclassr�assertFalse)rrrrrr
r
r�test_structural_subclassing sz6TestAbstractContextManager.test_structural_subclassingN)rr
rrrr"r
r
r
rrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Ze
jdd��Ze
jdd��Zdd�ZdS)�ContextManagerTestCasecs`g�t�fdd��}|��*}|j�dg�|j|d��j|�WdQRX|j�dddg�dS)Nc3s�jd�dV�jd�dS)N��*i�)�appendr
)�stater
r�woohoo>s
z@ContextManagerTestCase.test_contextmanager_plain.<locals>.woohoor$r%i�)�contextmanager�assertEqualr&)rr(�xr
)r'r�test_contextmanager_plain<sz0ContextManagerTestCase.test_contextmanager_plaincs|g�t�fdd��}|jt��B|��0}|j�dg�|j|d��j|�t��WdQRXWdQRX|j�dddg�dS)Nc3s&�jd�z
dVWd�jd�XdS)Nr$r%i�)r&r
)r'r
rr(Ks

zBContextManagerTestCase.test_contextmanager_finally.<locals>.woohoor$r%i�)r)r�ZeroDivisionErrorr*r&)rr(r+r
)r'r�test_contextmanager_finallyIs
z2ContextManagerTestCase.test_contextmanager_finallycCs6tdd��}|�}|j�|j|jttd�d��dS)Ncss
dVdS)Nr
r
r
r
r�whee[szCContextManagerTestCase.test_contextmanager_no_reraise.<locals>.whee�foo)r)rr!rr)rr/�ctxr
r
r�test_contextmanager_no_reraiseZsz5ContextManagerTestCase.test_contextmanager_no_reraisecCs6tdd��}|�}|j�|jt|jttd�d�dS)Nc	ss"y
dVWndVYnXdS)Nr
r
r
r
r�whoods
zOContextManagerTestCase.test_contextmanager_trap_yield_after_throw.<locals>.whoor0)r)rr�RuntimeErrorrr)rr3r1r
r
r�*test_contextmanager_trap_yield_after_throwcs
zAContextManagerTestCase.test_contextmanager_trap_yield_after_throwcsjg�t��fdd��}|��2}�j�dg��j|d��j|�td��WdQRX�j�dddg�dS)Nc3s^�jd�y
dVWnDtk
rX}z(�j|jd��j�dddg�WYdd}~XnXdS)Nr$r%ri�)r&r-rr*)�e)rr'r
rr(rs

zAContextManagerTestCase.test_contextmanager_except.<locals>.woohoor$r%i�)r)r*r&r-)rr(r+r
)rr'r�test_contextmanager_exceptps
z1ContextManagerTestCase.test_contextmanager_exceptcCs�td�}tdd��}y2|jtd��|��
|�WdQRXWdQRXWn.tk
rt}z|j||�WYdd}~XnX|jd�dS)N�spamcss
dVdS)Nr
r
r
r
rr(�szJContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.woohoo�
StopIterationzStopIteration was suppressed)r9r)ZassertWarnsRegex�DeprecationWarning�	Exceptionr�fail)r�stop_excr(�exr
r
r�#test_contextmanager_except_stopiter�sz:ContextManagerTestCase.test_contextmanager_except_stopitercCs|d}i}t|||�|d}td�}y|��
|�WdQRXWn.tk
rl}z|j||�WYdd}~XnX|jd�dS)Nztfrom __future__ import generator_stop
from contextlib import contextmanager
@contextmanager
def woohoo():
    yield
r(r8zStopIteration was suppressed)�execr9r;rr<)r�code�localsr(r=r>r
r
r�!test_contextmanager_except_pep479�sz8ContextManagerTestCase.test_contextmanager_except_pep479cCs�tdd��}y|��
t�WdQRXWnRtk
rx}z6|jt|�t�|j|jdd�|j|j	t�WYdd}~XnXy|��t
d��WdQRXWnPtk
r�}z4|jt|�t
�|j|jdd�|j|j	�WYdd}~XnXdS)Ncss<y
dVWn,tk
r6}ztd�|�WYdd}~XnXdS)Nzissue29692:Chained)r;r4)�excr
r
r�test_issue29692�s
zoContextManagerTestCase.test_contextmanager_do_not_unchain_non_stopiteration_exceptions.<locals>.test_issue29692rzissue29692:Chainedzissue29692:Unchained)r)r-r;r�typer4r*r�assertIsInstance�	__cause__r9�assertIsNone)rrEr>r
r
r�?test_contextmanager_do_not_unchain_non_stopiteration_exceptions�s zVContextManagerTestCase.test_contextmanager_do_not_unchain_non_stopiteration_exceptionscCs"dd�}t|dd�dd���}|S)Ncs�fdd�}|S)Ncs&x �j�D]\}}t|||�q
W|S)N)�items�setattr)�func�k�v)�kwr
r�decorate�szXContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs.<locals>.decorater
)rPrQr
)rPr�attribs�szFContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs�bar)r0cSsdS)zWhee!Nr
)r8r
r
r�baz�szBContextManagerTestCase._create_contextmanager_attribs.<locals>.baz)r))rrRrTr
r
r�_create_contextmanager_attribs�sz5ContextManagerTestCase._create_contextmanager_attribscCs(|j�}|j|jd�|j|jd�dS)NrTrS)rUr*rr0)rrTr
r
r�test_contextmanager_attribs�sz2ContextManagerTestCase.test_contextmanager_attribscCs|j�}|j|jd�dS)NzWhee!)rUr*�__doc__)rrTr
r
r�test_contextmanager_doc_attrib�sz5ContextManagerTestCase.test_contextmanager_doc_attribcCs|j�d�}|j|jd�dS)NzWhee!)rUr*rW)rrTr
r
r�*test_instance_docstring_given_cm_docstring�szAContextManagerTestCase.test_instance_docstring_given_cm_docstringc
Cs8tdd��}|ddddd��}|j|d�WdQRXdS)	Ncss||||fVdS)Nr
)rrMr�kwdsr
r
rr(�sz4ContextManagerTestCase.test_keywords.<locals>.woohoo���!�,)rrMrrZ)r[r\r]r^)r)r*)rr(�targetr
r
r�
test_keywords�sz$ContextManagerTestCase.test_keywordsN)rr
rr,r.r2r5r7r?rCrJrUrVr�requires_docstringsrXrYr`r
r
r
rr#:s
	

r#c@s*eZdZejdd��Zdd�Zdd�ZdS)�ClosingTestCasecCs tj}td�}|j|j|�dS)N)�closingrWr*)r�cm_docstring�objr
r
r�test_instance_docs�sz"ClosingTestCase.test_instance_docsc
sZg�G�fdd�d�}|�}|j�g�t|��}|j||�WdQRX|j�dg�dS)NcseZdZ�fdd�ZdS)z'ClosingTestCase.test_closing.<locals>.Ccs�jd�dS)Nr$)r&)r)r'r
r�close�sz-ClosingTestCase.test_closing.<locals>.C.closeN)rr
rrgr
)r'r
r�C�srhr$)r*rc)rrhr+�yr
)r'r�test_closing�s
zClosingTestCase.test_closingcsxg�G�fdd�d�}|�}|j�g�|jt��.t|��}|j||�ddWdQRXWdQRX|j�dg�dS)NcseZdZ�fdd�ZdS)z-ClosingTestCase.test_closing_error.<locals>.Ccs�jd�dS)Nr$)r&)r)r'r
rrg�sz3ClosingTestCase.test_closing_error.<locals>.C.closeN)rr
rrgr
)r'r
rrh�srhr$r)r*rr-rc)rrhr+rir
)r'r�test_closing_error�s
z"ClosingTestCase.test_closing_errorN)rr
rrrarfrjrkr
r
r
rrb�srbc@seZdZdd�ZdS)�FileContextTestCasecCs�tj�}z�d}t|d��}|j|j�|jd�WdQRX|j|j�d}|jt��@t|d��*}|j|j�|j	|j
�d�ddWdQRXWdQRX|j|j�Wdtj|�XdS)N�wzBooh
�rr$r)
�tempfileZmktemp�openr!�closed�writerrr-r*�readr�unlink)rZtfn�fr
r
r�testWithOpensz FileContextTestCase.testWithOpenN)rr
rrvr
r
r
rrlsrlz!Threading required for this test.c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�LockContextTestCasecCs~|j|��|�|j|��WdQRX|j|��|jt��*|�|j|��ddWdQRXWdQRX|j|��dS)Nr$r)r!rrr-)r�lock�lockedr
r
r�boilerPlateszLockContextTestCase.boilerPlatecCstj�}|j||j�dS)N)�	threadingZLockrzry)rrxr
r
r�testWithLock$sz LockContextTestCase.testWithLockcCstj�}|j||j�dS)N)r{�RLockrz�	_is_owned)rrxr
r
r�
testWithRLock(sz!LockContextTestCase.testWithRLockcs$tj���fdd�}|j�|�dS)Ncs�j�S)N)r~r
)rxr
rry.sz5LockContextTestCase.testWithCondition.<locals>.locked)r{Z	Conditionrz)rryr
)rxr�testWithCondition,sz%LockContextTestCase.testWithConditioncs$tj���fdd�}|j�|�dS)Ncs�jd�r�j�dSdSdS)NFT)�acquire�releaser
)rxr
rry4s
z5LockContextTestCase.testWithSemaphore.<locals>.locked)r{Z	Semaphorerz)rryr
)rxr�testWithSemaphore2sz%LockContextTestCase.testWithSemaphorecs$tj���fdd�}|j�|�dS)Ncs�jd�r�j�dSdSdS)NFT)r�r�r
)rxr
rry>s
z<LockContextTestCase.testWithBoundedSemaphore.<locals>.locked)r{ZBoundedSemaphorerz)rryr
)rxr�testWithBoundedSemaphore<sz,LockContextTestCase.testWithBoundedSemaphoreN)	rr
rrzr|rr�r�r�r
r
r
rrws
rwc@s,eZdZdZdZdZdZdd�Zdd�ZdS)�	mycontextz9Example decoration-compatible context manager for testingFNcCs
d|_|S)NT)�started)rr
r
rrMszmycontext.__enter__cGs||_|jS)N)rD�catch)rrDr
r
rrQszmycontext.__exit__)	rr
rrWr�rDr�rrr
r
r
rr�Gsr�c@sbeZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�ZdS)�TestContextDecoratorcCstj}t�}|j|j|�dS)N)r�rWr*)rrdrer
r
rrfXsz'TestContextDecorator.test_instance_docscCs@t�}|�}|j||�|j|j�WdQRX|j|jd�dS)N)NNN)r�rrr�r*rD)r�context�resultr
r
r�test_contextdecorator_s
z*TestContextDecorator.test_contextdecoratorcCs�t�}|jtd��|�td��WdQRXWdQRX|j|j�|j|jdt�t�}d|_|�td��WdQRX|j|j�|j|jdt�dS)Nr0rT)r��assertRaisesRegex�	NameError�assertIsNotNonerDrr�)rr�r
r
r�$test_contextdecorator_with_exceptionhsz9TestContextDecorator.test_contextdecorator_with_exceptioncs0t�����fdd��}|��j�jd�dS)Ncs�j�j��j�j�dS)N)rIrDrr�r
)r�rr
r�test|sz1TestContextDecorator.test_decorator.<locals>.test)NNN)r�r*rD)rr�r
)r�rr�test_decoratorysz#TestContextDecorator.test_decoratorc
sXt�����fdd��}�jtd��|�WdQRX�j�j��j�jdt�dS)Ncs$�j�j��j�j�td��dS)Nr0)rIrDrr�r�r
)r�rr
rr��sz@TestContextDecorator.test_decorator_with_exception.<locals>.testr0r)r�r�r�r�rDr)rr�r
)r�rr�test_decorator_with_exception�sz2TestContextDecorator.test_decorator_with_exceptioncs�t��G�fdd�dt�}|�}|jdd�|j|jd�|j|jd�|j|jd�|�}|jddd�|j|jd�|j|jd�|j|jd�|�}|jddd�|j|jd�|j|jd�dS)	NcseZdZ�ddd��ZdS)z9TestContextDecorator.test_decorating_method.<locals>.TestNcSs||_||_||_dS)N)�a�b�c)rr�r�r�r
r
r�method�sz@TestContextDecorator.test_decorating_method.<locals>.Test.method)N)rr
rr�r
)r�r
r�Test�sr�r$�r�r�r�)r�r�)r��objectr�r*r�r�r�)rr�r�r
)r�r�test_decorating_method�s 	z+TestContextDecorator.test_decorating_methodcCs<Gdd�dt�}|jt��|��WdQRXWdQRXdS)Nc@seZdZdd�Zdd�ZdS)z7TestContextDecorator.test_typo_enter.<locals>.mycontextcSsdS)Nr
)rr
r
r�	__unter__�szATestContextDecorator.test_typo_enter.<locals>.mycontext.__unter__cWsdS)Nr
)rrDr
r
rr�sz@TestContextDecorator.test_typo_enter.<locals>.mycontext.__exit__N)rr
rr�rr
r
r
rr��sr�)�ContextDecoratorr�AttributeError)rr�r
r
r�test_typo_enter�sz$TestContextDecorator.test_typo_entercCs<Gdd�dt�}|jt��|��WdQRXWdQRXdS)Nc@seZdZdd�Zdd�ZdS)z6TestContextDecorator.test_typo_exit.<locals>.mycontextcSsdS)Nr
)rr
r
rr�sz@TestContextDecorator.test_typo_exit.<locals>.mycontext.__enter__cWsdS)Nr
)rrDr
r
r�__uxit__�sz?TestContextDecorator.test_typo_exit.<locals>.mycontext.__uxit__N)rr
rrr�r
r
r
rr��sr�)r�rr�)rr�r
r
r�test_typo_exit�sz#TestContextDecorator.test_typo_exitcsRGdd�dt�}Gdd�d|t�}|�����fdd��}|��j�jd�dS)Nc@s$eZdZdZdZdd�Zdd�ZdS)zHTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontextFNcSs
d|_|S)NT)r�)rr
r
rr�szRTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__enter__cWs
||_dS)N)rD)rrDr
r
rr�szQTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__exit__)rr
rr�rDrrr
r
r
r�somecontext�sr�c@seZdZdS)zFTestContextDecorator.test_contextdecorator_as_mixin.<locals>.mycontextN)rr
rr
r
r
rr��sr�cs�j�j��j�j�dS)N)rIrDrr�r
)r�rr
rr��szATestContextDecorator.test_contextdecorator_as_mixin.<locals>.test)NNN)r�r�r*rD)rr�r�r�r
)r�rr�test_contextdecorator_as_mixin�sz3TestContextDecorator.test_contextdecorator_as_mixincsft�fdd��}g�|d���fdd��}|d��j�dddg�g�|d��j�dddg�dS)	Nc3s�j|�dV�jd�dS)Ni�)r&)ri)r'r
rr(�s
zETestContextDecorator.test_contextmanager_as_decorator.<locals>.woohoor$cs�j�dg��j|�dS)Nr$)r*r&)r+)rr'r
rr��szCTestContextDecorator.test_contextmanager_as_decorator.<locals>.testZ	somethingi�zsomething else)r)r*)rr(r�r
)rr'r� test_contextmanager_as_decorator�sz5TestContextDecorator.test_contextmanager_as_decoratorN)rr
rrrarfr�r�r�r�r�r�r�r�r�r
r
r
rr�Vs	r�c@s�eZdZejdd��Zdd�Zdd�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'S)(�
TestExitStackcCstj}t�}|j|j|�dS)N)�	ExitStackrWr*)rrdrer
r
rrf�sz TestExitStack.test_instance_docsc	Cst��WdQRXdS)N)r�)rr
r
r�test_no_resources�szTestExitStack.test_no_resourcescsfifdifdifftdd�fdtdd�fd	tdd�fg}g��fdd�}t���}xpt|�D]d\}}|r�|r�|j|f|�|�}n4|r�|j|f|��}n|r�|j|f|�}n
|j|�}|j||�q\Wx<|jD]2}|j|j|�|j|j|j�|j	|j
|j
�q�WWdQRX|j�|�dS)
Nr$r�)Zexamplecs�j||f�dS)zTest metadata propagationN)r&)rrZ)r�r
r�_exit
sz*TestExitStack.test_callback.<locals>._exit)r$)r$r�)r$)r$r�)�dictr��reversed�callbackr�_exit_callbacks�__wrapped__ZassertNotEqualrrIrWr*)rZexpectedr��stackrrZru�wrapperr
)r�r�
test_callbacks.
zTestExitStack.test_callbackc
st���fdd�}dd�}�fdd�}Gdd�dt�}t���}|j|��j|jd|�||�}|j|��j|jdj|�|j|��j|jd
|�||�}|j|��j|jdj|�|j|��j|jd|�|j|��j|jd|�d	d
WdQRXdS)Ncs�j|��dS)N)r)rrD�exc_tb)�
exc_raisedrr
r�_expect_exc#sz,TestExitStack.test_push.<locals>._expect_exccWsdS)NTr
)�exc_detailsr
r
r�
_suppress_exc%sz.TestExitStack.test_push.<locals>._suppress_exccs"�j|��j|��j|�dS)N)rI)rrDr�)rr
r�
_expect_ok's

z+TestExitStack.test_push.<locals>._expect_okc@s$eZdZdd�Zdd�Zdd�ZdS)z'TestExitStack.test_push.<locals>.ExitCMcSs
||_dS)N)�	check_exc)rr�r
r
r�__init__,sz0TestExitStack.test_push.<locals>.ExitCM.__init__cSs|jd�dS)NzShould not be called!)r<)rr
r
rr.sz1TestExitStack.test_push.<locals>.ExitCM.__enter__cWs|j|�dS)N)r�)rr�r
r
rr0sz0TestExitStack.test_push.<locals>.ExitCM.__exit__N)rr
rr�rrr
r
r
r�ExitCM+sr�r$r���r�r�r�r�r�)r-r�r��pushrr��__self__)rr�r�r�r�r��cmr
)r�rr�	test_push!s*





zTestExitStack.test_pushc
s�G�fdd�dt�}g�|�}t��J}|j�fdd��}|j|�|j|�|j|jd	j|��jd�WdQRX|j	�ddddg�dS)
Ncs$eZdZ�fdd�Z�fdd�ZdS)z0TestExitStack.test_enter_context.<locals>.TestCMcs�jd�dS)Nr$)r&)r)r�r
rrEsz:TestExitStack.test_enter_context.<locals>.TestCM.__enter__cs�jd�dS)N�)r&)rr�)r�r
rrGsz9TestExitStack.test_enter_context.<locals>.TestCM.__exit__N)rr
rrrr
)r�r
r�TestCMDsr�cs�jd�dS)N�)r&r
)r�r
rr�Msz/TestExitStack.test_enter_context.<locals>._exitr$r�r�r�r�)
r�r�r�r��
enter_contextrr�r�r&r*)rr�r�r�r�r
)r�r�test_enter_contextCs

z TestExitStack.test_enter_contextcsXg�t��4}|j�fdd��}|j|�|j��jd�WdQRX|j�ddg�dS)Ncs�jd�dS)Nr$)r&r
)r�r
rr�Ysz'TestExitStack.test_close.<locals>._exitr�r$)r�r�r�rgr&r*)rr�r�r
)r�r�
test_closeVs
zTestExitStack.test_closecslg�t��4}|j�fdd��}|j|�|j�}�jd�WdQRX�jd�|j�|j�dddg�dS)Ncs�jd�dS)Nr�)r&r
)r�r
rr�dsz)TestExitStack.test_pop_all.<locals>._exitr$r�r�)r�r�r��pop_allr&rgr*)rr�r��	new_stackr
)r�r�test_pop_allas

zTestExitStack.test_pop_allcCsB|jt��.t��}|jdd��ddWdQRXWdQRXdS)NcWsdS)NFr
)rDr
r
r�<lambda>qsz/TestExitStack.test_exit_raise.<locals>.<lambda>r$r)rr-r�r�)rr�r
r
r�test_exit_raisenszTestExitStack.test_exit_raisec
Cs,t��}|jdd��ddWdQRXdS)NcWsdS)NTr
)rDr
r
rr�vsz2TestExitStack.test_exit_suppress.<locals>.<lambda>r$r)r�r�)rr�r
r
r�test_exit_suppresstsz TestExitStack.test_exit_suppressc%Cs
Gdd�d�}Gdd�d�}Gdd�d�}y\|t��J|tt��4|��"|t��ddWdQRXWdQRXWdQRXWdQRXWnPtk
r�}z4|j|jt�|j|jjt�|j|jjj�WYdd}~XnX|jd	�|jd}|j|t�|j|jt	�dS)
Nc@s$eZdZdd�Zdd�Zdd�ZdS)zFTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExccSs
||_dS)N)rD)rrDr
r
rr�}szOTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__init__cSs|S)Nr
)rr
r
rrszPTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__enter__cWs
|j�dS)N)rD)rr�r
r
rr�szOTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__exit__N)rr
rr�rrr
r
r
r�RaiseExc|sr�c@s$eZdZdd�Zdd�Zdd�ZdS)zQTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContextcSs||_||_dS)N)�outer�inner)rr�r�r
r
rr��szZTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__init__cSs|S)Nr
)rr
r
rr�sz[TestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__enter__c	Ws"y
|j�Wn|j�YnXdS)N)r�r�)rr�r
r
rr�s
zZTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__exit__N)rr
rr�rrr
r
r
r�RaiseExcWithContext�sr�c@seZdZdd�Zdd�ZdS)zITestExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExccSs|S)Nr
)rr
r
rr�szSTestExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__enter__cWs|t|�_dS)NT)rF�
saved_details)rr�r
r
rr�s
zRTestExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__exit__N)rr
rrrr
r
r
r�SuppressExc�sr�r$rz0Expected IndexError, but no exception was raised)
�
IndexError�KeyErrorr��
ValueErrorrG�__context__rIr<r�r-)rr�r�r�rD�	inner_excr
r
r�&test_exit_exception_chaining_referenceys"

4"

z4TestExitStack.test_exit_exception_chaining_referencecs�dd�}d��fdd�}yXt��H}|j|t�|j|t�|j|t�|j|�|j|t�ddWdQRXWnPtk
r�}z4|j|jt�|j|jjt�|j	|jjj�WYdd}~XnX|j
d��d}|j|t�|j|jt�dS)NcSs|�dS)Nr
)rDr
r
r�	raise_exc�sz=TestExitStack.test_exit_exception_chaining.<locals>.raise_exccs|�dS)NTr
)r�)r�r
r�suppress_exc�sz@TestExitStack.test_exit_exception_chaining.<locals>.suppress_excr$rz0Expected IndexError, but no exception was raised)r�r�r�r�r�r�r�rGr�rIr<r-)rr�r�r�rDr�r
)r�r�test_exit_exception_chaining�s&
"
z*TestExitStack.test_exit_exception_chainingcCs�dd�}dd�}y0t�� }|jdd��|j|t�WdQRXWn.tk
rn}z|j|t�WYdd}~XnX|jd�y8t��(}|j|t�|j|�|j|t�WdQRXWn.tk
r�}z|j|t�WYdd}~XnX|jd�dS)	NcSs|�dS)Nr
)rDr
r
rr��szDTestExitStack.test_exit_exception_non_suppressing.<locals>.raise_exccWsdS)NTr
)r�r
r
rr��szGTestExitStack.test_exit_exception_non_suppressing.<locals>.suppress_exccSsdS)Nr
r
r
r
rr��szCTestExitStack.test_exit_exception_non_suppressing.<locals>.<lambda>z0Expected IndexError, but no exception was raisedz.Expected KeyError, but no exception was raised)r�r�r�r;rGr<r�r�)rr�r�r�rDr
r
r�#test_exit_exception_non_suppressing�s"

z1TestExitStack.test_exit_exception_non_suppressingcCs�tdd��}td�}td�}td�}td�}yDt��4}|j||��|j||��|j||��|�WdQRXWnptk
r�}zT|j||�|j|j|�|j|jj|�|j|jjj|�|j|jjjj�WYdd}~XnXdS)Nc
ssz
dVWd|�XdS)Nr
)rDr
r
r�gets_the_context_right�s
zVTestExitStack.test_exit_exception_with_correct_context.<locals>.gets_the_context_rightr$r�r�r�)r)r;r�r�rr�rI)rr��exc1�exc2�exc3�exc4r�rDr
r
r�(test_exit_exception_with_correct_context�s$z6TestExitStack.test_exit_exception_with_correct_contextc	Cs�dd�}td�}td�}td�}td�}td�}y6t��&}|j|||�|j|||�|�WdQRXWn�tk
r�}zj|j||�|j|j|�|j|jj|�|j|jjj|�|j|jjjj|�|j|jjjjj�WYdd}~XnXdS)Nc
Ssz|�Wd|�XdS)Nr
)r�Z	outer_excr
r
r�raise_nestedszMTestExitStack.test_exit_exception_with_existing_context.<locals>.raise_nestedr$r�r�r��)r;r�r�rr�rI)	rr�r�r�r�r�Zexc5r�rDr
r
r�)test_exit_exception_with_existing_contexts(z7TestExitStack.test_exit_exception_with_existing_contextcCsbdd�}y(t��}|j|�ddWdQRXWn,tk
r\}z|jd�WYdd}~XnXdS)NcWsdS)NTr
)r�r
r
rr�!sz@TestExitStack.test_body_exception_suppress.<locals>.suppress_excr$rz%Expected no exception, got IndexError)r�r�r�r<)rr�r�rDr
r
r�test_body_exception_suppress s
z*TestExitStack.test_body_exception_suppressc
Cs@t��0}|jdd��|jdd��|jdd��WdQRXdS)NcWsdS)NTr
)rDr
r
rr�,szETestExitStack.test_exit_exception_chaining_suppress.<locals>.<lambda>cWsddS)Nr$rr
)rDr
r
rr�-scWsidS)Nr$r
)rDr
r
rr�.s)r�r�)rr�r
r
r�%test_exit_exception_chaining_suppress*sz3TestExitStack.test_exit_exception_chaining_suppressc
Cs2t��"}xtd�D]}|jt�qWWdQRXdS)Ni')r��ranger��int)rr��ir
r
r�test_excessive_nesting0sz$TestExitStack.test_excessive_nestingcCsTGdd�dt�}|�}t�|_t�}|jt|j|�|j|�|j|jd|�dS)Nc@seZdZdS)z3TestExitStack.test_instance_bypass.<locals>.ExampleN)rr
rr
r
r
r�Example7sr�r$r�)	r�rr�rr�r�r�rr�)rr�r�r�r
r
r�test_instance_bypass6s
z"TestExitStack.test_instance_bypasscs�Gdd�dt��Gdd�dt�}t�fdd��}tdd��}|j���8}t��&}|j|��|j|��|d	��WdQRXWdQRX|j}|j|��|j|j|�|j	|jj�|j	|jj
�|j|j
|j�dS)
Nc@seZdZdS)zETestExitStack.test_dont_reraise_RuntimeError.<locals>.UniqueExceptionN)rr
rr
r
r
r�UniqueExceptionAsr�c@seZdZdS)zHTestExitStack.test_dont_reraise_RuntimeError.<locals>.UniqueRuntimeErrorN)rr
rr
r
r
r�UniqueRuntimeErrorBsr�c3s<y
dVWn,tk
r6}z�d�|�WYdd}~XnXdS)Nr$z
new exception)r;)rD)r�r
r�secondDs
z<TestExitStack.test_dont_reraise_RuntimeError.<locals>.secondcss6y
dVWn&tk
r0}z
|�WYdd}~XnXdS)Nr$)r;)rDr
r
r�firstKs
z;TestExitStack.test_dont_reraise_RuntimeError.<locals>.firstzplease no infinite loop.)r;r4r)rr�r�Z	exceptionrGr�rIrHr)rr�r�r�Zerr_ctxZes_ctxrDr
)r�r�test_dont_reraise_RuntimeError?s	z,TestExitStack.test_dont_reraise_RuntimeErrorN)rr
rrrarfr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
r
r
rr��s&"
0
	r�c@sJeZdZdZdZejdd��Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�ZdS)�TestRedirectStreamNcCs$|jj}|jd�}|j|j|�dS)N)�redirect_streamrWr*)rrdrer
r
rrfgs
z%TestRedirectStream.test_instance_docscCs.tt|j�}|jd�|jtt|j�|�dS)N)�getattr�sys�orig_streamr�r)r�orig_stdoutr
r
r�test_no_redirect_in_initns
z+TestRedirectStream.test_no_redirect_in_initcCsrtj�}d}tt|j�}|j|��t|tt|j�d�WdQRX|jtt|j�|�|j�j	�}|j
||�dS)Nz<Consider an API like help(), which prints directly to stdout)�file)�io�StringIOr�r�r�r��printr�getvalue�stripr*)rru�msgr��sr
r
r�test_redirect_to_string_iossz-TestRedirectStream.test_redirect_to_string_ioc
Cs.tj�}|j|��}|j||�WdQRXdS)N)r�r�r�r)rru�enter_resultr
r
r�test_enter_result_is_target}sz.TestRedirectStream.test_enter_result_is_targetcCs�tj�}|j|�}tt|j�}|�tddtt|j�d�WdQRX|�tdtt|j�d�WdQRX|jtt|j�|�|j�}|j	|d�dS)N�Hello� )�endr�zWorld!)r�z
Hello World!
)
r�r�r�r�r�r�r�rr�r*)rru�
write_to_fr�r�r
r
r�test_cm_is_reusable�s
 z&TestRedirectStream.test_cm_is_reusablecCs�tj�}|j|�}tt|j�}|�@tddtt|j�d�|�tdtt|j�d�WdQRXWdQRX|jtt|j�|�|j�}|j	|d�dS)Nrr)rr�zWorld!)r�z
Hello World!
)
r�r�r�r�r�r�r�rr�r*)rrurr�r�r
r
r�test_cm_is_reentrant�s
(z'TestRedirectStream.test_cm_is_reentrant)
rr
rr�r�rrarfr�r�rrrr
r
r
rr�bs
r�c@seZdZeZdZdS)�TestRedirectStdout�stdoutN)rr
r�redirect_stdoutr�r�r
r
r
rr�src@seZdZeZdZdS)�TestRedirectStderr�stderrN)rr
r�redirect_stderrr�r�r
r
r
rr�src@sZeZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�TestSuppresscCstj}t�}|j|j|�dS)N)�suppressrWr*)rrdrer
r
rrf�szTestSuppress.test_instance_docsc	Cs"tt��}|j|�WdQRXdS)N)rr�rI)rrr
r
r�test_no_result_from_enter�s
z&TestSuppress.test_no_result_from_entercCs*tt��|jtdd�d�WdQRXdS)Nr�r�� )rr�r*�pow)rr
r
r�test_no_exception�s
zTestSuppress.test_no_exceptionc	Cs tt��td�WdQRXdS)Nr�)rr�len)rr
r
r�test_exact_exception�s
z!TestSuppress.test_exact_exceptionc	Cs tt��ddWdQRXdS)Nr�2)r�LookupError)rr
r
r�test_exception_hierarchy�s
z%TestSuppress.test_exception_hierarchycCs6|jt��"tt��ddWdQRXWdQRXdS)Nr$r)rr-rr)rr
r
r�test_other_exception�s
z!TestSuppress.test_other_exceptioncCs4|jt�� t��ddWdQRXWdQRXdS)Nr$r)rr-r)rr
r
r�test_no_args�szTestSuppress.test_no_argscCs@ttt��ddWdQRXttt��td�WdQRXdS)Nr$rr�)rr-rr)rr
r
r�test_multiple_exception_args�sz)TestSuppress.test_multiple_exception_argscCsrtt�}|�WdQRX|�td�WdQRX|�*|�td�WdQRXd}ddWdQRX|j|�dS)Nr�Tr$r)rr;rr)rZignore_exceptionsZouter_continuedr
r
rr�s
z!TestSuppress.test_cm_is_reentrantN)rr
rrrarfrrrrrrrrr
r
r
rr�sr�__main__)rWr�r�roZunittest�
contextlibr�rr{�ImportErrorZTestCaserr#rbrlZ
skipUnlessrwr�r�r�r�r�rrrr�mainr
r
r
r�<module>s:
+(!
0!n96


Youez - 2016 - github.com/yon3zu
LinuXploit