Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib/python3.7/site-packages/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/__pycache__/contextlib2.cpython-37.opt-1.pyc

B

�s�W�9�@sLdZddlZddlZddlmZddlmZddddd	d
dgZedg7ZGd
d�de�Z	Gdd�de	�Z
dd�ZGdd�de�ZGdd�de�Z
Gdd	�d	e
�ZGdd
�d
e
�ZGdd�de�ZejddkZer�dd�Zdd�Zndd�Zdd�ZyddlmZWnek
�reZYn
Xdd �ZGd!d�de�ZGd"d�de�ZdS)#zAcontextlib2 - backports and enhancements to the contextlib module�N)�deque)�wraps�contextmanager�closing�ContextDecorator�	ExitStack�redirect_stdout�redirect_stderr�suppress�ContextStackc@s(eZdZdZdd�Zdd�Zdd�ZdS)	rzJA base class or mixin that enables context managers to work as decorators.cCst�dt�|��S)a�Returns the context manager used to actually wrap the call to the
        decorated function.

        The default implementation just returns *self*.

        Overriding this method allows otherwise one-shot context managers
        like _GeneratorContextManager to support use as decorators via
        implicit recreation.

        DEPRECATED: refresh_cm was never added to the standard library's
                    ContextDecorator API
        z2refresh_cm was never added to the standard library)�warnings�warn�DeprecationWarning�_recreate_cm)�self�r�</opt/alt/python37/lib/python3.7/site-packages/contextlib2.py�
refresh_cms
zContextDecorator.refresh_cmcCs|S)a6Return a recreated instance of self.

        Allows an otherwise one-shot context manager like
        _GeneratorContextManager to support use as
        a decorator via implicit recreation.

        This is a private interface just for _GeneratorContextManager.
        See issue #11647 for details.
        r)rrrrr"s
zContextDecorator._recreate_cmcst����fdd��}|S)Nc	s�����||�SQRXdS)N)r)�args�kwds)�funcrrr�inner/s
z(ContextDecorator.__call__.<locals>.inner)r)rrrr)rrr�__call__.szContextDecorator.__call__N)�__name__�
__module__�__qualname__�__doc__rrrrrrrrsc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_GeneratorContextManagerz%Helper for @contextmanager decorator.cCsJ|||�|_||||_|_|_t|dd�}|dkr@t|�j}||_dS)Nr)�genrrr�getattr�typer)rrrr�docrrr�__init__9s
z!_GeneratorContextManager.__init__cCs|�|j|j|j�S)N)�	__class__rrr)rrrrrGsz%_GeneratorContextManager._recreate_cmcCs,y
t|j�Stk
r&td��YnXdS)Nzgenerator didn't yield)�nextr�
StopIteration�RuntimeError)rrrr�	__enter__Ms
z"_GeneratorContextManager.__enter__c
Cs�|dkr6yt|j�Wntk
r*dSXtd��n�|dkrD|�}y|j�|||�td��Wn�tk
r�}z||k	Sd}~XYn^tk
r�}z$||kr�dStr�|j|kr�dS�Wdd}~XYnt��d|k	rނYnXdS)Nzgenerator didn't stopz#generator didn't stop after throw()F�)	r$rr%r&�throw�_HAVE_EXCEPTION_CHAINING�	__cause__�sys�exc_info)rr �value�	traceback�excrrr�__exit__Ss,
z!_GeneratorContextManager.__exit__N)rrrrr"rr'r1rrrrr6s
rcst���fdd��}|S)a�@contextmanager decorator.

    Typical usage:

        @contextmanager
        def some_generator(<arguments>):
            <setup>
            try:
                yield <value>
            finally:
                <cleanup>

    This makes this:

        with some_generator(<arguments>) as <variable>:
            <body>

    equivalent to this:

        <setup>
        try:
            <variable> = <value>
            <body>
        finally:
            <cleanup>

    cst�||�S)N)r)rr)rrr�helper�szcontextmanager.<locals>.helper)r)rr2r)rrr~sc@s(eZdZdZdd�Zdd�Zdd�ZdS)	ra2Context to automatically close something at the end of a block.

    Code like this:

        with closing(<module>.open(<arguments>)) as f:
            <block>

    is equivalent to this:

        f = <module>.open(<arguments>)
        try:
            <block>
        finally:
            f.close()

    cCs
