'Format a single stack frame'

def format_record(self, frame, file, lnum, func, lines, index):

    Colors = self.Colors
    ColorsNormal = Colors.Normal
    col_scheme = self.color_scheme_table.active_scheme_name
    indent = ('    ' * INDENT_SIZE)
    em_normal = ('%s\n%s%s' % (Colors.valEm, indent, ColorsNormal))
    undefined = ('%sundefined%s' % (Colors.em, ColorsNormal))
    tpl_link = ('%s%%s%s' % (Colors.filenameEm, ColorsNormal))
    tpl_call = ('in    %s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal))
    tpl_call_fail = ('in    %s%%s%s(***failed    resolving    arguments***)%s' % (Colors.vName, Colors.valEm, ColorsNormal))
    tpl_local_var = ('%s%%s%s' % (Colors.vName, ColorsNormal))
    tpl_global_var = ('%sglobal%s    %s%%s%s' % (Colors.em, ColorsNormal, Colors.vName, ColorsNormal))
    tpl_name_val = ('%%s    %s=    %%s%s' % (Colors.valEm, ColorsNormal))
    tpl_line = ('%s%%s%s    %%s' % (Colors.lineno, ColorsNormal))
    tpl_line_em = ('%s%%s%s    %%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal))
    abspath = os.path.abspath
    if (not file):
        file = '?'
    elif (file.startswith(str('<')) and file.endswith(str('>'))):
        pass
    elif (not os.path.isabs(file)):
        for dirname in sys.path:
            try:
                fullname = os.path.join(dirname, file)
                if os.path.isfile(fullname):
                    file = os.path.abspath(fullname)
                    break
            except Exception:
                pass
    file = py3compat.cast_unicode(file, util_path.fs_encoding)
    link = (tpl_link % util_path.compress_user(file))
    (args, varargs, varkw, locals) = inspect.getargvalues(frame)
    if (func == '?'):
        call = ''
    else:
        var_repr = ((self.include_vars and eqrepr) or nullrepr)
        try:
            call = (tpl_call % (func, inspect.formatargvalues(args, varargs, varkw, locals, formatvalue=var_repr)))
        except KeyError:
            call = (tpl_call_fail % func)
    if file.endswith(('.so', '.pyd', '.dll')):
        return ('%s    %s\n' % (link, call))
    elif file.endswith(('.pyc', '.pyo')):
        try:
            file = openpy.source_from_cache(file)
        except ValueError:
            return ('%s    %s\n' % (link, call))
    def linereader(file=file, lnum=[lnum], getline=linecache.getline):
        line = getline(file, lnum[0])
        lnum[0] += 1
        return line
    try:
        names = []
        name_cont = False
        for (token_type, token, start, end, line) in generate_tokens(linereader):
            if ((token_type == tokenize.NAME) and (token not in keyword.kwlist)):
                if name_cont:
                    try:
                        names[(-1)].append(token)
                    except IndexError:
                        names.append([token])
                    name_cont = False
                else:
                    names.append([token])
            elif (token == '.'):
                name_cont = True
            elif (token_type == tokenize.NEWLINE):
                break
    except (IndexError, UnicodeDecodeError, SyntaxError):
        pass
    except tokenize.TokenError as msg:
        _m = ('An    unexpected    error    occurred    while    tokenizing    input\nThe    following    traceback    may    be    corrupted    or    invalid\nThe    error    message    is:    %s\n' % msg)
        error(_m)
    names = ['.'.join(n) for n in names]
    unique_names = uniq_stable(names)
    lvals = []
    if self.include_vars:
        for name_full in unique_names:
            name_base = name_full.split('.', 1)[0]
            if (name_base in frame.f_code.co_varnames):
                if (name_base in locals):
                    try:
                        value = repr(eval(name_full, locals))
                    except:
                        value = undefined
                else:
                    value = undefined
                name = (tpl_local_var % name_full)
            else:
                if (name_base in frame.f_globals):
                    try:
                        value = repr(eval(name_full, frame.f_globals))
                    except:
                        value = undefined
                else:
                    value = undefined
                name = (tpl_global_var % name_full)
            lvals.append((tpl_name_val % (name, value)))
    if lvals:
        lvals = ('%s%s' % (indent, em_normal.join(lvals)))
    else:
        lvals = ''
    level = ('%s    %s\n' % (link, call))
    if (index is None):
        return level
    else:
        _line_format = PyColorize.Parser(style=col_scheme, parent=self).format2
        return ('%s%s' % (level, ''.join(_format_traceback_lines(lnum, index, lines, Colors, lvals, _line_format))))
