| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -195,20 +195,30 @@ def request_from_main_greenlet(self, force_refresh=False): | |||
| 195 | 195 | ||
| 196 | 196 | ||
| 197 | 197 | class FakeOutput(object): | |
| 198 | - def __init__(self, coderunner, on_write): | ||
| 198 | + def __init__(self, coderunner, on_write, fileno=1): | ||
| 199 | 199 | """Fakes sys.stdout or sys.stderr | |
| 200 | 200 | ||
| 201 | 201 | 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). | ||
| 202 | 205 | """ | |
| 203 | 206 | self.coderunner = coderunner | |
| 204 | 207 | self.on_write = on_write | |
| 208 | + self.real_fileno = fileno | ||
| 205 | 209 | ||
| 206 | 210 | def write(self, s, *args, **kwargs): | |
| 207 | 211 | if not py3 and isinstance(s, str): | |
| 208 | 212 | s = s.decode(getpreferredencoding(), 'ignore') | |
| 209 | 213 | self.on_write(s, *args, **kwargs) | |
| 210 | 214 | return self.coderunner.request_from_main_greenlet(force_refresh=True) | |
| 211 | 215 | ||
| 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 | + | ||
| 212 | 222 | def writelines(self, l): | |
| 213 | 223 | for s in l: | |
| 214 | 224 | self.write(s) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -389,8 +389,13 @@ def __init__(self, | |||
| 389 | 389 | self.orig_tcattrs = orig_tcattrs | |
| 390 | 390 | ||
| 391 | 391 | 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 | + | ||
| 393 | + # filenos match the backing device for libs that expect it, | ||
| 394 | + # but writing to them will do weird things to the display | ||
| 395 | + self.stdout = FakeOutput(self.coderunner, self.send_to_stdout, | ||
| 396 | + fileno=sys.__stdout__.fileno()) | ||
| 397 | + self.stderr = FakeOutput(self.coderunner, self.send_to_stderr, | ||
| 398 | + fileno=sys.__stderr__.fileno()) | ||
| 394 | 399 | self.stdin = FakeStdin(self.coderunner, self, self.edit_keys) | |
| 395 | 400 | ||
| 396 | 401 | # next paint should clear screen | |
| Back | FazBrowse Home | New Git URL |
0 commit comments