trepan/lib/stack.py
def format_stack_entry(dbg_obj, frame_lineno, lprefix=': ',
                       include_location=True, color='plain'):
    """Format and return a stack entry gdb-style.
    Note: lprefix is not used. It is kept for compatibility.
    """
    frame, lineno = frame_lineno
    filename = frame2file(dbg_obj.core, frame)

    s = ''
    if frame.f_code.co_name:
        funcname = frame.f_code.co_name
    else:
        funcname = "<lambda>"
        pass
    s = format_token(Mformat.Function, funcname, highlight=color)

    args, varargs, varkw, local_vars = inspect.getargvalues(frame)
    if '<module>' == funcname and ([], None, None,) == (args, varargs, varkw,):
        is_module = True
        if is_exec_stmt(frame):
            fn_name = format_token(Mformat.Function, 'exec', highlight=color)
            source_text = deparse_source_from_code(frame.f_code)
            s += ' %s(%s)' % (format_token(Mformat.Function, fn_name,
                                           highlight=color), source_text)
        else:
            fn_name = get_call_function_name(frame)
            if fn_name:
                source_text = deparse_source_from_code(frame.f_code)
                if fn_name: s += ' %s(%s)' % (format_token(Mformat.Function, fn_name,
                                                           highlight=color), source_text)
            pass
    else:
        is_module = False
        parms=inspect.formatargvalues(args, varargs, varkw, local_vars)
        maxargstrsize = dbg_obj.settings['maxargstrsize']
        if len(parms) >= maxargstrsize:
            parms = "%s...)" % parms[0:maxargstrsize]
            pass
        s += parms
        pass

    # Note: ddd can't handle wrapped stack entries (yet).
    # The 35 is hoaky though. FIXME.
    if len(s) >= 35: s += "\n    "

    if '__return__' in frame.f_locals:
        rv = frame.f_locals['__return__']
        s += '->'
        s += format_token(Mformat.Return, Mrepr.repr(rv),
                          highlight=color)
        pass

    if include_location:
        is_pseudo_file = _re_pseudo_file.match(filename)
        add_quotes_around_file = not is_pseudo_file
        if is_module:
            if filename == '<string>':
                s += ' in exec'
            elif not is_exec_stmt(frame) and not is_pseudo_file:
                s += ' file'
        elif s == '?()':
            if is_exec_stmt(frame):
                s = 'in exec'
                # exec_str = get_exec_string(frame.f_back)
                # if exec_str != None:
                #     filename = exec_str
                #     add_quotes_around_file = False
                #     pass
                # pass
            elif not is_pseudo_file:
                s = 'in file'
                pass
            pass
        elif not is_pseudo_file:
            s += ' called from file'
            pass

        if add_quotes_around_file: filename = "'%s'" % filename
        s += " %s at line %s" % (
            format_token(Mformat.Filename, filename,
                         highlight=color),
            format_token(Mformat.LineNumber, "%r" % lineno,
                         highlight=color)
            )
    return s