||_dS)N)�thing)rr3rrrr"�szclosing.__init__cCs|jS)N)r3)rrrrr'�szclosing.__enter__cGs|j��dS)N)r3�close)rr-rrrr1�szclosing.__exit__N)rrrrr"r'r1rrrrr�sc@s(eZdZdZdd�Zdd�Zdd�ZdS)�_RedirectStreamNcCs||_g|_dS)N)�_new_target�_old_targets)r�
new_targetrrrr"�sz_RedirectStream.__init__cCs*|j�tt|j��tt|j|j�|jS)N)r7�appendrr,�_stream�setattrr6)rrrrr'�sz_RedirectStream.__enter__cCstt|j|j���dS)N)r;r,r:r7�pop)r�exctype�excinst�exctbrrrr1�sz_RedirectStream.__exit__)rrrr:r"r'r1rrrrr5�sr5c@seZdZdZdZdS)raAContext 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)rrrrr:rrrrr�sc@seZdZdZdZdS)r	zCContext manager for temporarily redirecting stderr to another file.�stderrN)rrrrr:rrrrr	�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
||_dS)N)�_exceptions)r�
exceptionsrrrr"�szsuppress.__init__cCsdS)Nr)rrrrr'�szsuppress.__enter__cCs|dk	ot||j�S)N)�
issubclassrB)rr=r>r?rrrr1�s
zsuppress.__exit__N)rrrrr"r'r1rrrrr
�s	�cs�fdd�}|S)Ncs8x,|j}||krdS|dks$|�kr&P|}qW||_dS)N)�__context__)�new_exc�old_exc�exc_context)�	frame_excrr�_fix_exception_contextsz3_make_context_fixer.<locals>._fix_exception_contextr)rJrKr)rJr�_make_context_fixers
rLcCs<y|dj}|d�Wn tk
r6||d_�YnXdS)Nr()rF�
BaseException)�exc_details�	fixed_ctxrrr�_reraise_with_existing_contexts

rPcCsdd�S)NcSsdS)Nr)rGrHrrr�<lambda>�z%_make_context_fixer.<locals>.<lambda>r)rJrrrrLscCs|\}}}td�dS)Nz!raise exc_type, exc_value, exc_tb)�exec)rN�exc_type�	exc_value�exc_tbrrrrP"s
)�InstanceTypecCst|�}|tkr|jS|S)N)r rWr#)�objZobj_typerrr�	_get_type.srYc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)ra�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�|_dS)N)r�_exit_callbacks)rrrrr"AszExitStack.__init__cCst|��}|j|_t�|_|S)z?Preserve the context stack by transferring it to a new instance)r rZr)r�	new_stackrrr�pop_allDs
zExitStack.pop_allcs"��fdd�}�|_|�|�dS)z:Helper to correctly register callbacks to __exit__ methodscs��f|��S)Nr)rN)�cm�cm_exitrr�
_exit_wrapperMsz.ExitStack._push_cm_exit.<locals>._exit_wrapperN)�__self__�push)rr]r^r_r)r]r^r�
_push_cm_exitKszExitStack._push_cm_exitcCsDt|�}y
|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)
        )rYr1�AttributeErrorrZr9rb)r�exit�_cb_type�exit_methodrrrraRs

zExitStack.pushcs$���fdd�}�|_|�|��S)z\Registers an arbitrary callback and arguments.

        Cannot suppress exceptions.
        cs����dS)Nr)rTr0�tb)r�callbackrrrr_ksz)ExitStack.callback.<locals>._exit_wrapper)�__wrapped__ra)rrhrrr_r)rrhrrrhfs
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.
        )rYr1r'rb)rr]�_cm_type�_exit�resultrrr�
enter_contextss

zExitStack.enter_contextcCs|�ddd�dS)z$Immediately unwind the context stackN)r1)rrrrr4�szExitStack.closecCs|S)Nr)rrrrr'�szExitStack.__enter__c	Gs�|ddk	}t��d}t|�}d}d}x\|jr�|j��}y||�rPd}d}d}Wq*t��}||d|d�d}|}Yq*Xq*W|r�t|�|o�|S)Nrr(FT)NNN)r,r-rLrZr<rP)	rrN�received_excrJrK�suppressed_exc�
pending_raise�cb�new_exc_detailsrrrr1�s(
zExitStack.__exit__N)
rrrrr"r\rbrarhrmr4r'r1rrrrr5s

cs8eZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�ZS)
rz+Backwards compatibility alias for ExitStackcst�dt�tt|���dS)Nz*ContextStack has been renamed to ExitStack)rr
r�superrr")r)r#rrr"�szContextStack.__init__cCs
|�|�S)N)ra)rrhrrr�
register_exit�szContextStack.register_exitcOs|j|f|�|�S)N)rh)rrhrrrrr�register�szContextStack.registercCs|��S)N)r\)rrrr�preserve�szContextStack.preserve)	rrrrr"rtrurv�
__classcell__rr)r#rr�s
)rr,r�collectionsr�	functoolsr�__all__�objectrrrrr5rr	r
�version_infor*rLrP�typesrW�ImportErrorr rYrrrrrr�<module>s8

(H"

p