stx/support.py
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 30 Nov 2013 22:31:53 +0000
changeset 2 ef575a931434
parent 0 2c329a84bd89
permissions -rw-r--r--
Improved command `btx` (backtrace) Detects stc-compiled method and show their frames Class >> selector instead of showing stx-mangled C function name. Also catches an error and prints backtrace in case there's problem in the code (unhandled exception etc)

import types

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__() + "]"