[Twisted-Python] pending fixes
Just as reminder, this is my pending patch against SVN. .disconnecting can be added to all protocols or it can be renamed... (or we could use hasattr in the meantime) Index: Twisted/twisted/protocols/basic.py =================================================================== --- Twisted/twisted/protocols/basic.py (revision 13459) +++ Twisted/twisted/protocols/basic.py (working copy) @@ -166,9 +166,23 @@ """ return error.ConnectionLost('Line length exceeded') +class PauseProducer(object): + paused = False + def pauseProducing(self): + self.paused = True + self.transport.pauseProducing() -class LineReceiver(protocol.Protocol): + def resumeProducing(self): + self.paused = False + self.transport.resumeProducing() + self.dataReceived('') + + def stopProducing(self): + self.paused = True + self.transport.stopProducing() + +class LineReceiver(protocol.Protocol, PauseProducer): """A protocol that receives lines and/or raw data, depending on mode. In line mode, each line that's received becomes a callback to @@ -188,7 +202,6 @@ __buffer = '' delimiter = '\r\n' MAX_LENGTH = 16384 - paused = False def clearLineBuffer(self): """Clear buffered data.""" @@ -279,21 +292,8 @@ """ return self.transport.loseConnection() - def pauseProducing(self): - self.paused = True - self.transport.pauseProducing() - def resumeProducing(self): - self.paused = False - self.dataReceived('') - self.transport.resumeProducing() - - def stopProducing(self): - self.paused = True - self.transport.stopProducing() - - -class Int32StringReceiver(protocol.Protocol): +class Int32StringReceiver(protocol.Protocol, PauseProducer): """A receiver for int32-prefixed strings. An int32 string is a string prefixed by 4 bytes, the 32-bit length of @@ -314,7 +314,7 @@ """Convert int32 prefixed strings into calls to stringReceived. """ self.recvd = self.recvd + recd - while len(self.recvd) > 3: + while len(self.recvd) > 3 and not self.paused and not self.transport.disconnecting: length ,= struct.unpack("!i",self.recvd[:4]) if length > self.MAX_LENGTH: self.transport.loseConnection() @@ -331,7 +331,7 @@ self.transport.write(struct.pack("!i",len(data))+data) -class Int16StringReceiver(protocol.Protocol): +class Int16StringReceiver(protocol.Protocol, PauseProducer): """A receiver for int16-prefixed strings. An int16 string is a string prefixed by 2 bytes, the 16-bit length of @@ -351,7 +351,7 @@ """Convert int16 prefixed strings into calls to stringReceived. """ self.recvd = self.recvd + recd - while len(self.recvd) > 1: + while len(self.recvd) > 1 and not self.paused and not self.transport.disconnecting: length = (ord(self.recvd[0]) * 256) + ord(self.recvd[1]) if len(self.recvd) < length+2: break Index: Twisted/twisted/lore/latex.py =================================================================== --- Twisted/twisted/lore/latex.py (revision 13459) +++ Twisted/twisted/lore/latex.py (working copy) @@ -104,7 +104,7 @@ baseLevel = 0 try: - diaHack = not not os.popen('which dia').read() + diaHack = not not os.popen('which dia 2>/dev/null').read() except: # That's a no, then. diaHack = 0
On Sun, 2005-04-03 at 15:38 +0200, Andrea Arcangeli wrote:
Just as reminder, this is my pending patch against SVN. .disconnecting can be added to all protocols or it can be renamed... (or we could use hasattr in the meantime)
Please add it to the issue tracker, that way you don't have to repost to the list.
participants (2)
-
Andrea Arcangeli -
Itamar Shtull-Trauring