Implementation of traceeback.

    This version can produce empty tracebacks, which we generally don't want
    users seeing. So the higher level `tracebacks` filters those out.
504768
def _tracebacks(score_matrix, traceback_matrix, idx):
    
    score = score_matrix[idx]
    if score == 0:
        yield ()
        return

    directions = traceback_matrix[idx]

    assert directions != Direction.NONE, 'Tracebacks with direction NONE should have value 0!'

    row, col = idx

    if directions & Direction.UP.value:
        for tb in _tracebacks(score_matrix, traceback_matrix, (row - 1, col)):
            yield itertools.chain(tb, ((idx, Direction.UP),))

    if directions & Direction.LEFT.value:
        for tb in _tracebacks(score_matrix, traceback_matrix, (row, col - 1)):
            yield itertools.chain(tb, ((idx, Direction.LEFT),))

    if directions & Direction.DIAG.value:
        for tb in _tracebacks(score_matrix, traceback_matrix, (row - 1, col - 1)):
            yield itertools.chain(tb, ((idx, Direction.DIAG),))
1154189
def clear_trace_filter_cache():
    '''
    
    '''
    global should_trace_hook
    try:
        # Need to temporarily disable a hook because otherwise
        # _filename_to_ignored_lines.clear() will never complete.
        old_hook = should_trace_hook
        should_trace_hook = None

        # Clear the linecache
        linecache.clearcache()
        _filename_to_ignored_lines.clear()

    finally:
        should_trace_hook = old_hook
279829
def _show_traceback(method):
    """"""
    def m(self, *args, **kwargs):
        try:
            return(method(self, *args, **kwargs))
        except Exception as e:
            ip = get_ipython()
            if ip is None:
                self.log.warning("Exception in widget method %s: %s", method, e, exc_info=True)
            else:
                ip.showtraceback()
    return m
269440
private boolean updateTraceSpec(TraceSpecification ts) {
        List<TraceElement> traceSpecs = ts.getSpecs();
        Integer minimumLevel = null;
        if (ts.isSensitiveTraceSuppressed()) {
            minimumLevel = findMinimumSafeLevel(ts.getSafeLevelsIndex());
        }

        int newFineLevel = fineLevel;
        int newFineLevelsEnabled = 0;
        int newSpecTraceLevel = TrLevelConstants.SPEC_TRACE_LEVEL_OFF;

        for (TraceElement spec : traceSpecs) {
            String clazz = spec.groupName;
            int traceElementFineLevel = spec.fineLevel;
            int specTraceLevel = spec.specTraceLevel;
            boolean setValue = spec.action;

            // Do we have a match with our package name?
            boolean process = false;

            if (clazz.endsWith("*")) // packages can end with wildcard
            {
                if (1 == clazz.length()) {
                    process = true;
                } else {
                    clazz = clazz.substring(0, clazz.length() - 1);
                    for (String group : groups) {
                        if (group.startsWith(clazz)) {
                            process = true;
                            break;
                        }
                    }
                    process = process || name.startsWith(clazz);
                }
            } else {
                // or can be a complete package or parent package
                // - look for a full or partial match with the TC package name
                int lastDot = name.lastIndexOf('.');
                if (lastDot > 0) {
                    String packageName = name.substring(0, lastDot);
                    if (packageName.startsWith(clazz))
                        process = true;
                }
                // groups may be class names (eg WsLogger impls)
                for (String group : groups) {
                    lastDot = group.lastIndexOf('.');
                    if (lastDot > 0) {
                        String packageName = group.substring(0, lastDot);
                        if (packageName.startsWith(clazz))
                            process = true;
                        break;
                    }
                }

                // could be a straight group name match
                for (String group : groups) {
                    if (group.equalsIgnoreCase(clazz)) {
                        process = true;
                        break;
                    }
                }
                process = process || name.equalsIgnoreCase(clazz);
            }

            if (process) {
                newFineLevel = traceElementFineLevel;
                newSpecTraceLevel = specTraceLevel;
                if (minimumLevel != null && newFineLevel < minimumLevel) {
                    newFineLevel = minimumLevel;
                }

                for (int level = newFineLevel; level < TrLevelConstants.TRACE_LEVEL_OFF; level++) {
                    if (setValue) {
                        newFineLevelsEnabled |= 1 << level;
                    } else {
                        newFineLevelsEnabled &= ~(1 << level);
                    }
                }
                
                if (newFineLevel == TrLevelConstants.TRACE_LEVEL_OFF) {
                	isTraceOff = true;
                } else {
                	isTraceOff = false;
                }
                // Indicate that the trace spec matched something
                spec.setMatched(true);
            }
        } // end for each spec

        boolean updated = false;
        if (newFineLevel != fineLevel) {
            fineLevel = newFineLevel;
            updated = true;
        }
        if (newFineLevelsEnabled != fineLevelsEnabled) {
            fineLevelsEnabled = newFineLevelsEnabled;
            updated = true;
        }
        if (newSpecTraceLevel != specTraceLevel) {
            specTraceLevel = newSpecTraceLevel;
            updated = true;
        }

        return updated;
    }
