• File: contextlib2.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/lib/python2.7/site-packages/contextlib2.pyc
  • Date Modified: 04/26/2018 1:05 PM
  • File size: 15.04 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit

Zc@sdZddlZddlZddlmZddlmZddddd	d
dgZedg7Zdefd
YZ	de	fdYZ
dZdefdYZdefdYZ
d	e
fdYZd
e
fdYZdefdYZejddkZer7dZdZndZdZyddlmZWnek
rveZn
XdZdefdYZdefd YZdS(!sAcontextlib2 - backports and enhancements to the contextlib moduleiN(tdeque(twrapstcontextmanagertclosingtContextDecoratort	ExitStacktredirect_stdouttredirect_stderrtsuppresstContextStackcBs)eZdZdZdZdZRS(sJA base class or mixin that enables context managers to work as decorators.cCstjdt|jS(sReturns 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((s0/tmp/pip-build-mubq5u/contextlib2/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((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR
"s
cs"tfd}|S(Ncs$j||SWdQXdS(N(R
(targstkwds(tfuncR(s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pytinner/s
(R(RRR((RRs0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt__call__.s(t__name__t
__module__t__doc__RR
R(((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRs		t_GeneratorContextManagercBs2eZdZdZdZdZdZRS(s%Helper for @contextmanager decorator.cCsl||||_||||_|_|_t|dd}|dkr_t|j}n||_dS(NR(tgenRRRtgetattrtNonettypeR(RRRRtdoc((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt__init__9scCs|j|j|j|jS(N(t	__class__RRR(R((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR
GscCs5yt|jSWntk
r0tdnXdS(Nsgenerator didn't yield(tnextRt
StopIterationtRuntimeError(R((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt	__enter__Ms
cCs|dkrAyt|jWntk
r1dSXtdn|dkrY|}ny&|jj|||tdWnztk
r}||k	Stk
r}||krtStr|j|krtSn#t	j
d|k	rqnXdS(Nsgenerator didn't stops#generator didn't stop after throw()i(RR RR!R"tthrowtFalset_HAVE_EXCEPTION_CHAININGt	__cause__tsystexc_info(RRtvaluet	tracebacktexc((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt__exit__Ss,

(RRRRR
R#R-(((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR6s
			cstfd}|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(s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pythelpers(R(RR.((Rs0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR~scBs)eZdZdZdZdZRS(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/((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRscCs|jS(N(R/(R((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR#scGs|jjdS(N(R/tclose(RR)((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR-s(RRRRR#R-(((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRs		t_RedirectStreamcBs)eZdZdZdZdZRS(cCs||_g|_dS(N(t_new_targett_old_targets(Rt
new_target((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRs	cCs9|jjtt|jtt|j|j|jS(N(R3tappendRR(t_streamtsetattrR2(R((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR#scCs tt|j|jjdS(N(R7R(R6R3tpop(Rtexctypetexcinsttexctb((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR-sN(RRRR6RR#R-(((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR1s		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(((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRscBseZdZdZRS(sCContext manager for temporarily redirecting stderr to another file.tstderr(RRRR6(((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRscBs)eZdZdZdZdZRS(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((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRscCsdS(N((R((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR#scCs|dk	ot||jS(N(Rt
issubclassR>(RR9R:R;((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR-s
(RRRRR#R-(((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRs			iicsfd}|S(NcsNx>|j}||krdS|dks4|kr8Pn|}q||_dS(N(t__context__R(tnew_exctold_exctexc_context(t	frame_exc(s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt_fix_exception_contexts		((RERF((REs0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt_make_context_fixers
cCsCy|dj}|dWn!tk
r>||d_nXdS(Ni(RAt
BaseException(texc_detailst	fixed_ctx((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt_reraise_with_existing_contexts


cCsdS(NcSsdS(N(R(RBRC((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt<lambda>s((RE((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRGscBs|\}}}ddUdS(Ns!raise exc_type, exc_value, exc_tb((RItexc_typet	exc_valuetexc_tb((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRK"s(tInstanceTypecCs#t|}|tkr|jS|S(N(RRPR(tobjtobj_type((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt	_get_type.scBs_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
sContext 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((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRAscCs+t|}|j|_t|_|S(s?Preserve the context stack by transferring it to a new instance(RRTR(Rt	new_stack((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pytpop_allDscs,fd}|_|j|dS(s:Helper to correctly register callbacks to __exit__ methodscs
|S(N((RI(tcmtcm_exit(s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt
_exit_wrapperMsN(t__self__tpush(RRWRXRY((RWRXs0/tmp/pip-build-mubq5u/contextlib2/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)
        (RSR-tAttributeErrorRTR5R\(Rtexitt_cb_typetexit_method((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR[Rs


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

        Cannot suppress exceptions.
        csdS(N((RMR,ttb(RtcallbackR(s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRYks(t__wrapped__R[(RRbRRRY((RRbRs0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRbfs	
cCs8t|}|j}|j|}|j|||S(sEnters the supplied context manager

        If successful, also pushes its __exit__ method as a callback and
        returns the result of the __enter__ method.
        (RSR-R#R\(RRWt_cm_typet_exittresult((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt
enter_contextss
	cCs|jddddS(s$Immediately unwind the context stackN(R-R(R((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR0scCs|S(N((R((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR#sc	Gs|ddk	}tjd}t|}t}t}xx|jr|jj}y%||rwt}t}d}nWq;tj}||d|dt}|}q;Xq;W|rt|n|o|S(Nii(NNN(	RR(R)RGR%RTR8tTrueRK(	RRItreceived_excRERFtsuppressed_exct
pending_raisetcbtnew_exc_details((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR-s(

(RRRRRVR\R[RbRgR0R#R-(((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR5s					
	
		cBs2eZdZdZdZdZdZRS(s+Backwards compatibility alias for ExitStackcCs'tjdttt|jdS(Ns*ContextStack has been renamed to ExitStack(R
RRtsuperR	R(R((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyRs	cCs
|j|S(N(R[(RRb((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt
register_exitscOs|j|||S(N(Rb(RRbRR((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pytregisterscCs
|jS(N(RV(R((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pytpreserves(RRRRRoRpRq(((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyR	s
			(RR(R
tcollectionsRt	functoolsRt__all__tobjectRRRRR1RRRtversion_infoR&RGRKttypesRPtImportErrorRRSRR	(((s0/tmp/pip-build-mubq5u/contextlib2/contextlib2.pyt<module>s8
(H	"			

	p