Created
November 5, 2011 03:32
-
-
Save stephenmcd/1341065 to your computer and use it in GitHub Desktop.
Trap every object method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo(object): | |
def __getattribute__(self, name): | |
attr = object.__getattribute__(self, name) | |
if callable(attr): | |
def wrapper(*args, **kwargs): | |
try: | |
return attr(*args, **kwargs) | |
except Exception, e: | |
print "%s failed with exc %s" % (name, e) | |
attr = wrapper | |
return attr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment