summaryrefslogtreecommitdiff
path: root/pypers/oxford/metatracer.py
blob: 253fb7ce096b902041cfe72b29f2096d1d49f442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# metatracer.py

import inspect
from decorators import decorator

@decorator
def traced(meth, *args, **kw):
    cls = meth.__cls__
    modname = meth.__module__ or cls.__module__
    print "calling %s.%s.%s" % (modname, cls.__name__, meth.__name__)
    return meth(*args, **kw)

class MetaTracer(type):            
    def __init__(cls, name, bases, dic):
        super(MetaTracer, cls).__init__(name, bases, dic)
        for k, v in dic.iteritems():
            if inspect.isfunction(v):
                v.__cls__ = cls # so we know in which class v was defined
                setattr(cls, k, traced(v))