From: Cameron Dale Date: Fri, 11 Apr 2008 06:34:40 +0000 (-0700) Subject: Fix a bug in the ThrottlingProtocol when writeSequence is called with a tuple. X-Git-Url: https://git.mxchange.org/?p=quix0rs-apt-p2p.git;a=commitdiff_plain;h=50a358f29b1f4cb082bac8a7c712dab53056c8e7 Fix a bug in the ThrottlingProtocol when writeSequence is called with a tuple. --- diff --git a/apt_p2p/policies.py b/apt_p2p/policies.py index e7bae81..9dc7ec8 100644 --- a/apt_p2p/policies.py +++ b/apt_p2p/policies.py @@ -146,15 +146,17 @@ class ThrottlingProtocol(ProtocolWrapper): self._throttleWrites() def writeSequence(self, seq): + i = 0 if not self.throttled: # Write each sequence separately - while seq and not self.factory.registerWritten(len(seq[0])): - ProtocolWrapper.write(self, seq.pop(0)) + while i < len(seq) and not self.factory.registerWritten(len(seq[i])): + ProtocolWrapper.write(self, seq[i]) + i += 1 # If there's some left, we must have been paused - if seq: - self._tempDataBuffer.extend(seq) - self._tempDataLength += reduce(operator.add, map(len, seq)) + if i < len(seq): + self._tempDataBuffer.extend(seq[i:]) + self._tempDataLength += reduce(operator.add, map(len, seq[i:])) self._throttleWrites() def dataReceived(self, data):