aop
Apply Aspect Oriented Programming to your Python code
is_detectable
is_detectable (name, obj)
Determines when an object is potentially detectable to add an aspect to it.
| Details | |
|---|---|
| name | The name of the object. |
| obj | The builded object (potentially class). |
advice
advice (moment:str, todo:object, use_reference:bool=False)
Add an advice to a particular function.
| Type | Default | Details | |
|---|---|---|---|
| moment | str | One of ‘before’, ‘around’, ‘after_returning’, ‘after_throwing’ or ‘after’. See the documentation for more information. | |
| todo | object | What to do at the selected moment. | |
| use_reference | bool | False | Whether to use or not the referenced object, used when the catched method is not a class method. |
Aspect
Aspect ()
Defines a complete aspect.
Aspect.create_pointcut
Aspect.create_pointcut (objects, pattern, logging=True)
Creates a new pointcut associated with the aspect.
| Type | Default | Details | |
|---|---|---|---|
| objects | All the classes to which the aspect can be added. See the documentation for more information. | ||
| pattern | The pattern (string that defines a regular expression) used to select the methods to be added the aspect. | ||
| logging | bool | True | Whether to log the captured methods with the PointCut. |
Aspect.set_before
Aspect.set_before (function)
Determines what to do before the execution of the method.
| Details | |
|---|---|
| function | The ‘to do’ function in that moment. |
Aspect.set_around
Aspect.set_around (function)
Determines what to do instead of the execution of the method.
| Details | |
|---|---|
| function | The ‘to do’ function in that moment. |
Aspect.set_after_returning
Aspect.set_after_returning (function)
Determines what to do after a complete execution of the method (when there are not exceptions).
| Details | |
|---|---|
| function | The ‘to do’ function in that moment. |
Aspect.set_after_throwing
Aspect.set_after_throwing (function)
Determines what to do when the execution of the method raises an exception.
- BEWARE! This method will not handle the exception (it will be finally raised), but it will allow you to do something when the exception is raised.
| Details | |
|---|---|
| function | The ‘to do’ function in that moment. |
Aspect.set_after
Aspect.set_after (function)
Determines what to do after the execution of the method. This function will be always executed after the after_returning and after_throwing functions.
| Details | |
|---|---|
| function | The ‘to do’ function in that moment. |