def trace(self, frame, event, arg): if not self._is_traced_frame(frame): if (self.depth == 1 or self._is_internal_frame(frame) ) and not is_comprehension_frame(frame): return None else: candidate = frame i = 0 while True: if is_comprehension_frame(candidate): candidate = candidate.f_back 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 == '<genexpr>' 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
def __init__(self, frame): self.frame = frame self.local_reprs = {} self.last_line_no = frame.f_lineno self.comprehension_variables = OrderedDict() self.source = Source.for_frame(frame) self.is_generator = frame.f_code.co_flags & inspect.CO_GENERATOR self.had_exception = False if is_comprehension_frame(frame): self.comprehension_type = (re.match( r'<(\w+)comp>', frame.f_code.co_name).group(1).title() + u' comprehension') else: self.comprehension_type = ''
def __init__(self, frame): self.frame = frame self.local_reprs = {} self.last_line_no = frame.f_lineno self.comprehension_variables = OrderedDict() self.source = Source.for_frame(frame) code = frame.f_code self.is_generator = code.co_flags & inspect.CO_GENERATOR self.had_exception = False if is_comprehension_frame(frame): self.comprehension_type = ( re.match(r'<(\w+)comp>', code.co_name).group(1).title() + u' comprehension') else: self.comprehension_type = '' self.is_ipython_cell = (code.co_name == '<module>' and code.co_filename.startswith('<ipython-input-'))