Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''Exercise 1 Classes'''
- class PoetryProtocol(Protocol):
- poem = ''
- def dataReceived(self, data):
- self.poem += data
- def connectionLost(self, reason):
- if self.delayedTimeout.active():
- self.delayedTimeout.cancel()
- self.poemReceived(self.poem)
- def poemReceived(self, poem):
- self.factory.poem_finished(poem)
- def connectionMade(self):
- self.delayedTimeout = reactor.callLater(7, self.timeout, Failure(TimeoutException))
- def timeout(self, failure):
- self.factory.errback(failure)
- self.transport.loseConnection()
- class TimeoutException(Exception):
- def __init__(self):
- self.message = "timeout exception how exciting"
- def __str__(self):
- return repr(self.message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement