How to use the snoop.formatting.Event function in snoop

To help you get started, we’ve selected a few snoop examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexmojaki / snoop / snoop / tracer.py View on Github external
thread_local.__dict__.setdefault('depth', -1)
        frame_info = self.frame_infos[frame]
        if event in ('call', 'enter'):
            thread_local.depth += 1
        elif self.config.last_frame and self.config.last_frame is not frame:
            line_no = frame_info.last_line_no
            trace_event = Event(frame_info, event, arg, thread_local.depth, line_no=line_no)
            line = self.config.formatter.format_line_only(trace_event)
            self.config.write(line)

        if event == 'exception':
            frame_info.had_exception = True

        self.config.last_frame = frame

        trace_event = Event(frame_info, event, arg, thread_local.depth)
        if not (frame.f_code.co_name == '' and event not in ('return', 'exception')):
            trace_event.variables = frame_info.update_variables(
                self.watch,
                self.config.watch_extras,
                event,
                self.variable_whitelist,
            )

        if event in ('return', 'exit'):
            del self.frame_infos[frame]
            thread_local.depth -= 1

        formatted = self.config.formatter.format(trace_event)
        self.config.write(formatted)

        return self.trace
github alexmojaki / snoop / snoop / tracer.py View on Github external
continue
                    i += 1
                    if self._is_traced_frame(candidate):
                        break
                    candidate = candidate.f_back
                    if i >= self.depth or candidate is None or self._is_internal_frame(candidate):
                        return None

        thread_local = self.config.thread_local
        thread_local.__dict__.setdefault('depth', -1)
        frame_info = self.frame_infos[frame]
        if event in ('call', 'enter'):
            thread_local.depth += 1
        elif self.config.last_frame and self.config.last_frame is not frame:
            line_no = frame_info.last_line_no
            trace_event = Event(frame_info, event, arg, thread_local.depth, line_no=line_no)
            line = self.config.formatter.format_line_only(trace_event)
            self.config.write(line)

        if event == 'exception':
            frame_info.had_exception = True

        self.config.last_frame = frame

        trace_event = Event(frame_info, event, arg, thread_local.depth)
        if not (frame.f_code.co_name == '' and event not in ('return', 'exception')):
            trace_event.variables = frame_info.update_variables(
                self.watch,
                self.config.watch_extras,
                event,
                self.variable_whitelist,
            )
github alexmojaki / snoop / snoop / pp_module.py View on Github external
def __init__(self, pp_object, args, deep):
        self.config = pp_object.config
        self.args = args
        depth = getattr(self.config.thread_local, 'depth', 0)
        frame = inspect.currentframe().f_back.f_back
        self.event = Event(FrameInfo(frame), 'log', None, depth)
        formatted = self.config.formatter.format_log(self.event)
        self.config.write(formatted)

        self.returns = None
        try:
            assert not NO_ASTTOKENS
            self.call = call = Source.executing(frame).node
            assert isinstance(call, ast.Call)
            assert len(args) == len(call.args)
        except Exception:
            if deep:
                self.returns = args[0] = args[0]()
            for i, arg in enumerate(args):
                self.write_placeholder(i, arg)
        else:
            if deep: