Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PoetryProtocol(Protocol):
- poem = ''
- def __init__(self):
- self.timeout = None
- self.if_timedout = False
- def timedout(self):
- self.if_timedout = True
- self.transport.loseConnection()
- print 'Timed out!'
- def success(self):
- if self.timeout is None or self.if_timedout is True:
- return
- self.timeout.cancel()
- def dataReceived(self, data):
- self.poem += data
- def connectionMade(self):
- self.timeout = reactor.callLater(5, self.timedout)
- def connectionLost(self, reason):
- self.poemReceived(self.poem)
- def poemReceived(self, poem):
- self.factory.poem_finished(poem)
- self.success()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement