~ubuntu-branches/ubuntu/trusty/twisted/trusty-proposed

« back to all changes in this revision

Viewing changes to doc/examples/stdin.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-01-08 00:19:41 UTC
  • mfrom: (1.3.1) (44.2.2 sid)
  • Revision ID: package-import@ubuntu.com-20140108001941-kxhzbyi4a40sc08r
Tags: 13.2.0-1ubuntu1
* Merge with Debian; remaining changes:
  - Keep the preliminary python3 support, but don't enable it.
  - Try to use plain pygtkcompat and fall back to gi.pygtkcompat, to
    avoid a DeprecationWarning, and a crash.
  - Use new io_add_watch api on new versions of pygobject.

Show diffs side-by-side

added added

removed removed

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