@@ -106,26 +106,7 @@ def showsyntaxerror(self, filename=None):
106
106
l = traceback .format_exception_only (type , value )
107
107
tbtext = '' .join (l )
108
108
lexer = get_lexer_by_name ("pytb" )
109
- traceback_informative_formatter = BPythonFormatter (default_colors )
110
- traceback_code_formatter = BPythonFormatter ({Token : ('d' )})
111
- tokens = list (lexer .get_tokens (tbtext ))
112
- no_format_mode = False
113
- cur_line = []
114
- for token , text in tokens :
115
- if text .endswith ('\n ' ):
116
- cur_line .append ((token ,text ))
117
- if no_format_mode :
118
- traceback_code_formatter .format (cur_line , self .outfile )
119
- no_format_mode = False
120
- else :
121
- traceback_informative_formatter .format (cur_line , self .outfile )
122
- cur_line = []
123
- elif text == ' ' and cur_line == []:
124
- no_format_mode = True
125
- cur_line .append ((token ,text ))
126
- else :
127
- cur_line .append ((token ,text ))
128
- assert cur_line == [], cur_line
109
+ self .format (tbtext ,lexer )
129
110
130
111
def showtraceback (self ):
131
112
"""Display the exception that just occurred.
@@ -147,7 +128,10 @@ def showtraceback(self):
147
128
tbtext = '' .join (l )
148
129
lexer = get_lexer_by_name ("pytb" , stripall = True )
149
130
131
+ self .format (tbtext ,lexer )
150
132
133
+
134
+ def format (self , tbtext , lexer ):
151
135
traceback_informative_formatter = BPythonFormatter (default_colors )
152
136
traceback_code_formatter = BPythonFormatter ({Token : ('d' )})
153
137
tokens = list (lexer .get_tokens (tbtext ))
@@ -168,5 +152,4 @@ def showtraceback(self):
168
152
cur_line .append ((token ,text ))
169
153
else :
170
154
cur_line .append ((token ,text ))
171
- assert cur_line == []
172
-
155
+ assert cur_line == [], cur_line
0 commit comments