Find the deepest stack frame that is not part of SCons.

    Input is a "pre-processed" stack trace in the form
    returned by traceback.extract_tb() or traceback.extract_stack()
9135
def find_deepest_user_frame(tb):
    

    tb.reverse()

    # find the deepest traceback frame that is not part
    # of SCons:
    for frame in tb:
        filename = frame[0]
        if filename.find(os.sep+'SCons'+os.sep) == -1:
            return frame
    return tb[0]
663294
def find_top_pyfile():
    
    import os
    frame = currentframe()
    while True:
        if frame.f_back is None:
            finfo = getframeinfo(frame)
            #print(getframeinfo(frame))
            return os.path.abspath(finfo.filename)

        frame = frame.f_back
969016
def getProvStack(self, iden: bytes):
        '''
        
        '''
        retn = self.slab.get(iden, db=self.db)
        if retn is None:
            return None

        return s_msgpack.un(retn)
84822
def filter_traceback(error, tb, ignore_pkg=CURRENT_PACKAGE):
    
    if not isinstance(tb, types.TracebackType):
        return tb

    def in_namespace(n):
        return n and (n.startswith(ignore_pkg + '.') or n == ignore_pkg)
    # Skip test runner traceback levels
    while tb and in_namespace(tb.tb_frame.f_globals['__package__']):
        tb = tb.tb_next
    starting_tb = tb
    limit = 0
    while tb and not in_namespace(tb.tb_frame.f_globals['__package__']):
        tb = tb.tb_next
        limit += 1

    return ''.join(traceback.format_exception(error.__class__, error, starting_tb, limit))
825664
def get_stack(self, f, t):
        """"""
        stack = []
        if t and t.tb_frame == f:
            t = t.tb_next
        while f is not None:
            stack.append((f, f.f_lineno))
            f = f.f_back
        stack.reverse()
        i = max(0, len(stack) - 1)
        while t is not None:
            stack.append((t.tb_frame, t.tb_lineno))
            t = t.tb_next
        if f is None:
            i = max(0, len(stack) - 1)
        return stack, i
1278071
function prepareStackTrace (_, stack){
    return $.map(stack.slice(2), function(frame) {
      var _f = {
        fileName: frame.getFileName(),
        linenumber: frame.getLineNumber(),
        columnNumber: frame.getColumnNumber()
      };

      if (frame.getFunctionName()) _f.functionName = frame.getFunctionName();
      if (frame.getMethodName()) _f.methodName = frame.getMethodName();
      if (frame.getThis()) _f.self = frame.getThis();

      return _f;
    });
  }
819148
def traverse_depth_first_post_order(self, callback):
        
        # a. Reimplement without python lists?..
        # b. Interface will require it to have not internal nodes only?..
        #    (but actually this implementation gives a ~2x gain of performance)
        last_interval = None
        n = len(self.suftab)
        stack = [[0, 0, None, []]]  # <l, i, j, children>
        for i in xrange(1, n):
            lb = i - 1
            while self.lcptab[i] < stack[-1][0]:
                stack[-1][2] = i - 1
                last_interval = stack.pop()
                callback(last_interval)
                lb = last_interval[1]
                if self.lcptab[i] <= stack[-1][0]:
                    stack[-1][3].append(last_interval)
                    last_interval = None
            if self.lcptab[i] > stack[-1][0]:
                if last_interval:
                    stack.append([self.lcptab[i], lb, None, [last_interval]])
                    last_interval = None
                else:
                    stack.append([self.lcptab[i], lb, None, []])
        stack[-1][2] = n - 1
        callback(stack[-1])
502913
def stackToList(stack):
    
    if isinstance(stack, types.TracebackType):
        while stack.tb_next:
            stack = stack.tb_next
        stack = stack.tb_frame
    out = []
    while stack:
        out.append(stack)
        stack = stack.f_back
    return out
460904
def _get_stack_info_for_trace(
        self,
        frames,
        library_frame_context_lines=None,
        in_app_frame_context_lines=None,
        with_locals=True,
        locals_processor_func=None,
    ):
        """"""
        return stacks.get_stack_info(
            frames,
            library_frame_context_lines=library_frame_context_lines,
            in_app_frame_context_lines=in_app_frame_context_lines,
            with_locals=with_locals,
            include_paths_re=self.include_paths_re,
            exclude_paths_re=self.exclude_paths_re,
            locals_processor_func=locals_processor_func,
        )
912658
def extract_relevant_tb(tb, exctype, is_test_failure):
    
    # Skip test runner traceback levels:
    while tb and _is_unittest_frame(tb):
        tb = tb.tb_next
    if is_test_failure:
        # Skip assert*() traceback levels:
        length = _count_relevant_tb_levels(tb)
        return extract_tb(tb, length)
    return extract_tb(tb)
881276
def move_in_stack(move_up):
    ''''''
    frame = Frame.get_selected_python_frame()
    while frame:
        if move_up:
            iter_frame = frame.older()
        else:
            iter_frame = frame.newer()

        if not iter_frame:
            break

        if iter_frame.is_evalframeex():
            # Result:
            if iter_frame.select():
                iter_frame.print_summary()
            return

        frame = iter_frame

    if move_up:
        print 'Unable to find an older python frame'
    else:
        print 'Unable to find a newer python frame'