def format_stack_entry(dbg_obj, frame_lineno, lprefix=': ',
                       include_location=True, color='plain'):
    """Format and return a stack entry gdb-style.
    Note: lprefix is not used. It is kept for compatibility.
    """
    frame, lineno = frame_lineno
    filename = frame2file(dbg_obj.core, frame)

    s = ''
    if frame.f_code.co_name:
        funcname = frame.f_code.co_name
    else:
        funcname = "<lambda>"
        pass
    s = format_token(Mformat.Function, funcname, highlight=color)

    args, varargs, varkw, local_vars = inspect.getargvalues(frame)
    if '<module>' == funcname and ([], None, None,) == (args, varargs, varkw,):
        is_module = True
        if is_exec_stmt(frame):
            fn_name = format_token(Mformat.Function, 'exec', highlight=color)
            source_text = deparse_source_from_code(frame.f_code)
            s += ' %s(%s)' % (format_token(Mformat.Function, fn_name,
                                           highlight=color), source_text)
        else:
            fn_name = get_call_function_name(frame)
            if fn_name:
                source_text = deparse_source_from_code(frame.f_code)
                if fn_name: s += ' %s(%s)' % (format_token(Mformat.Function, fn_name,
                                                           highlight=color), source_text)
            pass
    else:
        is_module = False
        parms=inspect.formatargvalues(args, varargs, varkw, local_vars)
        maxargstrsize = dbg_obj.settings['maxargstrsize']
        if len(parms) >= maxargstrsize:
            parms = "%s...)" % parms[0:maxargstrsize]
            pass
        s += parms
        pass

    # Note: ddd can't handle wrapped stack entries (yet).
    # The 35 is hoaky though. FIXME.
    if len(s) >= 35: s += "\n    "

    if '__return__' in frame.f_locals:
        rv = frame.f_locals['__return__']
        s += '->'
        s += format_token(Mformat.Return, Mrepr.repr(rv),
                          highlight=color)
        pass

    if include_location:
        is_pseudo_file = _re_pseudo_file.match(filename)
        add_quotes_around_file = not is_pseudo_file
        if is_module:
            if filename == '<string>':
                s += ' in exec'
            elif not is_exec_stmt(frame) and not is_pseudo_file:
                s += ' file'
        elif s == '?()':
            if is_exec_stmt(frame):
                s = 'in exec'
                # exec_str = get_exec_string(frame.f_back)
                # if exec_str != None:
                #     filename = exec_str
                #     add_quotes_around_file = False
                #     pass
                # pass
            elif not is_pseudo_file:
                s = 'in file'
                pass
            pass
        elif not is_pseudo_file:
            s += ' called from file'
            pass

        if add_quotes_around_file: filename = "'%s'" % filename
        s += " %s at line %s" % (
            format_token(Mformat.Filename, filename,
                         highlight=color),
            format_token(Mformat.LineNumber, "%r" % lineno,
                         highlight=color)
            )
    return s
def format_stack_entry ( dbg_obj , frame_lineno , lprefix = ': ' , include_location = True , color = 'plain' ) : frame , lineno = frame_lineno filename = frame2file ( dbg_obj . core , frame ) s = '' if frame . f_code . co_name : funcname = frame . f_code . co_name else : funcname = "<lambda>" pass s = format_token ( Mformat . Function , funcname , highlight = color ) args , varargs , varkw , local_vars = inspect . getargvalues ( frame ) if '<module>' == funcname and ( [ ] , None , None , ) == ( args , varargs , varkw , ) : is_module = True if is_exec_stmt ( frame ) : fn_name = format_token ( Mformat . Function , 'exec' , highlight = color ) source_text = deparse_source_from_code ( frame . f_code ) s += ' %s(%s)' % ( format_token ( Mformat . Function , fn_name , highlight = color ) , source_text ) else : fn_name = get_call_function_name ( frame ) if fn_name : source_text = deparse_source_from_code ( frame . f_code ) if fn_name : s += ' %s(%s)' % ( format_token ( Mformat . Function , fn_name , highlight = color ) , source_text ) pass else : is_module = False parms = inspect . formatargvalues ( args , varargs , varkw , local_vars ) maxargstrsize = dbg_obj . settings [ 'maxargstrsize' ] if len ( parms ) >= maxargstrsize : parms = "%s...)" % parms [ 0 : maxargstrsize ] pass s += parms pass # Note: ddd can't handle wrapped stack entries (yet). # The 35 is hoaky though. FIXME. if len ( s ) >= 35 : s += "\n    " if '__return__' in frame . f_locals : rv = frame . f_locals [ '__return__' ] s += '->' s += format_token ( Mformat . Return , Mrepr . repr ( rv ) , highlight = color ) pass if include_location : is_pseudo_file = _re_pseudo_file . match ( filename ) add_quotes_around_file = not is_pseudo_file if is_module : if filename == '<string>' : s += ' in exec' elif not is_exec_stmt ( frame ) and not is_pseudo_file : s += ' file' elif s == '?()' : if is_exec_stmt ( frame ) : s = 'in exec' # exec_str = get_exec_string(frame.f_back) # if exec_str != None: #     filename = exec_str #     add_quotes_around_file = False #     pass # pass elif not is_pseudo_file : s = 'in file' pass pass elif not is_pseudo_file : s += ' called from file' pass if add_quotes_around_file : filename = "'%s'" % filename s += " %s at line %s" % ( format_token ( Mformat . Filename , filename , highlight = color ) , format_token ( Mformat . LineNumber , "%r" % lineno , highlight = color ) ) return s
Format and return a stack entry gdb-style.
    Note: lprefix is not used. It is kept for compatibility.
Format and return a stack entry gdb - style . Note : lprefix is not used . It is kept for compatibility .