2929 Name .Class :'d' ,
3030 }
3131
32-
3332class BPythonFormatter (Formatter ):
3433 """This is subclassed from the custom formatter for bpython.
3534 Its format() method receives the tokensource
@@ -58,7 +57,7 @@ def format(self, tokensource, outfile):
5857 outfile .write (str (parse (o .rstrip ())))
5958
6059class Interp (code .InteractiveInterpreter ):
61- def __init__ (self , locals = None , outfile = sys . __stderr__ ):
60+ def __init__ (self , locals = None ):
6261 """Constructor.
6362
6463 The optional 'locals' argument specifies the dictionary in
@@ -73,7 +72,10 @@ def __init__(self, locals=None, outfile=sys.__stderr__):
7372 locals = {"__name__" : "__console__" , "__doc__" : None }
7473 self .locals = locals
7574 self .compile = CommandCompiler ()
76- self .outfile = outfile
75+
76+ # typically changed after being instantiated
77+ self .write = lambda stuff : sys .stderr .write (stuff )
78+ self .outfile = self
7779
7880 def showsyntaxerror (self , filename = None ):
7981 """Display the syntax error that just occurred.
@@ -113,10 +115,10 @@ def showsyntaxerror(self, filename=None):
113115 if text .endswith ('\n ' ):
114116 cur_line .append ((token ,text ))
115117 if no_format_mode :
116- traceback_code_formatter .format (cur_line ,self .outfile )
118+ traceback_code_formatter .format (cur_line , self .outfile )
117119 no_format_mode = False
118120 else :
119- traceback_informative_formatter .format (cur_line ,self .outfile )
121+ traceback_informative_formatter .format (cur_line , self .outfile )
120122 cur_line = []
121123 elif text == ' ' and cur_line == []:
122124 no_format_mode = True
@@ -154,10 +156,10 @@ def showtraceback(self):
154156 if text .endswith ('\n ' ):
155157 cur_line .append ((token ,text ))
156158 if no_format_mode :
157- traceback_code_formatter .format (cur_line ,self .outfile )
159+ traceback_code_formatter .format (cur_line , self .outfile )
158160 no_format_mode = False
159161 else :
160- traceback_informative_formatter .format (cur_line ,self .outfile )
162+ traceback_informative_formatter .format (cur_line , self .outfile )
161163 cur_line = []
162164 elif text == ' ' and cur_line == []:
163165 no_format_mode = True
0 commit comments