Skip to content

Commit 8b3f9f7

Browse files
Add encoding attribute to fake stdout/stderr.
Start storing an original file object on the fake one.
1 parent c828fad commit 8b3f9f7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

bpython/curtsiesfrontend/coderunner.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def request_from_main_greenlet(self, force_refresh=False):
195195

196196

197197
class FakeOutput(object):
198-
def __init__(self, coderunner, on_write, fileno=1):
198+
def __init__(self, coderunner, on_write, real_fileobj):
199199
"""Fakes sys.stdout or sys.stderr
200200
201201
on_write should always take unicode
@@ -205,7 +205,7 @@ def __init__(self, coderunner, on_write, fileno=1):
205205
"""
206206
self.coderunner = coderunner
207207
self.on_write = on_write
208-
self.real_fileno = fileno
208+
self._real_fileobj = real_fileobj
209209

210210
def write(self, s, *args, **kwargs):
211211
if not py3 and isinstance(s, str):
@@ -217,7 +217,7 @@ def write(self, s, *args, **kwargs):
217217
# have a method called fileno. One example is pwntools. This
218218
# is not a widespread issue, but is annoying.
219219
def fileno(self):
220-
return self.real_fileno
220+
return self._real_fileobj.fileno()
221221

222222
def writelines(self, l):
223223
for s in l:
@@ -228,3 +228,7 @@ def flush(self):
228228

229229
def isatty(self):
230230
return True
231+
232+
@property
233+
def encoding(self):
234+
return self._real_fileobj.encoding

bpython/curtsiesfrontend/repl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ def __init__(self,
393393
# filenos match the backing device for libs that expect it,
394394
# but writing to them will do weird things to the display
395395
self.stdout = FakeOutput(self.coderunner, self.send_to_stdout,
396-
fileno=sys.__stdout__.fileno())
396+
real_fileobj=sys.__stdout__)
397397
self.stderr = FakeOutput(self.coderunner, self.send_to_stderr,
398-
fileno=sys.__stderr__.fileno())
398+
real_fileobj=sys.__stderr__)
399399
self.stdin = FakeStdin(self.coderunner, self, self.edit_keys)
400400

401401
# next paint should clear screen

0 commit comments

Comments
 (0)