Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
ó
MEYc@sâdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddlm
Z
ddlmZdefd„ƒYZ
d„Zd	efd
„ƒYZd„Zdefd
„ƒYZdS(s
Exception related utilities.
iÿÿÿÿN(tencodeutils(t
reflection(t	timeutilstCausedByExceptioncBsGeZdZdd„Zd„Zd„Zd„Zdded„Z	RS(	sBase class for exceptions which have associated causes.

    NOTE(harlowja): in later versions of python we can likely remove the need
    to have a ``cause`` here as PY3+ have implemented :pep:`3134` which
    handles chaining in a much more elegant manner.

    :param message: the exception message, typically some string that is
                    useful for consumers to view when debugging or analyzing
                    failures.
    :param cause: the cause of the exception being raised, when provided this
                  should itself be an exception instance, this is useful for
                  creating a chain of exceptions for versions of python where
                  this is not yet implemented/supported natively.

    .. versionadded:: 2.4
    cCs#tt|ƒj|ƒ||_dS(N(tsuperRt__init__tcause(tselftmessageR((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyR4scCs|jƒjdƒS(Ntutf8(tpformattencode(R((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyt	__bytes__8scCs
|jƒS(N(R
(R((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyt__str__;scCs|jdS(Ni(targs(R((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyt_get_message>sit cCsâ|dkrtd|ƒ‚ntjƒ}|r]|jtj|dtƒƒ|jdƒn|j|jƒƒ|}|j}g}xP|d	k	r×||kr×|j
|ƒ|jtjƒt
|tƒr|j||ƒ|jtj|dtƒƒ|jdƒ|j|jƒƒnœtjt|ƒ|ƒ}x€t|ƒD]r\}	}
|j||ƒ|
jdƒr}|
dd!}
n|j|
ƒ|	dt|ƒkrA|jtjƒqAqAWP||7}t|dd	ƒ}qˆW|jƒS(
s9Pretty formats a caused exception + any connected causes.isEProvided 'indent' must be greater than or equal to zero instead of %stfully_qualifieds: s
iÿÿÿÿiRN(t
ValueErrortsixtStringIOtwriteRtget_class_nametFalseRRtNonetappendtostlinesept
isinstanceRt	tracebacktformat_exception_onlyttypet	enumeratetendswithtlentgetattrtgetvalue(Rtindenttindent_texttshow_root_classtbuft
active_indenttnext_uptseentlinestitline((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyR
Ds@
	




N(
t__name__t
__module__t__doc__RRRR
RRR
(((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyR#s			cOswd|krNtjƒ\}}}z|dk	r=||d<nWd~~~Xntj||||Ž|jdƒƒdS(sðHelper to raise + chain exceptions (when able) and associate a *cause*.

    NOTE(harlowja): Since in py3.x exceptions can be chained (due to
    :pep:`3134`) we should try to raise the desired exception with the given
    *cause* (or extract a *cause* from the current stack if able) so that the
    exception formats nicely in old and new versions of python. Since py2.x
    does **not** support exception chaining (or formatting) the exception
    class provided should take a ``cause`` keyword argument (which it may
    discard if it wants) to its constructor which can then be
    inspected/retained on py2.x to get *similar* information as would be
    automatically included/obtainable in py3.x.

    :param exc_cls: the exception class to raise (typically one derived
                    from :py:class:`.CausedByException` or equivalent).
    :param message: the text/str message that will be passed to
                    the exceptions constructor as its first positional
                    argument.
    :param args: any additional positional arguments to pass to the
                 exceptions constructor.
    :param kwargs: any additional keyword arguments to pass to the
                   exceptions constructor.

    .. versionadded:: 1.6
    RN(tsystexc_infoRRt
raise_fromtget(texc_clsRRtkwargstexc_typetexctexc_tb((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pytraise_with_causems
tsave_and_reraise_exceptioncBsDeZdZedd„Zd„Zed„Zd„Zd„Z	RS(sUSave current exception, run some code and then re-raise.

    In some cases the exception context can be cleared, resulting in None
    being attempted to be re-raised after an exception handler is run. This
    can happen when eventlet switches greenthreads or when running an
    exception handler, code raises and catches an exception. In both
    cases the exception context will be cleared.

    To work around this, we save the exception state, run handler code, and
    then re-raise the original exception. If another exception occurs, the
    saved exception is logged and the new exception is re-raised.

    In some cases the caller may not want to re-raise the exception, and
    for those circumstances this context provides a reraise flag that
    can be used to suppress the exception.  For example::

      except Exception:
          with save_and_reraise_exception() as ctxt:
              decide_if_need_reraise()
              if not should_be_reraised:
                  ctxt.reraise = False

    If another exception occurs and reraise flag is False,
    the saved exception will not be logged.

    If the caller wants to raise new exception during exception handling
    he/she sets reraise to False initially with an ability to set it back to
    True if needed::

      except Exception:
          with save_and_reraise_exception(reraise=False) as ctxt:
              [if statements to determine whether to raise a new exception]
              # Not raising a new exception, so reraise
              ctxt.reraise = True

    .. versionchanged:: 1.4
       Added *logger* optional parameter.
    cCsI||_|dkr$tjƒ}n||_d\|_|_|_dS(N(NNN(treraiseRtloggingt	getLoggertloggerttype_tvaluettb(RR=R@((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyR¹s
		cCsM|jdkr-|jdkr-tdƒ‚ntj|j|j|jƒdS(NsDThere is no (currently) captured exception to force the reraising of(RARRBtRuntimeErrorRR=RC(R((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyt
force_reraiseÀscCsctjƒ\}}}|rB|dkrB|dkrBtdƒ‚n||||_|_|_|S(Ns'There is no active exception to capture(R2R3RRDRARBRC(RtcheckRARBRC((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pytcaptureÆs
cCs|jdtƒS(NRF(RGR(R((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyt	__enter__ÍscCsa|dk	rG|jrC|jjdtj|j|j|jƒƒnt	S|jr]|j
ƒndS(Ns$Original exception being dropped: %s(RR=R@terrorRtformat_exceptionRARBRCRRE(RR8texc_valR:((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyt__exit__Ós		N(
R/R0R1tTrueRRRERGRHRL(((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyR<’s&		csH‡fd†}ˆs|r |St|ƒdkr@||dƒS|SdS(såDecorates provided function with infinite retry behavior.

    The function retry delay is **always** one second unless
    keyword argument ``retry_delay`` is passed that defines a value different
    than 1.0 (less than zero values are automatically changed to be 0.0).

    If repeated exceptions with the same message occur, logging will only
    output/get triggered for those equivalent messages every 60.0
    seconds, this can be altered by keyword argument ``same_log_delay`` to
    be a value different than 60.0 seconds (exceptions that change the
    message are always logged no matter what this delay is set to). As in
    the ``retry_delay`` case if this is less than zero, it will be
    automatically changed to be 0.0.
    csjtdtˆjddƒƒƒ‰tdtˆjddƒƒƒ‰tjˆƒ‡‡‡fd†ƒ}|S(Ngtretry_delaygð?tsame_log_delaygN@csìd}d}tjdˆƒ}xÇtrçyˆ||ŽSWq!tk
rã}tj|ƒ}||krr|d7}nd}||ks|jƒrÓtj	d|ƒ|j
ƒsº|jƒn
|jƒd}|}nt
jˆƒq!Xq!WdS(Nitdurationis5Unexpected exception occurred %d time(s)... retrying.(RRt	StopWatchRMt	ExceptionRtexception_to_unicodetexpiredR>t	exceptionthas_startedtstarttrestartttimetsleep(RR7tlast_exc_messagetsame_failure_counttwatchR9tthis_exc_message(tinfuncRNRO(sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pytwrapperós*	


	(tmaxtfloatR5Rtwraps(R_R`(R7(R_RNROsH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyt	decoratorïs!!$iiN(R"(RR7Rd((R7sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyt!forever_retry_uncaught_exceptionsßs#
texception_filtercBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(s|A context manager that prevents some exceptions from being raised.

    Use this class as a decorator for a function that returns whether a given
    exception should be ignored, in cases where complex logic beyond subclass
    matching is required. e.g.

    >>> @exception_filter
    >>> def ignore_test_assertions(ex):
    ...     return isinstance(ex, AssertionError) and 'test' in str(ex)

    The filter matching function can then be used as a context manager:

    >>> with ignore_test_assertions:
    ...     assert False, 'This is a test'

    or called directly:

    >>> try:
    ...     assert False, 'This is a test'
    ... except Exception as ex:
    ...     ignore_test_assertions(ex)

    Any non-matching exception will be re-raised. When the filter is used as a
    context manager, the traceback for re-raised exceptions is always
    preserved. When the filter is called as a function, the traceback is
    preserved provided that no other exceptions have been raised in the
    intervening time. The context manager method is preferred for this reason
    except in cases where the ignored exception affects control flow.
    cs?ˆ|_t‡fd†tjDƒƒr;tj|ˆƒndS(Nc3s|]}tˆ|ƒVqdS(N(thasattr(t.0ta(tshould_ignore_ex(sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pys	<genexpr>=s(t_should_ignore_extallt	functoolstWRAPPER_ASSIGNMENTStupdate_wrapper(RRj((RjsH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyR:s	cCst|ƒ|jj||ƒƒS(N(RRkt__get__(Rtobjtowner((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyRpAscCs|S(N((R((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyRHDscCs|dk	r|j|ƒSdS(N(RRk(RR8RKR:((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyRLGscCsdtjƒ\}}}z>|j|ƒsR||krItj|||ƒqR|‚nWd~~~XdS(s¬Re-raise any exception value not being filtered out.

        If the exception was the last to be raised, it will be re-raised with
        its original traceback.
        N(R2R3RkRR=(RtexR8RKR((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyt__call__Ks
(R/R0R1RRpRHRLRt(((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyRfs				(R1RmR>RR2RYRRt
oslo_utilsRRRRRRR;tobjectR<ReRf(((sH/home/tvault/.virtenv/lib/python2.7/site-packages/oslo_utils/excutils.pyt<module>sJ	%M	<