AlkantarClanX12

Your IP : 18.188.110.150


Current Path : /opt/alt/python27/lib/python2.7/site-packages/
Upload File :
Current File : //opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyc

�
�s�Wc@s�dZddlZddlZddlmZddlmZddddd	d
dgZedg7Zdefd
��YZ	de	fd��YZ
d�Zdefd��YZdefd��YZ
d	e
fd��YZd
e
fd��YZdefd��YZejddkZer7d�Zd�Znd�Zd�ZyddlmZWnek
rveZn
Xd�Zdefd��YZdefd ��YZdS(!sAcontextlib2 - backports and enhancements to the contextlib modulei����N(tdeque(twrapstcontextmanagertclosingtContextDecoratort	ExitStacktredirect_stdouttredirect_stderrtsuppresstContextStackcBs)eZdZd�Zd�Zd�ZRS(sJA base class or mixin that enables context managers to work as decorators.cCstjdt�|j�S(s�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
        s2refresh_cm was never added to the standard library(twarningstwarntDeprecationWarningt_recreate_cm(tself((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt
refresh_cms
	cCs|S(s6Return 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((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR
"s
cs"t����fd��}|S(Ncs$�j���||�SWdQXdS(N(R
(targstkwds(tfuncR(s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pytinner/s
(R(RRR((RRs</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt__call__.s(t__name__t
__module__t__doc__RR
R(((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyRs		t_GeneratorContextManagercBs2eZdZd�Zd�Zd�Zd�ZRS(s%Helper for @contextmanager decorator.cCsl|||�|_||||_|_|_t|dd�}|dkr_t|�j}n||_dS(NR(tgenRRRtgetattrtNonettypeR(RRRRtdoc((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt__init__9scCs|j|j|j|j�S(N(t	__class__RRR(R((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR
GscCs5yt|j�SWntk
r0td��nXdS(Nsgenerator didn't yield(tnextRt
StopIterationtRuntimeError(R((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt	__enter__Ms
cCs|dkrAyt|j�Wntk
r1dSXtd��n�|dkrY|�}ny&|jj|||�td��Wnztk
r�}||k	Stk
r�}||kr�tStr�|j|kr�tS�n#t	j
�d|k	r��q�nXdS(Nsgenerator didn't stops#generator didn't stop after throw()i(RR RR!R"tthrowtFalset_HAVE_EXCEPTION_CHAININGt	__cause__tsystexc_info(RRtvaluet	tracebacktexc((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt__exit__Ss,

(RRRRR
R#R-(((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR6s
			cst���fd��}|S(s�@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>

    cst�||�S(N(R(RR(R(s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pythelper�s(R(RR.((Rs</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR~scBs)eZdZd�Zd�Zd�ZRS(s2Context 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(tthing(RR/((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR�scCs|jS(N(R/(R((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR#�scGs|jj�dS(N(R/tclose(RR)((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR-�s(RRRRR#R-(((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR�s		t_RedirectStreamcBs)eZdZd�Zd�Zd�ZRS(cCs||_g|_dS(N(t_new_targett_old_targets(Rt
new_target((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR�s	cCs9|jjtt|j��tt|j|j�|jS(N(R3tappendRR(t_streamtsetattrR2(R((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR#�scCs tt|j|jj��dS(N(R7R(R6R3tpop(Rtexctypetexcinsttexctb((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR-�sN(RRRR6RR#R-(((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR1�s		cBseZdZdZRS(sAContext 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)
    tstdout(RRRR6(((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR�scBseZdZdZRS(sCContext manager for temporarily redirecting stderr to another file.tstderr(RRRR6(((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR�scBs)eZdZd�Zd�Zd�ZRS(s?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(t_exceptions(Rt
exceptions((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR�scCsdS(N((R((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR#�scCs|dk	ot||j�S(N(Rt
issubclassR>(RR9R:R;((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR-�s
(RRRRR#R-(((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR�s			iics�fd�}|S(NcsOx?|j}||krdS|dks4|�kr8Pn|}qW||_dS(N(t__context__R(tnew_exctold_exctexc_context(t	frame_exc(s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt_fix_exception_contexts	
((RERF((REs</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt_make_context_fixers
cCsCy|dj}|d�Wn!tk
r>||d_�nXdS(Ni(RAt
BaseException(texc_detailst	fixed_ctx((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt_reraise_with_existing_contexts


cCsd�S(NcSsdS(N(R(RBRC((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt<lambda>t((RE((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyRGscBs|\}}}ddUdS(Ns!raise exc_type, exc_value, exc_tb((RItexc_typet	exc_valuetexc_tb((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyRK"s(tInstanceTypecCs#t|�}|tkr|jS|S(N(RRQR(tobjtobj_type((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt	_get_type.scBs_eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�ZRS(
s�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

    cCst�|_dS(N(Rt_exit_callbacks(R((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyRAscCs+t|��}|j|_t�|_|S(s?Preserve the context stack by transferring it to a new instance(RRUR(Rt	new_stack((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pytpop_allDscs,��fd�}�|_|j|�dS(s:Helper to correctly register callbacks to __exit__ methodscs
��|�S(N((RI(tcmtcm_exit(s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt
_exit_wrapperMsN(t__self__tpush(RRXRYRZ((RXRYs</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt
_push_cm_exitKs	cCsQt|�}y
|j}Wn!tk
r<|jj|�nX|j||�|S(sRegisters 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)
        (RTR-tAttributeErrorRUR5R](Rtexitt_cb_typetexit_method((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR\Rs


cs/���fd�}�|_|j|��S(s\Registers an arbitrary callback and arguments.

        Cannot suppress exceptions.
        cs����dS(N((RNR,ttb(RtcallbackR(s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyRZks(t__wrapped__R\(RRcRRRZ((RRcRs</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyRcfs	
cCs8t|�}|j}|j|�}|j||�|S(s�Enters the supplied context manager

        If successful, also pushes its __exit__ method as a callback and
        returns the result of the __enter__ method.
        (RTR-R#R](RRXt_cm_typet_exittresult((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt
enter_contextss
	cCs|jddd�dS(s$Immediately unwind the context stackN(R-R(R((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR0�scCs|S(N((R((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR#�sc	Gs�|ddk	}tj�d}t|�}t}t}xx|jr�|jj�}y%||�rwt}t}d}nWq;tj�}||d|d�t}|}q;Xq;W|r�t|�n|o�|S(Nii(NNN(	RR(R)RGR%RUR8tTrueRK(	RRItreceived_excRERFtsuppressed_exct
pending_raisetcbtnew_exc_details((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR-�s(

(RRRRRWR]R\RcRhR0R#R-(((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR5s					
	
		cBs2eZdZd�Zd�Zd�Zd�ZRS(s+Backwards compatibility alias for ExitStackcCs'tjdt�tt|�j�dS(Ns*ContextStack has been renamed to ExitStack(R
RRtsuperR	R(R((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR�s	cCs
|j|�S(N(R\(RRc((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt
register_exit�scOs|j|||�S(N(Rc(RRcRR((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pytregister�scCs
|j�S(N(RW(R((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pytpreserve�s(RRRRRpRqRr(((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyR	�s
			(RR(R
tcollectionsRt	functoolsRt__all__tobjectRRRRR1RRRtversion_infoR&RGRKttypesRQtImportErrorRRTRR	(((s</opt/alt/python27/lib/python2.7/site-packages/contextlib2.pyt<module>s8
(H	"			

	p