Guest User

Untitled

a guest
Feb 17th, 2012
314
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '''Exercise 1 Classes'''
  2. class PoetryProtocol(Protocol):
  3.     poem = ''
  4.  
  5.     def dataReceived(self, data):
  6.         self.poem += data
  7.  
  8.     def connectionLost(self, reason):
  9.         if self.delayedTimeout.active():
  10.             self.delayedTimeout.cancel()
  11.             self.poemReceived(self.poem)
  12.            
  13.     def poemReceived(self, poem):
  14.         self.factory.poem_finished(poem)
  15.    
  16.     def connectionMade(self):
  17.         self.delayedTimeout = reactor.callLater(7, self.timeout, Failure(TimeoutException))
  18.  
  19.     def timeout(self, failure):
  20.         self.factory.errback(failure)
  21.         self.transport.loseConnection()
  22.  
  23. class TimeoutException(Exception):
  24.     def __init__(self):
  25.         self.message = "timeout exception how exciting"
  26.     def __str__(self):
  27.         return repr(self.message)
RAW Paste Data