| 1 |
# Copyright (c) Twisted Matrix Laboratories. |
| 2 |
# See LICENSE for details. |
| 3 |
|
| 4 |
|
| 5 |
""" |
| 6 |
An example of reading a line at a time from standard input |
| 7 |
without blocking the reactor. |
| 8 |
""" |
| 9 |
|
| 10 |
from os import linesep |
| 11 |
|
| 12 |
from twisted.internet import stdio |
| 13 |
from twisted.protocols import basic |
| 14 |
|
| 15 |
|
| 16 |
class Echo(basic.LineReceiver): |
| 17 |
delimiter = linesep.encode("ascii") |
| 18 |
|
| 19 |
def connectionMade(self): |
| 20 |
self.transport.write(b">>> ") |
| 21 |
|
| 22 |
def lineReceived(self, line): |
| 23 |
self.sendLine(b"Echo: " + line) |
| 24 |
self.transport.write(b">>> ") |
| 25 |
|
| 26 |
|
| 27 |
def main(): |
| 28 |
stdio.StandardIO(Echo()) |
| 29 |
from twisted.internet import reactor |
| 30 |
|
| 31 |
reactor.run() |
| 32 |
|
| 33 |
|
| 34 |
if __name__ == "__main__": |
| 35 |
main() |