|
42 | 42 | #TODO options.interactive, .quiet |
43 | 43 | #TODO execute file if in args |
44 | 44 | #TODO working raw_input |
| 45 | +#TODO use events instead of length-one queues for interthread communication |
45 | 46 |
|
46 | 47 | from bpython.keys import cli_key_dispatch as key_dispatch |
47 | 48 |
|
| 49 | +#TODO not that this object is custom, it should do more (not treated like a StringIO) |
| 50 | +class FakeStdout(object): |
| 51 | + def __init__(self): |
| 52 | + self.data = StringIO() |
| 53 | + def seek(self, pos, mode=0): return self.data.seek(pos, mode) |
| 54 | + def tell(self): return self.data.tell() |
| 55 | + def read(self, n=None): |
| 56 | + data = self.data.read() |
| 57 | + if isinstance(data, bytes): |
| 58 | + return data.decode('utf8') |
| 59 | + else: |
| 60 | + return data |
| 61 | + def write(self, msg): |
| 62 | + if isinstance(msg, bytes): |
| 63 | + return self.data.write(msg.encode('uft8')) |
| 64 | + else: |
| 65 | + return self.data.write(msg) |
| 66 | + |
48 | 67 | class FakeStdin(object): |
49 | 68 | def __init__(self, on_receive_tuple): |
50 | 69 | self.request_from_executing_code = Queue.Queue(maxsize=1) |
@@ -162,7 +181,7 @@ def __enter__(self): |
162 | 181 | self.orig_stdout = sys.stdout |
163 | 182 | self.orig_stderr = sys.stderr |
164 | 183 | self.orig_stdin = sys.stdin |
165 | | - sys.stdout = StringIO() |
| 184 | + sys.stdout = FakeStdout() |
166 | 185 | sys.stderr = StringIO() |
167 | 186 | sys.stdin = self.stdin |
168 | 187 | return self |
|
0 commit comments