Guest User

Untitled

a guest
Feb 17th, 2012
310
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×