Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
factor out redundant code from showtraceback and showsyntaxerror
  • Loading branch information
mlauter committed Sep 4, 2014
commit 8aca9a5de7170602ae922c7bc78c49ab09464345
27 changes: 5 additions & 22 deletions bpython/curtsiesfrontend/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,7 @@ def showsyntaxerror(self, filename=None):
l = traceback.format_exception_only(type, value)
tbtext = ''.join(l)
lexer = get_lexer_by_name("pytb")
traceback_informative_formatter = BPythonFormatter(default_colors)
traceback_code_formatter = BPythonFormatter({Token: ('d')})
tokens= list(lexer.get_tokens(tbtext))
no_format_mode = False
cur_line = []
for token, text in tokens:
if text.endswith('\n'):
cur_line.append((token,text))
if no_format_mode:
traceback_code_formatter.format(cur_line, self.outfile)
no_format_mode = False
else:
traceback_informative_formatter.format(cur_line, self.outfile)
cur_line = []
elif text == ' ' and cur_line == []:
no_format_mode = True
cur_line.append((token,text))
else:
cur_line.append((token,text))
assert cur_line == [], cur_line
self.format(tbtext,lexer)

def showtraceback(self):
"""Display the exception that just occurred.
Expand All @@ -147,7 +128,10 @@ def showtraceback(self):
tbtext = ''.join(l)
lexer = get_lexer_by_name("pytb", stripall=True)

self.format(tbtext,lexer)


def format(self, tbtext, lexer):
traceback_informative_formatter = BPythonFormatter(default_colors)
traceback_code_formatter = BPythonFormatter({Token: ('d')})
tokens= list(lexer.get_tokens(tbtext))
Expand All @@ -168,5 +152,4 @@ def showtraceback(self):
cur_line.append((token,text))
else:
cur_line.append((token,text))
assert cur_line == []

assert cur_line == [], cur_line