daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Jun 1st, 2013 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class PoetryProtocol(Protocol):
  2.  
  3.     poem = ''
  4.  
  5.     def __init__(self):
  6.         self.timeout = None
  7.         self.if_timedout = False
  8.  
  9.     def timedout(self):
  10.         self.if_timedout = True
  11.         self.transport.loseConnection()
  12.         print 'Timed out!'
  13.  
  14.     def success(self):
  15.         if self.timeout is None or self.if_timedout is True:
  16.             return
  17.         self.timeout.cancel()
  18.  
  19.     def dataReceived(self, data):
  20.         self.poem += data
  21.  
  22.     def connectionMade(self):
  23.         self.timeout = reactor.callLater(5, self.timedout)
  24.  
  25.     def connectionLost(self, reason):
  26.         self.poemReceived(self.poem)
  27.  
  28.     def poemReceived(self, poem):
  29.         self.factory.poem_finished(poem)
  30.         self.success()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top