Skip to content

Commit 4559328

Browse files
Use Curtsies interpreter for -i file
1 parent 427d371 commit 4559328

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

bpython/curtsies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from bpython.curtsiesfrontend.repl import BaseRepl
1515
from bpython.curtsiesfrontend.coderunner import SystemExitFromCodeGreenlet
16+
from bpython.curtsiesfrontend.interpreter import Interp
1617
from bpython import args as bpargs
1718
from bpython import translations
1819
from bpython.translations import _
@@ -165,7 +166,7 @@ def main(args=None, locals_=None, banner=None, welcome_message=None):
165166
paste.events.extend(sourcecode)
166167
else:
167168
try:
168-
interp = code.InteractiveInterpreter(locals=locals_)
169+
interp = Interp(locals=locals_)
169170
bpargs.exec_code(interp, exec_args)
170171
except SystemExit as e:
171172
exit_value = e.args

bpython/curtsiesfrontend/interpreter.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from codeop import CommandCompiler
3-
from six import iteritems
3+
from six import iteritems, text_type
44

55
from pygments.token import Generic, Token, Keyword, Name, Comment, String
66
from pygments.token import Error, Literal, Number, Operator, Punctuation
@@ -83,7 +83,14 @@ def __init__(self, locals=None, encoding=None):
8383
self.compile = CommandCompiler()
8484

8585
# typically changed after being instantiated
86-
self.write = lambda stuff: sys.stderr.write(stuff)
86+
# but used when interpreter used corresponding REPL
87+
def write(err_line):
88+
"""Default stderr handler for tracebacks
89+
90+
Accepts FmtStrs so interpreters can output them"""
91+
sys.stderr.write(text_type(err_line))
92+
93+
self.write = write
8794
self.outfile = self
8895

8996
def writetb(self, lines):

bpython/curtsiesfrontend/repl.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ def get_current_block(self):
11191119
return '\n'.join(self.buffer + [self.current_line])
11201120

11211121
def send_to_stdout(self, output):
1122+
"""Send unicode string to Repl stdout"""
11221123
lines = output.split('\n')
11231124
logger.debug('display_lines: %r', self.display_lines)
11241125
self.current_stdouterr_line += lines[0]
@@ -1133,6 +1134,10 @@ def send_to_stdout(self, output):
11331134
logger.debug('display_lines: %r', self.display_lines)
11341135

11351136
def send_to_stderr(self, error):
1137+
"""Send unicode strings or FmtStr to Repl stderr
1138+
1139+
Must be able to handle FmtStrs because interepter pass in
1140+
tracebacks already formatted."""
11361141
lines = error.split('\n')
11371142
if lines[-1]:
11381143
self.current_stdouterr_line += lines[-1]

0 commit comments

Comments
 (0)