1 class MetaAll(type):
2 def __new__(mcl, name, bases, dict):
3 def log(func):
4 def f(*args, **kwds):
5 print 'pre %s' % func.__name__
6 value = func(*args, **kwds)
7 print 'post %s' % func.__name__
8 return value
9 return f
10 for attr, value in dict.iteritems():
11 if attr.startswith('set'):
12 dict[attr] = log(value)
13 return super(MetaAll, mcl).__new__(mcl, name, bases, dict)
14
15 __metaclass__ = MetaAll
16
17 class A:
18 def __init__(self):
19 self.__x = 1
20
21 def getx(self):
22 return self.__x
23
24 def setx(self, value):
25 self.__x = value
26
27 a = A()
28 a.setx(2)
29 print a.getx()