29
29
Name .Class :'d' ,
30
30
}
31
31
32
-
33
32
class BPythonFormatter (Formatter ):
34
33
"""This is subclassed from the custom formatter for bpython.
35
34
Its format() method receives the tokensource
@@ -58,7 +57,7 @@ def format(self, tokensource, outfile):
58
57
outfile .write (str (parse (o .rstrip ())))
59
58
60
59
class Interp (code .InteractiveInterpreter ):
61
- def __init__ (self , locals = None , outfile = sys . __stderr__ ):
60
+ def __init__ (self , locals = None ):
62
61
"""Constructor.
63
62
64
63
The optional 'locals' argument specifies the dictionary in
@@ -73,7 +72,10 @@ def __init__(self, locals=None, outfile=sys.__stderr__):
73
72
locals = {"__name__" : "__console__" , "__doc__" : None }
74
73
self .locals = locals
75
74
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
77
79
78
80
def showsyntaxerror (self , filename = None ):
79
81
"""Display the syntax error that just occurred.
@@ -113,10 +115,10 @@ def showsyntaxerror(self, filename=None):
113
115
if text .endswith ('\n ' ):
114
116
cur_line .append ((token ,text ))
115
117
if no_format_mode :
116
- traceback_code_formatter .format (cur_line ,self .outfile )
118
+ traceback_code_formatter .format (cur_line , self .outfile )
117
119
no_format_mode = False
118
120
else :
119
- traceback_informative_formatter .format (cur_line ,self .outfile )
121
+ traceback_informative_formatter .format (cur_line , self .outfile )
120
122
cur_line = []
121
123
elif text == ' ' and cur_line == []:
122
124
no_format_mode = True
@@ -154,10 +156,10 @@ def showtraceback(self):
154
156
if text .endswith ('\n ' ):
155
157
cur_line .append ((token ,text ))
156
158
if no_format_mode :
157
- traceback_code_formatter .format (cur_line ,self .outfile )
159
+ traceback_code_formatter .format (cur_line , self .outfile )
158
160
no_format_mode = False
159
161
else :
160
- traceback_informative_formatter .format (cur_line ,self .outfile )
162
+ traceback_informative_formatter .format (cur_line , self .outfile )
161
163
cur_line = []
162
164
elif text == ' ' and cur_line == []:
163
165
no_format_mode = True
0 commit comments