b3j0f.aop.advice module¶
Provides functions in order to weave/unweave/get advices from callable objects.
-
exception
b3j0f.aop.advice.
AdviceError
[source]¶ Bases:
exceptions.Exception
Handle Advice errors.
-
b3j0f.aop.advice.
get_advices
(target, ctx=None, local=False)[source]¶ Get element advices.
Parameters: - target – target from where get advices.
- ctx – ctx from where get target.
- local (bool) – If ctx is not None or target is a method, if True (False by default) get only target advices without resolving super target advices in a super ctx.
Returns: list of advices.
Return type:
-
b3j0f.aop.advice.
weave
(target, advices, pointcut=None, ctx=None, depth=1, public=False, pointcut_application=None, ttl=None)[source]¶ Weave advices on target with input pointcut.
Parameters: - target (callable) – target from where checking pointcut and weaving advices.
- advices – advices to weave on target.
- ctx – target ctx (class or instance).
- pointcut – condition for weaving advices on joinpointe. The condition depends on its type.
- depth (int) – class weaving depthing.
- public (bool) – (default True) weave only on public members.
- pointcut_application (routine) – routine which applies a pointcut when required. _Joinpoint().apply_pointcut by default. Such routine has to take in parameters a routine called target and its related function called function. Its result is the interception function.
- ttl (float) – time to leave for weaved advices.
Returns: the intercepted functions created from input target or a tuple with intercepted functions and ttl timer.
Return type: Raises: AdviceError if pointcut is not None, not callable neither a str.
-
b3j0f.aop.advice.
unweave
(target, advices=None, pointcut=None, ctx=None, depth=1, public=False)[source]¶ Unweave advices on target with input pointcut.
Parameters: - target (callable) – target from where checking pointcut and weaving advices.
- pointcut – condition for weaving advices on joinpointe. The condition depends on its type.
- ctx – target ctx (class or instance).
- depth (int) – class weaving depthing.
- public (bool) – (default True) weave only on public members
Returns: the intercepted functions created from input target.
-
b3j0f.aop.advice.
weave_on
(advices, pointcut=None, ctx=None, depth=1, ttl=None)[source]¶ Decorator for weaving advices on a callable target.
Parameters:
-
class
b3j0f.aop.advice.
Advice
(impl, uid=None, enable=True)[source]¶ Bases:
object
Advice class which aims to embed an advice function with disabling property.
-
apply
(joinpoint)[source]¶ Apply this advice on input joinpoint.
TODO: improve with internal methods instead of conditional test.
-
enable
¶ Get self enable state. Change state if input enable is a boolean.
TODO: change of method execution instead of saving a state.
-
static
set_enable
(target, enable=True, advice_ids=None)[source]¶ Enable or disable all target Advices designated by input advice_ids.
If advice_ids is None, apply (dis|en)able state to all advices.
-
uid
¶ Get advice uid.
-