[Twisted-Python] NetstringReceiver
Andrew Bennetts
andrew at bemusement.org
Sun Mar 28 03:24:20 MDT 2010
exarkun at twistedmatrix.com wrote:
> On 10:25 am, albert.brandl at weiermayer.com wrote:
[...]
> >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.
That's true — but each illegal string is delivered one byte at a time. So the
'abc' string will trigger a NetstringParseError on the first dataReceived('a'),
but then the test expects the subsequent dataReceived('b') and dataReceived('c')
to execute without raising.
-Andrew.
More information about the Twisted-Python
mailing list