-=[ Mr. Bumblebee ]=-
_Indonesia_

Path : /usr/lib/python2.7/dist-packages/bzrlib/
File Upload :
Current File : //usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyc

σ
ξ:οNc@@sœdZddlmZddlmZddlZddlmZmZd„Z	d„Z
d„Zd	efd
„ƒYZ
de
fd„ƒYZd
„ZdS(s€Helpers for managing cleanup functions and the errors they might raise.

The usual way to run cleanup code in Python is::

    try:
        do_something()
    finally:
        cleanup_something()

However if both `do_something` and `cleanup_something` raise an exception
Python will forget the original exception and propagate the one from
cleanup_something.  Unfortunately, this is almost always much less useful than
the original exception.

If you want to be certain that the first, and only the first, error is raised,
then use::

    operation = OperationWithCleanups(do_something)
    operation.add_cleanup(cleanup_something)
    operation.run_simple()

This is more inconvenient (because you need to make every try block a
function), but will ensure that the first error encountered is the one raised,
while also ensuring all cleanups are run.  See OperationWithCleanups for more
details.
i(tabsolute_import(tdequeN(tdebugttracecC@s=tjdƒtjƒdtjkr9tjd|ƒndS(NsCleanup failed:tcleanups bzr: warning: Cleanup failed: %s(Rtmuttertlog_exception_quietlyRtdebug_flagstwarning(texc((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyt_log_cleanup_error5s

cO@sIy|||ŽWn1tk
r'‚ntk
rD}t|ƒtSXtS(sŽRun func(*args, **kwargs), logging but not propagating any error it
    raises.

    :returns: True if func raised no errors, else False.
    (tKeyboardInterruptt	ExceptionR
tFalsetTrue(tfunctargstkwargsR	((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyt_run_cleanup<s

cC@s.x'|D]\}}}t|||ŽqWdS(s"Run a series of cleanup functions.N(R(tfuncsRRR((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyt
_run_cleanupsLstObjectWithCleanupscB@s)eZdZd„Zd„Zd„ZRS(s‚A mixin for objects that hold a cleanup list.

    Subclass or client code can call add_cleanup and then later `cleanup_now`.
    cC@stƒ|_dS(N(Rtcleanups(tself((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyt__init__WscO@s|jj|||fƒdS(s}Add a cleanup to run.

        Cleanups may be added at any time.  
        Cleanups will be executed in LIFO order.
        N(Rt
appendleft(Rtcleanup_funcRR((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pytadd_cleanupZscC@st|jƒ|jjƒdS(N(RRtclear(R((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pytcleanup_nowbs
(t__name__t
__module__t__doc__RRR(((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyRRs		tOperationWithCleanupscB@s)eZdZd„Zd„Zd„ZRS(sPA way to run some code with a dynamic cleanup list.

    This provides a way to add cleanups while the function-with-cleanups is
    running.

    Typical use::

        operation = OperationWithCleanups(some_func)
        operation.run(args...)

    where `some_func` is::

        def some_func(operation, args, ...):
            do_something()
            operation.add_cleanup(something)
            # etc

    Note that the first argument passed to `some_func` will be the
    OperationWithCleanups object.  To invoke `some_func` without that, use
    `run_simple` instead of `run`.
    cC@s tt|ƒjƒ||_dS(N(tsuperR!RR(RR((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyR~scO@st|j|j|||ŽS(N(t_do_with_cleanupsRR(RRR((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pytrun‚scO@st|j|j||ŽS(N(R#RR(RRR((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyt
run_simple†s(RRR RR$R%(((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyR!gs		c	O@sΚy|||Ž}Wnt|ƒ‚nXd}x]|D]U\}}}|dkr|y|||ŽWqŒtjƒ}qŒXq7t|||Žq7W|dk	rΒz|d|d|d‚Wd~Xn|SdS(s©Run `func`, then call all the cleanup_funcs.

    All the cleanup_funcs are guaranteed to be run.  The first exception raised
    by func or any of the cleanup_funcs is the one that will be propagted by
    this function (subsequent errors are caught and logged).

    Conceptually similar to::

        try:
            return func(*args, **kwargs)
        finally:
            for cleanup, cargs, ckwargs in cleanup_funcs:
                cleanup(*cargs, **ckwargs)

    It avoids several problems with using try/finally directly:
     * an exception from func will not be obscured by a subsequent exception
       from a cleanup.
     * an exception from a cleanup will not prevent other cleanups from
       running (but the first exception encountered is still the one
       propagated).

    Unike `_run_cleanup`, `_do_with_cleanups` can propagate an exception from a
    cleanup, but only if there is no exception from func.
    iiiN(RtNonetsystexc_infoR(	t
cleanup_funcsRRRtresultR(Rtc_argstc_kwargs((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyR#‹s$
(R t
__future__RtcollectionsRR'tbzrlibRRR
RRtobjectRR!R#(((s2/usr/lib/python2.7/dist-packages/bzrlib/cleanup.pyt<module>*s			$

Copyright © 2017 || Recoded By Mr.Bumblebee