| Total Complexity | 5 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | def add_callback(before=None, after=None): |
||
| 2 | def decorator(function): |
||
| 3 | def wrapper(self, param): |
||
| 4 | if before: |
||
| 5 | [before_callback(self, param) for before_callback in before] |
||
| 6 | result = function(self, param) |
||
| 7 | if after: |
||
| 8 | [after_callback(self, param) for after_callback in after] |
||
| 9 | return result |
||
| 10 | |||
| 11 | return wrapper |
||
| 12 | |||
| 13 | return decorator |
||
| 14 | |||
| 15 | |||
| 16 | def add_catch(catch): |
||
| 17 | def decorator(function): |
||
| 18 | def wrapper(self, param): |
||
| 19 | try: |
||
| 20 | result = function(self, param) |
||
| 21 | except tuple(catch.keys()) as e: |
||
| 22 | result = catch[e.__class__] |
||
| 23 | |||
| 24 | return result |
||
| 25 | |||
| 26 | return wrapper |
||
| 27 | |||
| 28 | return decorator |
||
| 29 |