X Tutup
Skip to content

Commit 5498a38

Browse files
committed
deal with cases that locale.getpreferredencoding returns None - which apparently it does for some dude's setup; delegate to sys.getdefaultencoding
1 parent c38d9e7 commit 5498a38

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

bpython/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
import unicodedata
3838
import errno
3939

40-
from locale import LC_ALL, getpreferredencoding, setlocale
40+
from locale import LC_ALL, setlocale
41+
import locale
4142
from types import ModuleType
4243

4344
# These are used for syntax hilighting.
@@ -60,14 +61,15 @@
6061
from bpython.pager import page
6162
import bpython.args
6263

63-
6464
def log(x):
6565
f = open('/tmp/bpython.log', 'a')
6666
f.write('%s\n' % (x,))
6767

6868
py3 = sys.version_info[0] == 3
6969
stdscr = None
7070

71+
def getpreferredencoding():
72+
return locale.getpreferredencoding() or sys.getdefaultencoding()
7173

7274
def calculate_screen_lines(tokens, width, cursor=0):
7375
"""Given a stream of tokens and a screen width plus an optional

bpython/repl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
class Interpreter(code.InteractiveInterpreter):
6262

63-
def __init__(self, locals=None, encoding=sys.getdefaultencoding()):
63+
def __init__(self, locals=None, encoding=None):
6464
"""The syntaxerror callback can be set at any time and will be called
6565
on a caught syntax error. The purpose for this in bpython is so that
6666
the repl can be instantiated after the interpreter (which it
@@ -69,7 +69,7 @@ def __init__(self, locals=None, encoding=sys.getdefaultencoding()):
6969
specifically, this is so that autoindentation does not occur after a
7070
traceback."""
7171

72-
self.encoding = encoding
72+
self.encoding = encoding or sys.getdefaultencoding()
7373
self.syntaxerror_callback = None
7474
# Unfortunately code.InteractiveInterpreter is a classic class, so no super()
7575
code.InteractiveInterpreter.__init__(self, locals)

0 commit comments

Comments
 (0)
X Tutup