369024
def extract_locals(trcback):
    

    output = []
    stack = extract_stack(get_inner_most_frame(trcback))
    for frame, file_name, line_number, name, context, index in stack:
        args_names, nameless, keyword = extract_arguments(frame)
        arguments, nameless_args, keyword_args, locals = OrderedDict(), [], {}, {}
        for key, data in frame.f_locals.iteritems():
            if key == nameless:
                nameless_args = map(repr, frame.f_locals.get(nameless, ()))
            elif key == keyword:
                keyword_args = dict((arg, repr(value)) for arg, value in frame.f_locals.get(keyword, {}).iteritems())
            elif key in args_names:
                arguments[key] = repr(data)
            else:
                locals[key] = repr(data)
        output.append(((name, file_name, line_number), (arguments, nameless_args, keyword_args, locals)))
    return output
99088
def remove_stacktrace_locals(client, event):
    
    func = lambda frame: frame.pop("vars", None)
    return _process_stack_frames(event, func)
150692
def findCaller(self, stack_info=False, callers=0):
        
        f = logging.currentframe()
        #On some versions of IronPython, currentframe() returns None if
        #IronPython isn't run with -X:Frames.
        if f is not None:
            if callers > 0:
                # yes we can!
                co = f.f_code
                logger.debug2("%s:%s", co.co_filename, co.co_name)
            f = f.f_back
        rv = "(unknown file)", 0, "(unknown function)", None
        countdown = callers
        while hasattr(f, "f_code"):
            co = f.f_code
            filename = os.path.normcase(co.co_filename)
            if callers > 0:
                # yes we can!
                logger.debug2("%s:%s", co.co_filename, co.co_name)
            if filename in(_srcfile, logging._srcfile):
                f = f.f_back
                continue
            if countdown > 0:
                f = f.f_back
                countdown -= 1
                continue
            sinfo = None
            if stack_info:
                sio = io.StringIO()
                sio.write('Stack (most recent call last):\n')
                traceback.print_stack(f, file=sio)
                sinfo = sio.getvalue()
                if sinfo[-1] == '\n':
                    sinfo = sinfo[:-1]
                sio.close()
            rv = (co.co_filename, f.f_lineno, co.co_name, sinfo)
            break
        return rv
825714
def check_end_blocks(frame):
    
    try:
        try:
            module_name = frame.f_globals['__name__']
        except KeyError:
            warnings.warn(
                'Can not get the source of an uknown module. '
                'End-of-block syntax check is skipped.',
                EndSyntaxWarning)
            return
        end

        filename = frame.f_globals.get('__file__', '<unknown>')
        try:
            source = inspect.getsource(sys.modules[module_name])
        except Exception:
            warnings.warn(
                'Can not get the source of module "%s". '
                'End-of-block syntax check is skipped.' % (module_name,),
                EndSyntaxWarning)
            return
        end
    finally:
        del frame
    end

    root = ast.parse(source)
    for node in ast.walk(root):
        bodies = get_compound_bodies(node)
        if not bodies:
            continue
        end

        # FIXME: This is an inaccurate hack to handle if-elif-else.
        if (isinstance(node, ast.If) and
                len(node.orelse) == 1 and
                isinstance(node.orelse[0], ast.If)):
            continue
        end

        # FIXME: This is an inaccurate hack to handle try-except-finally
        # statement which is parsed as ast.TryExcept in ast.TryFinally in
        # Python 2.
        if (PY2 and
                isinstance(node, ast.TryFinally) and
                len(node.body) == 1 and
                isinstance(node.body[0], ast.TryExcept)):
            continue
        end

        for body in bodies:
            skip_next = False
            for i, child in enumerate(body):
                if skip_next:
                    skip_next = False
                elif is_end_node(child):
                    raise SyntaxError(
                        '"end" does not close a block.',
                        [filename, child.lineno, child.col_offset,
                         source.splitlines()[child.lineno - 1] + '\n'])
                elif get_compound_bodies(child):
                    try:
                        ok = is_end_node(body[i + 1])
                    except IndexError:
                        ok = False
                    end
                    if not ok:
                        raise SyntaxError(
                            'This block is not closed with "end".',
                            [filename, child.lineno, child.col_offset,
                             source.splitlines()[child.lineno - 1] + '\n'])
                    end
                    skip_next = True
                end
            end
        end
    end
775278
def infer_from_frame_stack(self, ob_stack):
    
    logits, vf = self.sess.run([self.logits_t, self.value_function_t],
                               feed_dict={self.obs_t: ob_stack})
    return logits, vf
211917
def _BacktraceFromFramePtr(self, frame_ptr):
    """"""
    # expects frame_ptr to be a gdb.Value
    frame_objs = [PyFrameObjectPtr(frame) for frame
                  in self._IterateChainedList(frame_ptr, 'f_back')]

    # We want to output tracebacks in the same format python uses, so we have to
    # reverse the stack
    frame_objs.reverse()
    tb_strings = ['Traceback (most recent call last):']
    for frame in frame_objs:
      line_string = ('  File "%s", line %s, in %s' %
                     (frame.filename(),
                      str(frame.current_line_num()),
                      frame.co_name.proxyval(set())))
      tb_strings.append(line_string)
      line_string = '    %s' % frame.current_line().strip()
      tb_strings.append(line_string)
    return '\n'.join(tb_strings)