40256
def _excepthook(self, etype, evalue, trace):
        
        if etype == ArgumentParserError:
            self.exit(code=CRITICAL,
                      message='error: {0}'.format(evalue),
                      extdata=self.parser.format_usage())
        else:
            self.exit(code=UNKNOWN,
                      message='Uncaught exception: {0} - {1}'
                              .format(etype.__name__, evalue),
                      extdata=''.join(traceback.format_tb(trace)))
1066342
def trace():
    
    import traceback
    import sys
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    # script name + line number
    line = tbinfo.split(", ")[1]
    # Get Python syntax error
    #
    synerror = traceback.format_exc().splitlines()[-1]
    return line, __file__, synerror
1168924
def flush(self):
        

        if self.kind == TraceField:
            self.filehandle.putth(self.traceno, self.buf)

        elif self.kind == BinField:
            self.filehandle.putbin(self.buf)

        else:
            msg = 'Object corrupted: kind {} not valid'
            raise RuntimeError(msg.format(self.kind))
1121191
Set<TraceeBackendProvider> getDefaultTraceeBackendProvider() {
		try {
			final ClassLoader classLoader = GetClassLoader.fromContext();
			final Class<?> slf4jTraceeBackendProviderClass = Class.forName("io.tracee.backend.slf4j.Slf4jTraceeBackendProvider", true, classLoader);
			final TraceeBackendProvider instance = (TraceeBackendProvider) slf4jTraceeBackendProviderClass.newInstance();
			updatedCache(classLoader, Collections.singleton(instance));
			return Collections.singleton(instance);
		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | ClassCastException e) {
			return Collections.emptySet();
		}
	}
899505
public static void printStackTrace(StackTraceElement[] trace, java.io.PrintWriter out) {
        Strand.printStackTrace(trace, out);
    }
1261430
def make_traceback(exc_info, source_hint=None):
    """"""
    exc_type, exc_value, tb = exc_info
    if isinstance(exc_value, TemplateSyntaxError):
        exc_info = translate_syntax_error(exc_value, source_hint)
        initial_skip = 0
    else:
        initial_skip = 1
    return translate_exception(exc_info, initial_skip)
