Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. logging full trace once
  2. '__init__': [
  3. {'init_method_1':
  4. [
  5. {'init_method_1_1': []}
  6. ]}
  7.  
  8. {'init_method_2': []}
  9.  
  10. ],
  11. 'main_function': [
  12. {'first_main_function': [
  13. {'condition_method_3': []},
  14. {'condition_method_5': []}
  15. ]}
  16. ]
  17.  
  18. import types
  19.  
  20. class DecoMeta(type):
  21. def __new__(cls, name, bases, attrs):
  22.  
  23. for attr_name, attr_value in attrs.items():
  24. if isinstance(attr_value, types.FunctionType):
  25. attrs[attr_name] = cls.deco(attr_value)
  26.  
  27. return super(DecoMeta, cls).__new__(cls, name, bases, attrs)
  28.  
  29. @classmethod
  30. def deco(cls, func):
  31. def wrapper(*args, **kwargs):
  32.  
  33. name = func.__name__
  34. stacktrace_full.setdefault(name, [])
  35. sorted_functions = stacktrace_full[name]
  36. if len(sorted_functions) > 0:
  37. stacktrace_full[name].append(name)
  38. result = func(*args, **kwargs)
  39. print("after",func.__name__)
  40. return result
  41. return wrapper
  42.  
  43. class MyKlass(metaclass=DecoMeta):
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement