Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. def debug_all_class_methods(cls):
  2.     """
  3.    This class decorator attempts to log each time a function is referenced.
  4.    This should help in debugging the flow of the process.
  5.    If you don't want these messages, set the logging level above the debug level.
  6.    :param cls: The class you are decorating.
  7.    :return: Printing all the things.
  8.    """
  9.     class NewClass(object):
  10.         def __init__(self, *args, **kwargs):
  11.             self.oInstance = cls(*args, **kwargs)
  12.  
  13.         def __getattribute__(self, s):
  14.             try:
  15.                 x = super(NewClass, self).__getattribute__()
  16.             except AttributeError:
  17.                 pass
  18.             else:
  19.                 return x
  20.  
  21.             x = self.oInstance.__getattribute__(s)
  22.             if callable(x):
  23.                 if self.oInstance.logger:
  24.                     self.oInstance.logger.debug("Entering %s", x.__name__)
  25.             return x
  26.  
  27.     return NewClass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement