From 50a358f29b1f4cb082bac8a7c712dab53056c8e7 Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Thu, 10 Apr 2008 23:34:40 -0700 Subject: [PATCH] Fix a bug in the ThrottlingProtocol when writeSequence is called with a tuple. --- apt_p2p/policies.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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): -- 2.30.2