Ticket #2259: testcase.py

File testcase.py, 1002 bytes (added by jknight, 8 years ago)
Line 
1import os, sys, time
2
3from twisted.internet import defer, reactor, stdio, interfaces
4from twisted.protocols import basic
5from twisted.python import usage
6from zope.interface import implements
7
8class TestReader (basic.LineReceiver):
9    from os import linesep as delimiter
10    implements(interfaces.IHalfCloseableProtocol)
11
12    def __init__ (self):
13        pass
14
15    def lineReceived (self, line):
16        self.transport.write(line + "\n")
17
18    def stop (self):
19        print >>sys.stderr, "stop"
20        self.transport.loseConnection()
21
22    def readConnectionLost (self):
23        print >>sys.stderr, "readConnectionLost"
24        reactor.callLater(1, self.transport.write, "stopping\n")
25        reactor.callLater(2, self.stop)
26
27    def writeConnectionLost(self):
28        print >>sys.stderr, "writeConnectionLost"
29        pass
30
31    def connectionLost(self, reason):
32        print >>sys.stderr, "connectionLost"
33        reactor.callWhenRunning(reactor.stop)
34
35stdio.StandardIO(TestReader())
36reactor.run()
37