stx/support.py
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 08 Sep 2013 23:18:16 +0100
changeset 0 2c329a84bd89
child 2 ef575a931434
permissions -rw-r--r--
Initial import of GDB support

class Decorator ( object ):
    '''
    Generic decorator class
    '''

    _obj = None

    def __init__ ( self , obj ):
        object.__setattr__(self, "_obj", obj)

    def target(self):
        return self._obj
    
    def __getattr__(self, aname):
        target = self._obj
        f = getattr(target, aname)
        if isinstance(f, types.MethodType):
            # Rebind the method to the target.
            return new.instancemethod(f.im_func, self, target.__class__)
        else:
            return f

    def __repr__( self ):
        return "[" +str(self.__class__) + ' : ' + self._obj.__repr__() + "]"