Пример #1
0
 def format_line(self, lineno, marker, line):
     lineno = '%4d' % lineno
     if self.config.highlight:
         lineno = setcolor(lineno, self.config.line_number_color)
     line = '%s  %2s %s' % (lineno, marker, line)
     if self.config.highlight and marker == '->':
         line = setbgcolor(line, self.config.current_line_color)
     return line
Пример #2
0
    def _print_if_sticky(self):
        if self.sticky:
            sys.stdout.write(CLEARSCREEN)
            frame, lineno = self.stack[self.curindex]
            filename = self.canonic(frame.f_code.co_filename)
            s = '> %s(%r)' % (filename, lineno)
            print s
            print
            sticky_range = self.sticky_ranges.get(self.curframe, None)
            self._printlonglist(sticky_range)

            if '__exception__' in frame.f_locals:
                exc = frame.f_locals['__exception__']
                if len(exc) == 2:
                    exc_type, exc_value = exc
                    s = ''
                    try:
                        try:
                            s = exc_type.__name__
                        except AttributeError:
                            s = str(exc_type)
                        if exc_value is not None:
                            s += ': '
                            s += str(exc_value)
                    except KeyboardInterrupt:
                        raise
                    except:
                        s += '(unprintable exception)'
                    print setcolor(' ' + s, self.config.line_number_color)
                    return
            if '__return__' in frame.f_locals:
                rv = frame.f_locals['__return__']
                try:
                    s = repr(rv)
                except KeyboardInterrupt:
                    raise
                except:
                    s = '(unprintable return value)'
                print setcolor(' return ' + s, self.config.line_number_color)