Skip to content

Commit 3cddcc6

Browse files
fix 415
1 parent 3995c12 commit 3cddcc6

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

bpython/curtsiesfrontend/interpreter.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ class BPythonFormatter(Formatter):
3636
them into the appropriate format string
3737
as defined above, then writes to the outfile
3838
object the final formatted string. This does not write real strings. It writes format string (FmtStr) objects.
39-
39+
4040
See the Pygments source for more info; it's pretty
4141
straightforward."""
42-
42+
4343
def __init__(self, color_scheme, **options):
4444
self.f_strings = {}
4545
for k, v in color_scheme.iteritems():
4646
self.f_strings[k] = '\x01%s' % (v,)
4747
Formatter.__init__(self, **options)
48-
48+
4949
def format(self, tokensource, outfile):
5050
o = ''
5151

@@ -54,7 +54,7 @@ def format(self, tokensource, outfile):
5454
token = token.parent
5555
o += "%s\x03%s\x04" % (self.f_strings[token], text)
5656
outfile.write(parse(o.rstrip()))
57-
57+
5858
class Interp(code.InteractiveInterpreter):
5959
def __init__(self, locals=None):
6060
"""Constructor.
@@ -128,7 +128,6 @@ def showtraceback(self):
128128
lexer = get_lexer_by_name("pytb", stripall=True)
129129

130130
self.format(tbtext,lexer)
131-
132131

133132
def format(self, tbtext, lexer):
134133
traceback_informative_formatter = BPythonFormatter(default_colors)

bpython/curtsiesfrontend/repl.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def process_simple_keypress(self, e):
667667
self.add_normal_character(e)
668668

669669
def send_current_block_to_external_editor(self, filename=None):
670-
text = self.send_to_external_editor(self.get_current_block().encode('utf8'))
670+
text = self.send_to_external_editor(self.get_current_block())
671671
lines = [line for line in text.split('\n')]
672672
while lines and not lines[-1].split():
673673
lines.pop()
@@ -679,11 +679,11 @@ def send_current_block_to_external_editor(self, filename=None):
679679
self.cursor_offset = len(self.current_line)
680680

681681
def send_session_to_external_editor(self, filename=None):
682-
for_editor = '### current bpython session - file will be reevaluated, ### lines will not be run\n'.encode('utf8')
683-
for_editor += ('\n'.join(line[len(self.ps1):] if line.startswith(self.ps1) else
684-
(line[len(self.ps2):] if line.startswith(self.ps2) else
685-
'### '+line)
686-
for line in self.getstdout().split('\n')).encode('utf8'))
682+
for_editor = u'### current bpython session - file will be reevaluated, ### lines will not be run\n'
683+
for_editor += '\n'.join(line[len(self.ps1):] if line.startswith(self.ps1) else
684+
(line[len(self.ps2):] if line.startswith(self.ps2) else
685+
'### '+line)
686+
for line in self.getstdout().split('\n'))
687687
text = self.send_to_external_editor(for_editor)
688688
lines = text.split('\n')
689689
self.history = [line for line in lines if line[:4] != '### ']

bpython/repl.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,11 +1046,14 @@ def send_to_external_editor(self, text, filename=None):
10461046
"""Returns modified text from an editor, or the oriignal text if editor exited with non-zero"""
10471047
editor_args = shlex.split(self.config.editor)
10481048
with tempfile.NamedTemporaryFile(suffix='.py') as temp:
1049-
temp.write(text)
1049+
temp.write(text.encode(getpreferredencoding()))
10501050
temp.flush()
10511051
if subprocess.call(editor_args + [temp.name]) == 0:
10521052
with open(temp.name) as f:
1053-
return f.read()
1053+
if py3:
1054+
return f.read()
1055+
else:
1056+
return f.read().decode(getpreferredencoding())
10541057
else:
10551058
return text
10561059

bpython/test/test_curtsies_repl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ def test_external_communication(self):
5353
self.repl.send_session_to_external_editor()
5454

5555
def test_external_communication_encoding(self):
56-
self.repl.display_lines.append(u'>>> åß∂ƒ')
57-
self.repl.send_session_to_external_editor()
56+
with captured_output():
57+
self.repl.display_lines.append(u'>>> "åß∂ƒ"')
58+
self.repl.send_session_to_external_editor()
5859

5960
def test_get_last_word(self):
6061
self.repl.rl_history.entries=['1','2 3','4 5 6']

0 commit comments

Comments
 (0)