def checkCalledInside(classname, stack):
    """ Fantastically inefficient! """
    ok = False
    for s in stack[1:]:
        cc = s.code_context[0]
        if 'class' in cc:
            if '(' in cc:
                bases = [b.strip() for b in cc.split('(')[1].split(')')[0].split(',')]
                for base_name in bases:
                    if base_name in s.frame.f_globals:
                        base = s.frame.f_globals[base_name]
                        for cls in base.__class__.mro(base):
                            if cls.__name__ == classname:
                                ok = True
                                break
                        if ok:
                            break
                if ok:
                    break
    if not ok:
        name = stack[0].function
        raise SyntaxError('%s not called inside a class inheriting from LocalNameManager' % name)
def checkCalledInside ( classname , stack ) : ok = False for s in stack [ 1 : ] : cc = s . code_context [ 0 ] if 'class' in cc : if '(' in cc : bases = [ b . strip ( ) for b in cc . split ( '(' ) [ 1 ] . split ( ')' ) [ 0 ] . split ( ',' ) ] for base_name in bases : if base_name in s . frame . f_globals : base = s . frame . f_globals [ base_name ] for cls in base . __class__ . mro ( base ) : if cls . __name__ == classname : ok = True break if ok : break if ok : break if not ok : name = stack [ 0 ] . function raise SyntaxError ( '%s not called inside a class inheriting from LocalNameManager' % name )
Fantastically inefficient!