[Twisted-Python] NetstringReceiver

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Fri Mar 26 08:08:02 EDT 2010

On 10:25 am, albert.brandl at weiermayer.com wrote:
>On Thu, Mar 25, 2010 at 09:22:03AM +1100, Andrew Bennetts wrote:
>>No; I think once loseConnection has been called dataReceived won't be
>>called again, so there's no point checking for brokenPeer in
>There is a unittest that assumes that dataReceives still works after
>sending in garbage:
>   def test_illegal(self):
>        """
>        Assert that illegal strings cause the transport to be closed.
>        """
>        for s in self.illegalStrings:
>            r = self.getProtocol()
>            for c in s:
>                r.dataReceived(c)
>            self.assertTrue(r.transport.disconnecting)
>self.illegalStrings is defined as
>    illegalStrings = [
>        '9999999999999999999999', 'abc', '4:abcde',
>        '51:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab,',]
>In this implementation, the dataReceived method has to be functional
>even after the NetstringReceiver has detected that the received
>data are garbage.

I'm not sure about this.  Each iteration around this loop creates a new 
instance of NetstringReceiver; after the illegal string is delivered, 
the instance isn't used again.

So, are you sure this is testing what you think it's testing?


More information about the Twisted-Python mailing list