[Twisted-Python] NetstringReceiver

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Mon Mar 29 11:04:33 EDT 2010

On 11:11 am, albert.brandl at weiermayer.com wrote:
>On Fri, Mar 26, 2010 at 12:08:02PM -0000, exarkun at twistedmatrix.com 
>>So, are you sure this is testing what you think it's testing?
>Yes. This test was already there, and it failed in unexpected ways, so 
>had to look at it quite closely. I'm not too happy about it, since it
>tests several things at once (illegal strings, bytewise delivery), but 
>decided to leave it there for now, just to make sure that I don't miss
>some test case with the new unit tests.
>As Andrew pointed out, this unittest assumes that dataReceived is still
>(somewhat) functional after the detection of an invalid netstring. This
>does not make much sense IMO, and it complicates the code. I'd prefer
>to raise an exception and adapt the unittest accordingly.

I see.  A good first step (separate from fixing any of the 
implementation of NetstringReceiver) might be to clean up the tests, 
then, so that each only exercises one case, and so that only the desired 
behavior is tested (for example, tests for the behavior you're talking 
about, of receiving invalid bytes after the connection has been closed, 
could be removed).
>But I still don't know which exception would be best. There is a
>ConnectionLost exception, which is raised in
>twisted.protocols.amp.BinaryBoxProtocol when the transport is None.
>Other options are ConnectionClosed and ConnectionDone (both are not
>raised directly anywhere), or a new one. Maybe ConnectionLost is the
>most appropriate one.

Feel free to introduce new exception types.  Unfortunately I don't 
remember what change you're actually proposing to make to 
NetstringReceiver anymore, so I won't try to suggest any names.


More information about the Twisted-Python mailing list