From 55c26557de4f9303eec1ce97b0c1b8fd5f167d98 Mon Sep 17 00:00:00 2001 From: Tom Ballinger Date: Sat, 19 Aug 2017 12:49:35 -0700 Subject: [PATCH 1/2] fix encoding issues in urwid and curses --- bpython/cli.py | 12 +++++++++--- bpython/urwid.py | 14 +++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bpython/cli.py b/bpython/cli.py index c7a540283..6fb0594ea 100644 --- a/bpython/cli.py +++ b/bpython/cli.py @@ -330,7 +330,7 @@ def __init__(self, scr, interp, statusbar, config, idle=None): repl.Repl.__init__(self, interp, config) self.interp.writetb = self.writetb self.scr = scr - self.stdout_hist = '' + self.stdout_hist = '' # str (bytes in Py2, unicode in Py3) self.list_win = newwin(get_colpair(config, 'background'), 1, 1, 1, 1) self.cpos = 0 self.do_exit = False @@ -1066,13 +1066,19 @@ def prompt(self, more): """Show the appropriate Python prompt""" if not more: self.echo("\x01%s\x03%s" % (self.config.color_scheme['prompt'], self.ps1)) - self.stdout_hist += self.ps1 + if py3: + self.stdout_hist += self.ps1 + else: + self.stdout_hist += self.ps1.encode(getpreferredencoding()) self.s_hist.append('\x01%s\x03%s\x04' % (self.config.color_scheme['prompt'], self.ps1)) else: prompt_more_color = self.config.color_scheme['prompt_more'] self.echo("\x01%s\x03%s" % (prompt_more_color, self.ps2)) - self.stdout_hist += self.ps2 + if py3: + self.stdout_hist += self.ps2 + else: + self.stdout_hist += self.ps2.encode(getpreferredencoding()) self.s_hist.append('\x01%s\x03%s\x04' % (prompt_more_color, self.ps2)) def push(self, s, insert_into_history=True): diff --git a/bpython/urwid.py b/bpython/urwid.py index c81843d9f..bcaf53460 100644 --- a/bpython/urwid.py +++ b/bpython/urwid.py @@ -596,7 +596,7 @@ def __init__(self, event_loop, palette, interpreter, config): self.tooltip = urwid.ListBox(urwid.SimpleListWalker([])) self.tooltip.grid = None self.overlay = Tooltip(self.listbox, self.tooltip) - self.stdout_hist = '' + self.stdout_hist = '' # str (bytes in Py2, unicode in Py3) self.frame = urwid.Frame(self.overlay) @@ -976,17 +976,17 @@ def prompt(self, more): # input to be the same type, using ascii as encoding. If the # caption is bytes this breaks typing non-ascii into bpython. if not more: + caption = ('prompt', self.ps1) if py3: - caption = ('prompt', self.ps1) + self.stdout_hist += self.ps1 else: - caption = ('prompt', self.ps1.decode(getpreferredencoding())) - self.stdout_hist += self.ps1 + self.stdout_hist += self.ps1.encode(getpreferredencoding()) else: + caption = ('prompt_more', self.ps2) if py3: - caption = ('prompt_more', self.ps2) + self.stdout_hist += self.ps2 else: - caption = ('prompt_more', self.ps2.decode(getpreferredencoding())) - self.stdout_hist += self.ps2 + self.stdout_hist += self.ps2.encode(getpreferredencoding()) self.edit = BPythonEdit(self.config, caption=caption) urwid.connect_signal(self.edit, 'change', self.on_input_change) From 143757c568bc016261cb5459586c9cb069697162 Mon Sep 17 00:00:00 2001 From: Tom Ballinger Date: Sun, 20 Aug 2017 16:11:55 -0700 Subject: [PATCH 2/2] terminology change: native str --- bpython/cli.py | 2 +- bpython/urwid.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bpython/cli.py b/bpython/cli.py index 6fb0594ea..a8f9ba2f8 100644 --- a/bpython/cli.py +++ b/bpython/cli.py @@ -330,7 +330,7 @@ def __init__(self, scr, interp, statusbar, config, idle=None): repl.Repl.__init__(self, interp, config) self.interp.writetb = self.writetb self.scr = scr - self.stdout_hist = '' # str (bytes in Py2, unicode in Py3) + self.stdout_hist = '' # native str (bytes in Py2, unicode in Py3) self.list_win = newwin(get_colpair(config, 'background'), 1, 1, 1, 1) self.cpos = 0 self.do_exit = False diff --git a/bpython/urwid.py b/bpython/urwid.py index bcaf53460..acb153a27 100644 --- a/bpython/urwid.py +++ b/bpython/urwid.py @@ -596,7 +596,7 @@ def __init__(self, event_loop, palette, interpreter, config): self.tooltip = urwid.ListBox(urwid.SimpleListWalker([])) self.tooltip.grid = None self.overlay = Tooltip(self.listbox, self.tooltip) - self.stdout_hist = '' # str (bytes in Py2, unicode in Py3) + self.stdout_hist = '' # native str (bytes in Py2, unicode in Py3) self.frame = urwid.Frame(self.overlay)