U ��.eB� @s�dZddlZddlZddlZddlmZddlmZddddd d d d d g Zedg7Zej dd�dkrnej Z ne� de fddi�Z dd�Zdd�ZGdd�de �ZGdd �d e �ZGdd�de�Zdd�ZGdd�de �ZGdd�de �ZGd d �d e�ZGd!d �d e�ZGd"d �d e �Zej dd#kZe�r@d$d%�Zd&d'�Znd(d%�Zd)d'�Zzdd*lmZWnek �rzeZ Yn Xd+d,�Z Gd-d �d e �Z!Gd.d�de!�Z"Gd/d�de�Z#dS)0zAcontextlib2 - backports and enhancements to the contextlib module�N)�deque��wraps�contextmanager�closing� nullcontext�AbstractContextManager�ContextDecorator� ExitStack�redirect_stdout�redirect_stderr�suppress� ContextStack�)���ABC� __slots__�cCs0||kr dS|�|�|jD]}t||�q|S�N)�append� __bases__� _classic_mro)�C�result�Brr�;/usr/lib/python3.8/site-packages/pip/_vendor/contextlib2.pyrs    rcGsvz |j}Wn"tk r,tt|g��}YnX|D]>}|D],}||jkr:|j|dkrbtSq2q:tSq2dS)NT)�__mro__�AttributeError�tupler�__dict__�NotImplemented)r�methods�mro�methodrrrr�_check_methods$s    r%c@s2eZdZdZdd�Zejdd��Zedd��Z dS) rz,An abstract base class for context managers.cCs|S)z0Return `self` upon entering the runtime context.r��selfrrr� __enter__8sz AbstractContextManager.__enter__cCsdS)z9Raise any exception triggered within the runtime context.Nr)r'�exc_type� exc_value� tracebackrrr�__exit__<szAbstractContextManager.__exit__cCs|tkrt|dd�StS)z.innerr)r'r?r@rr>r�__call__iszContextDecorator.__call__N)r/r0r1r2r:r9rArrrrr Is c@s0eZdZdZdd�Zdd�Zdd�Zdd �Zd S) �_GeneratorContextManagerz%Helper for @contextmanager decorator.cCsJ|||�|_||||_|_|_t|dd�}|dkr@t|�j}||_dS)Nr2)�genr?r<r=�getattr�typer2)r'r?r<r=�docrrr�__init__ts    z!_GeneratorContextManager.__init__cCs|�|j|j|j�Sr)� __class__r?r<r=r&rrrr9�sz%_GeneratorContextManager._recreate_cmcCs.z t|j�WStk r(td��YnXdS)Nzgenerator didn't yield)�nextrC� StopIteration� RuntimeErrorr&rrrr(�s z"_GeneratorContextManager.__enter__c Cs�|dkr8zt|j�Wntk r,YdSXtd��n�|dkrF|�}z|j�|||�td��Wn�tk r�}z||k WY�Sd}~XYnjtk r�}z0||kr�WY�"dStr�|j|kr�WY� dS�W5d}~XYnt��d|k r�YnXdS)Nzgenerator didn't stopz#generator didn't stop after throw()F�) rIrCrJrK�throw�_HAVE_EXCEPTION_CHAINING� __cause__�sys�exc_info)r'rE�valuer+�excrrrr,�s,    z!_GeneratorContextManager.__exit__N)r/r0r1r2rGr9r(r,rrrrrBqs rBcst���fdd��}|S)a�@contextmanager decorator. Typical usage: @contextmanager def some_generator(): try: yield finally: This makes this: with some_generator() as : equivalent to this: try: = finally: cs t�||�Sr)rBr;�r?rr�helper�szcontextmanager..helperr)r?rUrrTrr�sc@s(eZdZdZdd�Zdd�Zdd�ZdS) ra2Context to automatically close something at the end of a block. Code like this: with closing(.open()) as f: is equivalent to this: f = .open() try: finally: f.close() cCs ||_dSr��thing)r'rWrrrrG�szclosing.__init__cCs|jSrrVr&rrrr(�szclosing.__enter__cGs|j��dSr)rW�close)r'rQrrrr,�szclosing.__exit__N�r/r0r1r2rGr(r,rrrrr�sc@s(eZdZdZdd�Zdd�Zdd�ZdS)�_RedirectStreamNcCs||_g|_dSr)� _new_target� _old_targets)r'� new_targetrrrrG�sz_RedirectStream.__init__cCs*|j�tt|j��tt|j|j�|jSr)r\rrDrP�_stream�setattrr[r&rrrr(�sz_RedirectStream.__enter__cCstt|j|j���dSr)r_rPr^r\�pop�r'�exctype�excinst�exctbrrrr,sz_RedirectStream.__exit__)r/r0r1r^rGr(r,rrrrrZ�srZc@seZdZdZdZdS)r aAContext manager for temporarily redirecting stdout to another file. # How to send help() to stderr with redirect_stdout(sys.stderr): help(dir) # How to write help() to a file with open('help.txt', 'w') as f: with redirect_stdout(f): help(pow) �stdoutN�r/r0r1r2r^rrrrr s c@seZdZdZdZdS)r zCContext manager for temporarily redirecting stderr to another file.�stderrNrfrrrrr sc@s(eZdZdZdd�Zdd�Zdd�ZdS) r a?Context manager to suppress specified exceptions After the exception is suppressed, execution proceeds with the next statement following the with statement. with suppress(FileNotFoundError): os.remove(somefile) # Execution still resumes here if the file was already removed cGs ||_dSr)� _exceptions)r'� exceptionsrrrrG)szsuppress.__init__cCsdSrrr&rrrr(,szsuppress.__enter__cCs|dk ot||j�Sr)� issubclassrhrarrrr,/s zsuppress.__exit__NrYrrrrr s rcs�fdd�}|S)Ncs4|j}||krdS|dks*|�kr$q*|}q||_dSr)� __context__)�new_exc�old_exc� exc_context�� frame_excrr�_fix_exception_context@sz3_make_context_fixer.._fix_exception_contextr)rprqrror�_make_context_fixer?s rrcCs<z|dj}|d�Wn tk r6||d_�YnXdS)NrL)rk� BaseException)� exc_details� fixed_ctxrrr�_reraise_with_existing_contextOs    rvcCsdd�S)NcSsdSrr)rlrmrrr�[�z%_make_context_fixer..rrorrrrrZscCs|\}}}td�dS)Nz!raise exc_type, exc_value, exc_tb)�exec)rtr)r*Zexc_tbrrrrv_s )� InstanceTypecCst|�}|tkr|jS|Sr)rErzrH)�objZobj_typerrr� _get_typeksr|c@sXeZdZdZdd�Zdd�Zdd�Zdd �Zd d �Zd d �Z dd�Z dd�Z dd�Z dS)r a�Context manager for dynamic management of a stack of exit callbacks For example: with ExitStack() as stack: files = [stack.enter_context(open(fname)) for fname in filenames] # All opened files will automatically be closed at the end of # the with statement, even if attempts to open files later # in the list raise an exception cCs t�|_dSr)r�_exit_callbacksr&rrrrGszExitStack.__init__cCst|��}|j|_t�|_|S)z?Preserve the context stack by transferring it to a new instance)rEr}r)r'� new_stackrrr�pop_all�s zExitStack.pop_allcs"��fdd�}�|_|�|�dS)z:Helper to correctly register callbacks to __exit__ methodscs��f|��Srr)rt��cm�cm_exitrr� _exit_wrapper�sz.ExitStack._push_cm_exit.._exit_wrapperN)�__self__�push)r'r�r�r�rr�r� _push_cm_exit�szExitStack._push_cm_exitcCsDt|�}z |j}Wn tk r2|j�|�YnX|�||�|S)aRegisters a callback with the standard __exit__ method signature Can suppress exceptions the same way __exit__ methods can. Also accepts any object with an __exit__ method (registering a call to the method instead of the object itself) )r|r,rr}rr�)r'�exit�_cb_type� exit_methodrrrr��s   zExitStack.pushcs$���fdd�}�|_|�|��S)z\Registers an arbitrary callback and arguments. Cannot suppress exceptions. cs����dSrr)r)rS�tb�r<�callbackr=rrr��sz)ExitStack.callback.._exit_wrapper)� __wrapped__r�)r'r�r<r=r�rr�rr��s zExitStack.callbackcCs(t|�}|j}|�|�}|�||�|S)z�Enters the supplied context manager If successful, also pushes its __exit__ method as a callback and returns the result of the __enter__ method. )r|r,r(r�)r'r��_cm_type�_exitrrrr� enter_context�s   zExitStack.enter_contextcCs|�ddd�dS)z$Immediately unwind the context stackN)r,r&rrrrX�szExitStack.closecCs|Srrr&rrrr(�szExitStack.__enter__c Gs�|ddk }t��d}t|�}d}d}|jr�|j��}z||�rNd}d}d}Wq(t��}||d|d�d}|}Yq(Xq(|r�t|�|o�|S)NrrLFT)NNN)rPrQrrr}r`rv) r'rt� received_excrprq�suppressed_exc� pending_raise�cb�new_exc_detailsrrrr,�s(    zExitStack.__exit__N) r/r0r1r2rGrr�r�r�r�rXr(r,rrrrr ss   cs8eZdZdZ�fdd�Zdd�Zdd�Zdd �Z�ZS) rz+Backwards compatibility alias for ExitStackcst�dt�tt|���dS)Nz*ContextStack has been renamed to ExitStack)r6r7r8�superrrGr&�rHrrrG�s�zContextStack.__init__cCs |�|�Sr)r�)r'r�rrr� register_exit�szContextStack.register_exitcOs|j|f|�|�Sr)r�)r'r�r<r=rrr�register�szContextStack.registercCs|��Sr)rr&rrr�preserve�szContextStack.preserve) r/r0r1r2rGr�r�r�� __classcell__rrr�rr�s  c@s*eZdZdZd dd�Zdd�Zdd�ZdS) raMContext manager that does no additional processing. Used as a stand-in for a normal context manager, when a particular block of code is only sometimes used with a normal context manager: cm = optional_cm if condition else nullcontext() with cm: # Perform operation, using optional_cm if condition is True NcCs ||_dSr�� enter_result)r'r�rrrrG�sznullcontext.__init__cCs|jSrr�r&rrrr(sznullcontext.__enter__cGsdSrr)r'�excinforrrr,sznullcontext.__exit__)NrYrrrrr�s )$r2r3rPr6� collectionsr� functoolsr�__all__� version_inforZ_abc_ABC�ABCMeta�objectrr%rr rBrrrZr r r rNrrrv�typesrz� ImportErrorrEr|r rrrrrr�sT  �  (H"  q