Skip to content

Commit c2c9e84

Browse files
committed
Added fileno support to FakeOutput
1 parent 937865a commit c2c9e84

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

bpython/curtsiesfrontend/coderunner.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,30 @@ def request_from_main_greenlet(self, force_refresh=False):
195195

196196

197197
class FakeOutput(object):
198-
def __init__(self, coderunner, on_write):
198+
def __init__(self, coderunner, on_write, fileno=1):
199199
"""Fakes sys.stdout or sys.stderr
200200
201201
on_write should always take unicode
202+
203+
fileno should be the fileno that on_write will
204+
output to (e.g. 1 for standard output).
202205
"""
203206
self.coderunner = coderunner
204207
self.on_write = on_write
208+
self.real_fileno = fileno
205209

206210
def write(self, s, *args, **kwargs):
207211
if not py3 and isinstance(s, str):
208212
s = s.decode(getpreferredencoding(), 'ignore')
209213
self.on_write(s, *args, **kwargs)
210214
return self.coderunner.request_from_main_greenlet(force_refresh=True)
211215

216+
# Some applications which use curses require that sys.stdout
217+
# have a method called fileno. One example is pwntools. This
218+
# is not a widespread issue, but is annoying.
219+
def fileno(self):
220+
return self.real_fileno
221+
212222
def writelines(self, l):
213223
for s in l:
214224
self.write(s)

bpython/curtsiesfrontend/repl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,9 @@ def __init__(self,
389389
self.orig_tcattrs = orig_tcattrs
390390

391391
self.coderunner = CodeRunner(self.interp, self.request_refresh)
392-
self.stdout = FakeOutput(self.coderunner, self.send_to_stdout)
393-
self.stderr = FakeOutput(self.coderunner, self.send_to_stderr)
392+
# Added explicit fileno definitions to reflect to backend device
393+
self.stdout = FakeOutput(self.coderunner, self.send_to_stdout, fileno=1)
394+
self.stderr = FakeOutput(self.coderunner, self.send_to_stderr, fileno=2)
394395
self.stdin = FakeStdin(self.coderunner, self, self.edit_keys)
395396

396397
# next paint should clear screen

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy