[Twisted-Python] Could this be an error in pcp.py?

Gabriel Rossetti mailing_lists at evotex.ch
Wed Apr 23 08:48:26 MDT 2008


Jean-Paul Calderone wrote:
> On Wed, 23 Apr 2008 15:31:08 +0200, Gabriel Rossetti 
> <mailing_lists at evotex.ch> wrote:
>> Hello,
>>
>> I was looking at pcp.py and I noticed this :
>>
>>    def resumeProducing(self):
>>        self.paused = False
>>        if self._buffer:
>>            data = ''.join(self._buffer)
>>            bytesSent = self._writeSomeData(data)
>>            if bytesSent < len(data):
>>                unsent = data[bytesSent:]
>>                assert not self.iAmStreaming, (
>>                    "Streaming producer did not write all its data.")
>>                self._buffer[:] = [unsent]
>>            else:
>>                self._buffer[:] = []
>>        else:
>>            bytesSent = 0
>> ...
>>
>>
>> in the ProducerConsumerProxy class, self._writeSomeData(data) returns 
>> the length of what was written, but in the test right afterwards 
>> bytesSent is compared to len(data), but they both have the same 
>> value, shouldn't it be "if bytesSent < len(self._buffer):" instead?
>
> `self._buffer´ is a list of strings (hence the join call to create 
> `data´)
> so comparing the number of bytes sent to its length wouldn't make sense.
>
> Jean-Paul
>
Ok, yes, true, but there is still the fact that bytesSent == len(data) 
and thus the test will never be true, or did I miss something? From my 
tests self.transport.write(data) doesn't modify the data, and so it 
still has the same size as it had before being sent.

Gabriel




More information about the Twisted-Python mailing list