[Twisted-Python] Could this be an error in pcp.py?
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? Gabriel
On Wed, 23 Apr 2008 15:31:08 +0200, Gabriel Rossetti <mailing_lists@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
Jean-Paul Calderone wrote:
On Wed, 23 Apr 2008 15:31:08 +0200, Gabriel Rossetti <mailing_lists@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
On Wed, 23 Apr 2008 16:48:26 +0200, Gabriel Rossetti <mailing_lists@evotex.ch> wrote:
Jean-Paul Calderone wrote: [snip]
`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.
If bytesSent == len(data), then the else case is taken and the buffer is empty. I'm not really sure what you're getting at. Jean-Paul
Jean-Paul Calderone wrote:
On Wed, 23 Apr 2008 16:48:26 +0200, Gabriel Rossetti <mailing_lists@evotex.ch> wrote:
Jean-Paul Calderone wrote: [snip]
`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.
If bytesSent == len(data), then the else case is taken and the buffer is empty. I'm not really sure what you're getting at.
Jean-Paul
Ok, I must be way off, because as I see it bytesSent < len(data) is never true. Gabriel
On Wed, 23 Apr 2008 17:30:17 +0200, Gabriel Rossetti <mailing_lists@evotex.ch> wrote:
[snip]
If bytesSent == len(data), then the else case is taken and the buffer is empty. I'm not really sure what you're getting at.
Jean-Paul
Ok, I must be way off, because as I see it bytesSent < len(data) is never true.
Ah. Yes, you're right. I'm not sure why this code is written this way. It's pretty old and I haven't used it much myself. I don't know if this means there is a bug or not. If you think there is one, the next step is to write a unit test. :) Jean-Paul
Jean-Paul Calderone wrote:
On Wed, 23 Apr 2008 17:30:17 +0200, Gabriel Rossetti <mailing_lists@evotex.ch> wrote:
[snip]
If bytesSent == len(data), then the else case is taken and the buffer is empty. I'm not really sure what you're getting at.
Jean-Paul
Ok, I must be way off, because as I see it bytesSent < len(data) is never true.
Ah. Yes, you're right. I'm not sure why this code is written this way. It's pretty old and I haven't used it much myself. I don't know if this means there is a bug or not. If you think there is one, the next step is to write a unit test. :)
Jean-Paul Ok, I'll do that as soon as possible :-)
Gabriel
participants (2)
-
Gabriel Rossetti
-
Jean-Paul Calderone