Skip to content

Commit 16b091a

Browse files
committed
Use unicode internally
Only encode when necessary. Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent dd29ad5 commit 16b091a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import unicodedata
1515

1616
from pygments import format
17-
from bpython._py3compat import PythonLexer, cast_bytes
17+
from bpython._py3compat import PythonLexer
1818
from pygments.formatters import TerminalFormatter
1919

2020
import blessings
@@ -26,7 +26,8 @@
2626

2727
import bpython
2828
from bpython.repl import Repl as BpythonRepl, SourceNotFound
29-
from bpython.config import Struct, loadini, default_config_path
29+
from bpython.config import Struct, loadini, default_config_path, \
30+
getpreferredencoding
3031
from bpython.formatter import BPythonFormatter
3132
from bpython import autocomplete, importcompletion
3233
from bpython.translations import _
@@ -1395,10 +1396,10 @@ def focus_on_subprocess(self, args):
13951396
def pager(self, text):
13961397
"""Runs an external pager on text
13971398
1398-
text must be a bytestring, ie not yet encoded"""
1399+
text must be a unicode"""
13991400
command = get_pager_command()
14001401
with tempfile.NamedTemporaryFile() as tmp:
1401-
tmp.write(text)
1402+
tmp.write(text.encode(getpreferredencoding()))
14021403
tmp.flush()
14031404
self.focus_on_subprocess(command + [tmp.name])
14041405

@@ -1409,14 +1410,12 @@ def show_source(self):
14091410
self.status_bar.message(str(e))
14101411
else:
14111412
if self.config.highlight_show_source:
1412-
source = cast_bytes(format(PythonLexer().get_tokens(source),
1413-
TerminalFormatter()))
1414-
else:
1415-
source = cast_bytes(source)
1413+
source = format(PythonLexer().get_tokens(source),
1414+
TerminalFormatter())
14161415
self.pager(source)
14171416

14181417
def help_text(self):
1419-
return cast_bytes(self.version_help_text() + '\n' + self.key_help_text())
1418+
return self.version_help_text() + '\n' + self.key_help_text()
14201419

14211420
def version_help_text(self):
14221421
return (('bpython-curtsies version %s' % bpython.__version__) + ' ' +

0 commit comments

Comments
 (0)