~landscape/zope3/newer-from-ztk

« back to all changes in this revision

Viewing changes to src/twisted/test/process_twisted.py

  • Committer: Thomas Hervé
  • Date: 2009-07-08 13:52:04 UTC
  • Revision ID: thomas@canonical.com-20090708135204-df5eesrthifpylf8
Remove twisted copy

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""A process that reads from stdin and out using Twisted."""
2
 
 
3
 
### Twisted Preamble
4
 
# This makes sure that users don't have to set up their environment
5
 
# specially in order to run these programs from bin/.
6
 
import sys, os, string
7
 
pos = string.find(os.path.abspath(sys.argv[0]), os.sep+'Twisted')
8
 
if pos != -1:
9
 
    sys.path.insert(0, os.path.abspath(sys.argv[0])[:pos+8])
10
 
sys.path.insert(0, os.curdir)
11
 
### end of preamble
12
 
 
13
 
 
14
 
from twisted.python import log
15
 
from zope.interface import implements
16
 
from twisted.internet import interfaces
17
 
 
18
 
log.startLogging(sys.stderr)
19
 
 
20
 
from twisted.internet import protocol, reactor, stdio
21
 
 
22
 
 
23
 
class Echo(protocol.Protocol):
24
 
    implements(interfaces.IHalfCloseableProtocol)
25
 
    
26
 
    def connectionMade(self):
27
 
        print "connection made"
28
 
    
29
 
    def dataReceived(self, data):
30
 
        self.transport.write(data)
31
 
 
32
 
    def readConnectionLost(self):
33
 
        print "readConnectionLost"
34
 
        self.transport.loseConnection()
35
 
    def writeConnectionLost(self):
36
 
        print "writeConnectionLost"
37
 
    
38
 
    def connectionLost(self, reason):
39
 
        print "connectionLost", reason
40
 
        reactor.stop()
41
 
 
42
 
stdio.StandardIO(Echo())
43
 
reactor.run()