| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -205,7 +205,7 @@ def request_from_main_context(self, force_refresh=False): | |||
| 205 | 205 | ||
| 206 | 206 | ||
| 207 | 207 | class FakeOutput(object): | |
| 208 | - def __init__(self, coderunner, on_write, fileno=1): | ||
| 208 | + def __init__(self, coderunner, on_write, real_fileobj): | ||
| 209 | 209 | """Fakes sys.stdout or sys.stderr | |
| 210 | 210 | ||
| 211 | 211 | on_write should always take unicode | |
@@ -215,7 +215,7 @@ def __init__(self, coderunner, on_write, fileno=1): | |||
| 215 | 215 | """ | |
| 216 | 216 | self.coderunner = coderunner | |
| 217 | 217 | self.on_write = on_write | |
| 218 | - self.real_fileno = fileno | ||
| 218 | + self._real_fileobj = real_fileobj | ||
| 219 | 219 | ||
| 220 | 220 | def write(self, s, *args, **kwargs): | |
| 221 | 221 | if not py3 and isinstance(s, str): | |
@@ -227,7 +227,7 @@ def write(self, s, *args, **kwargs): | |||
| 227 | 227 | # have a method called fileno. One example is pwntools. This | |
| 228 | 228 | # is not a widespread issue, but is annoying. | |
| 229 | 229 | def fileno(self): | |
| 230 | - return self.real_fileno | ||
| 230 | + return self._real_fileobj.fileno() | ||
| 231 | 231 | ||
| 232 | 232 | def writelines(self, l): | |
| 233 | 233 | for s in l: | |
@@ -238,3 +238,7 @@ def flush(self): | |||
| 238 | 238 | ||
| 239 | 239 | def isatty(self): | |
| 240 | 240 | return True | |
| 241 | + | ||
| 242 | + @property | ||
| 243 | + def encoding(self): | ||
| 244 | + return self._real_fileobj.encoding | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -223,7 +223,7 @@ def close(self): | |||
| 223 | 223 | ||
| 224 | 224 | @property | |
| 225 | 225 | def encoding(self): | |
| 226 | - return "UTF8" | ||
| 226 | + return sys.__stdin__.encoding | ||
| 227 | 227 | ||
| 228 | 228 | # TODO write a read() method? | |
| 229 | 229 | ||
@@ -447,12 +447,12 @@ def __init__( | |||
| 447 | 447 | self.stdout = FakeOutput( | |
| 448 | 448 | self.coderunner, | |
| 449 | 449 | self.send_to_stdouterr, | |
| 450 | - fileno=sys.__stdout__.fileno(), | ||
| 450 | + real_fileobj=sys.__stdout__, | ||
| 451 | 451 | ) | |
| 452 | 452 | self.stderr = FakeOutput( | |
| 453 | 453 | self.coderunner, | |
| 454 | 454 | self.send_to_stdouterr, | |
| 455 | - fileno=sys.__stderr__.fileno(), | ||
| 455 | + real_fileobj=sys.__stderr__, | ||
| 456 | 456 | ) | |
| 457 | 457 | self.stdin = FakeStdin(self.coderunner, self, self.edit_keys) | |
| 458 | 458 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,8 +20,8 @@ def test_simple(self): | |||
| 20 | 20 | request_refresh=lambda: self.orig_stdout.flush() | |
| 21 | 21 | or self.orig_stderr.flush() | |
| 22 | 22 | ) | |
| 23 | - stdout = FakeOutput(c, lambda *args, **kwargs: None) | ||
| 24 | - stderr = FakeOutput(c, lambda *args, **kwargs: None) | ||
| 23 | + stdout = FakeOutput(c, lambda *args, **kwargs: None, None) | ||
| 24 | + stderr = FakeOutput(c, lambda *args, **kwargs: None, None) | ||
| 25 | 25 | sys.stdout = stdout | |
| 26 | 26 | sys.stdout = stderr | |
| 27 | 27 | c.load_code("1 + 1") | |
@@ -38,8 +38,8 @@ def test_exception(self): | |||
| 38 | 38 | def ctrlc(): | |
| 39 | 39 | raise KeyboardInterrupt() | |
| 40 | 40 | ||
| 41 | - stdout = FakeOutput(c, lambda x: ctrlc()) | ||
| 42 | - stderr = FakeOutput(c, lambda *args, **kwargs: None) | ||
| 41 | + stdout = FakeOutput(c, lambda x: ctrlc(), None) | ||
| 42 | + stderr = FakeOutput(c, lambda *args, **kwargs: None, None) | ||
| 43 | 43 | sys.stdout = stdout | |
| 44 | 44 | sys.stderr = stderr | |
| 45 | 45 | c.load_code("1 + 1") | |
@@ -51,5 +51,5 @@ def assert_unicode(self, s): | |||
| 51 | 51 | self.assertIsInstance(s, type(u"")) | |
| 52 | 52 | ||
| 53 | 53 | def test_bytes(self): | |
| 54 | - out = FakeOutput(mock.Mock(), self.assert_unicode) | ||
| 54 | + out = FakeOutput(mock.Mock(), self.assert_unicode, None) | ||
| 55 | 55 | out.write("native string type") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments