Interaction function, emulates a very dumb telnet client.
(self)
| 537 | return bool(selector.select(0)) |
| 538 | |
| 539 | def interact(self): |
| 540 | """Interaction function, emulates a very dumb telnet client.""" |
| 541 | if sys.platform == "win32": |
| 542 | self.mt_interact() |
| 543 | return |
| 544 | with _TelnetSelector() as selector: |
| 545 | selector.register(self, selectors.EVENT_READ) |
| 546 | selector.register(sys.stdin, selectors.EVENT_READ) |
| 547 | |
| 548 | while True: |
| 549 | for key, events in selector.select(): |
| 550 | if key.fileobj is self: |
| 551 | try: |
| 552 | text = self.read_eager() |
| 553 | except EOFError: |
| 554 | print('*** Connection closed by remote host ***') |
| 555 | return |
| 556 | if text: |
| 557 | sys.stdout.write(text.decode('ascii')) |
| 558 | sys.stdout.flush() |
| 559 | elif key.fileobj is sys.stdin: |
| 560 | line = sys.stdin.readline().encode('ascii') |
| 561 | if not line: |
| 562 | return |
| 563 | self.write(line) |
| 564 | |
| 565 | def mt_interact(self): |
| 566 | """Multithreaded version of interact().""" |