@@ -229,7 +229,7 @@ def readline(self):
229
229
value = self .readline_results .pop (0 )
230
230
else :
231
231
value = 'no saved input available'
232
- self .repl .send_to_stdout (value )
232
+ self .repl .send_to_stdouterr (value )
233
233
return value
234
234
235
235
@@ -333,7 +333,7 @@ def __init__(self,
333
333
334
334
if interp is None :
335
335
interp = Interp (locals = locals_ )
336
- interp .write = self .send_to_stderr
336
+ interp .write = self .send_to_stdouterr
337
337
if banner is None :
338
338
if config .help_key :
339
339
banner = (_ ('Welcome to bpython!' ) + ' ' +
@@ -393,9 +393,9 @@ def __init__(self,
393
393
394
394
# filenos match the backing device for libs that expect it,
395
395
# but writing to them will do weird things to the display
396
- self .stdout = FakeOutput (self .coderunner , self .send_to_stdout ,
396
+ self .stdout = FakeOutput (self .coderunner , self .send_to_stdouterr ,
397
397
fileno = sys .__stdout__ .fileno ())
398
- self .stderr = FakeOutput (self .coderunner , self .send_to_stderr ,
398
+ self .stderr = FakeOutput (self .coderunner , self .send_to_stdouterr ,
399
399
fileno = sys .__stderr__ .fileno ())
400
400
self .stdin = FakeStdin (self .coderunner , self , self .edit_keys )
401
401
@@ -1140,27 +1140,16 @@ def clear_current_block(self, remove_from_history=True):
1140
1140
def get_current_block (self ):
1141
1141
return '\n ' .join (self .buffer + [self .current_line ])
1142
1142
1143
- def move_current_stdouterr_line_up (self ):
1144
- """Append self.current_stdouterr_line to self.display_lines
1145
- then clean it."""
1146
- self .display_lines .extend (paint .display_linize (
1147
- self .current_stdouterr_line , self .width ))
1148
- self .current_stdouterr_line = ''
1143
+ def send_to_stdouterr (self , output ):
1144
+ """Send unicode strings or FmtStr to Repl stdout or stderr
1149
1145
1150
- def send_to_stdout ( self , output ):
1151
- """Send unicode string to Repl stdout """
1146
+ Must be able to handle FmtStrs because interpreter pass in
1147
+ tracebacks already formatted. """
1152
1148
if not output :
1153
1149
return
1154
1150
lines = output .split ('\n ' )
1155
- if all (not line for line in lines ):
1156
- # If the string consist only of newline characters,
1157
- # str.split returns one more empty strings.
1158
- lines = lines [:- 1 ]
1159
1151
logger .debug ('display_lines: %r' , self .display_lines )
1160
- if lines [0 ]:
1161
- self .current_stdouterr_line += lines [0 ]
1162
- else :
1163
- self .move_current_stdouterr_line_up ()
1152
+ self .current_stdouterr_line += lines [0 ]
1164
1153
if len (lines ) > 1 :
1165
1154
self .display_lines .extend (paint .display_linize (
1166
1155
self .current_stdouterr_line , self .width , blank_line = True ))
@@ -1171,26 +1160,6 @@ def send_to_stdout(self, output):
1171
1160
self .current_stdouterr_line = lines [- 1 ]
1172
1161
logger .debug ('display_lines: %r' , self .display_lines )
1173
1162
1174
- def send_to_stderr (self , error ):
1175
- """Send unicode strings or FmtStr to Repl stderr
1176
-
1177
- Must be able to handle FmtStrs because interpreter pass in
1178
- tracebacks already formatted."""
1179
- if not error :
1180
- return
1181
- lines = error .split ('\n ' )
1182
- if all (not line for line in lines ):
1183
- # If the string consist only of newline characters,
1184
- # str.split returns one more empty strings.
1185
- lines = lines [:- 1 ]
1186
- if lines [- 1 ]:
1187
- self .current_stdouterr_line += lines [- 1 ]
1188
- else :
1189
- self .move_current_stdouterr_line_up ()
1190
- self .display_lines .extend (sum ((paint .display_linize (line , self .width ,
1191
- blank_line = True )
1192
- for line in lines [:- 1 ]), []))
1193
-
1194
1163
def send_to_stdin (self , line ):
1195
1164
if line .endswith ('\n ' ):
1196
1165
self .display_lines .extend (
@@ -1653,7 +1622,7 @@ def reevaluate(self, insert_into_history=False):
1653
1622
1654
1623
if not self .weak_rewind :
1655
1624
self .interp = self .interp .__class__ ()
1656
- self .interp .write = self .send_to_stderr
1625
+ self .interp .write = self .send_to_stdouterr
1657
1626
self .coderunner .interp = self .interp
1658
1627
self .initialize_interp ()
1659
1628
0 commit comments