1004703
function processTraceOpts(options, defaults) {
  var opts = {
    // indicate to plugins to output ES modules instead of System.register for Rollup support
    outputESM: true,
    sourceMaps: false,

    // conditional tracing options
    browser: undefined,
    node: undefined,
    production: undefined,
    dev: undefined,
    conditions: {
      '@system-env|default': true,
      '@system-env|~default': false
    },
    inlineConditions: {},
    traceRuntimePlugin: true,

    // package config tracing (used for bundles only)
    tracePackageConfig: false,

    // when set, automatically excludes non-file URLs that don't resolve to canonical names
    // instead of showing the "Unable to calculate canonical name" error
    excludeURLs: true,
    externals: []
  };

  // ensure user environment overrides default environment
  if (typeof options == 'object') {
    if (typeof options.browser == 'boolean' || typeof options.node == 'boolean') {
      // browser true/false -> node is opposite
      if (typeof options.browser == 'boolean' && typeof options.node != 'boolean')
        options.node = !options.browser;
      // node true/false -> browser is opposite
      else if (typeof options.node == 'boolean' && typeof options.browser != 'boolean')
        options.browser = !options.node;
    }

    // development -> dev backwards compat
    if ('development' in options)
      options.dev = options.development;
    if (typeof options.dev == 'boolean' || typeof options.production == 'boolean') {
      if (typeof options.production != 'boolean')
        options.production = !options.dev;
      if (typeof options.dev != 'boolean')
        options.dev = !options.production;
    }
  }

  extend(opts, defaults);
  extend(opts, options);

  // globalDeps are externals
  if (opts.globalDeps)
    opts.externals = opts.externals.concat(Object.keys(opts.globalDeps));

  // conditional tracing defaults
  if (typeof opts.browser == 'boolean') {
    // browser, node   -> browser, ~browser, node, ~node
    // !browser, node  -> ~browser, node
    // browser, !node  -> browser, ~node
    // !browser, !node -> ~browser, ~node
    opts.conditions['@system-env|browser'] = opts.browser;
    opts.conditions['@system-env|~browser'] = opts.browser === true ? opts.node : !opts.browser;
    opts.conditions['@system-env|node'] = opts.node;
    opts.conditions['@system-env|~node'] = opts.node === true ? opts.browser : !opts.node;
  }
  if (typeof opts.production == 'boolean') {
    opts.conditions['@system-env|production'] = opts.production;
    opts.conditions['@system-env|~production'] = opts.dev;
    opts.conditions['@system-env|dev'] = opts.dev;
    opts.conditions['@system-env|~dev'] = opts.production;
  }

  if (typeof opts.inlineConditions == 'object')
    extend(opts.conditions, opts.inlineConditions);
  else if (opts.inlineConditions === true)
    opts.inlineConditions = opts.conditions;
  else
    opts.inlineConditions = {};

  return opts;
}
209346
def showtraceback(self, *args, **kwargs):
        """"""
        # Override for avoid using sys.excepthook PY-12600
        try:
            type, value, tb = sys.exc_info()
            sys.last_type = type
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            lines = traceback.format_list(tblist)
            if lines:
                lines.insert(0, "Traceback (most recent call last):\n")
            lines.extend(traceback.format_exception_only(type, value))
        finally:
            tblist = tb = None
        sys.stderr.write(''.join(lines))
686404
def traceback_string():
    
    tb_string = None
    exc_type, exc_value, exc_traceback = traceback.sys.exc_info()
    if exc_type is not None:
        display_lines_list = [str(exc_value)] + traceback.format_tb(exc_traceback)
        tb_string = "\n".join(display_lines_list)
    return tb_string
259587
def from_traceback(cls, tb):
        """"""
        stack_trace = cls(
            stack_trace_hash_id=generate_hash_id_from_traceback(tb)
        )
        # use the add_stack_frame so that json formatting is applied
        for tb_frame_info in traceback.extract_tb(tb):
            filename, line_num, fn_name, _ = tb_frame_info
            stack_trace.add_stack_frame(
                StackFrame(
                    func_name=fn_name,
                    original_func_name=fn_name,
                    file_name=filename,
                    line_num=line_num,
                    col_num=0,  # I don't think this is available in python
                    load_module=filename,
                    build_id=BUILD_ID,
                    source_version=SOURCE_VERSION
                )
            )
        return stack_trace
597124
def add_formatted_backtrace(out)
      _format_single(out, exception)
      current_backtrace = exception.backtrace
      cause = exception.cause
      until cause.nil?
        cause_trace = _unique_trace(cause.backtrace.to_a, current_backtrace)
        out.print "Caused by: "
        _format_single(out, cause, cause_trace)
        backtrace_length = cause.backtrace.length
        if backtrace_length > cause_trace.length
          out.print "\t... #{backtrace_length - cause_trace.length} more"
        end
        out.print "\n"
        current_backtrace = cause.backtrace
        cause = cause.cause
      end
    end
667240
def excepthook(cls, error, trace):
    
    global _excepthooks
    new_hooks = []

    for hook_ref in _excepthooks:
        hook = hook_ref()
        if hook:
            hook(cls, error, trace)
            new_hooks.append(hook_ref)

    _excepthook = new_hooks
    sys.__excepthook__(cls, error, trace)
482070
def trace_integration(tracer=None):
    """"""
    log.info('Integrated module: {}'.format(MODULE_NAME))

    if tracer is not None:
        # The execution_context tracer should never be None - if it has not
        # been set it returns a no-op tracer. Most code in this library does
        # not handle None being used in the execution context.
        execution_context.set_opencensus_tracer(tracer)

    # Wrap the requests functions
    for func in REQUESTS_WRAP_METHODS:
        requests_func = getattr(requests, func)
        wrapped = wrap_requests(requests_func)
        setattr(requests, requests_func.__name__, wrapped)

    # Wrap Session class
    wrapt.wrap_function_wrapper(
        MODULE_NAME, 'Session.request', wrap_session_request)