Capture IO to/from a given OS-level file descriptor. snap() produces text.
| 441 | |
| 442 | |
| 443 | class FDCapture(FDCaptureBinary): |
| 444 | """Capture IO to/from a given OS-level file descriptor. |
| 445 | |
| 446 | snap() produces text. |
| 447 | """ |
| 448 | |
| 449 | # Ignore type because it doesn't match the type in the superclass (bytes). |
| 450 | EMPTY_BUFFER = "" # type: ignore |
| 451 | |
| 452 | def snap(self): |
| 453 | self._assert_state("snap", ("started", "suspended")) |
| 454 | self.tmpfile.seek(0) |
| 455 | res = self.tmpfile.read() |
| 456 | self.tmpfile.seek(0) |
| 457 | self.tmpfile.truncate() |
| 458 | return res |
| 459 | |
| 460 | def writeorg(self, data): |
| 461 | """Write to original file descriptor.""" |
| 462 | super().writeorg(data.encode("utf-8")) # XXX use encoding of original stream |
| 463 | |
| 464 | |
| 465 | # MultiCapture |