1414import unicodedata
1515
1616from pygments import format
17- from bpython ._py3compat import PythonLexer , cast_bytes
17+ from bpython ._py3compat import PythonLexer
1818from pygments .formatters import TerminalFormatter
1919
2020import blessings
2626
2727import bpython
2828from 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
3031from bpython .formatter import BPythonFormatter
3132from bpython import autocomplete , importcompletion
3233from 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