class Reader:
def __init__(self):
pass
def fetch_page(self):
with open('/dev/blockingdevice/mypage.txt') as f:
return f.read()
def fetch_another_page(self):
with open('/dev/blockingdevice/another_mypage.txt') as f:
return f.read()
class Wrapper(Reader):
def __init__(self):
super().__init__()
def sanity_check(func):
def wrapper():
txt = func()
if 'banned_word' in txt:
raise Exception('Device has banned word on it!')
return wrapper
@sanity_check
<how to automatically put this decorator on each function of base class? >
w = Wrapper()
w.fetch_page()
w.fetch_another_page()
How can I make sure that sanity_check
's wrapper
was run automatically when calling fetch_page
and fetch_another_page
on an instance of the Wrapper
class?