def test_clearLineBuffer(self):
"""
L{LineReceiver.clearLineBuffer} removes all buffered data and returns
it as a C{bytes} and can be called from beneath C{dataReceived}.
"""
class ClearingReceiver(basic.LineReceiver):
def lineReceived(self, line):
self.line = line
self.rest = self.clearLineBuffer()
protocol = ClearingReceiver()
protocol.dataReceived(b'foo\r\nbar\r\nbaz')
self.assertEqual(protocol.line, b'foo')
self.assertEqual(protocol.rest, b'bar\r\nbaz')
# Deliver another line to make sure the previously buffered data is
# really gone.
protocol.dataReceived(b'quux\r\n')
self.assertEqual(protocol.line, b'quux')
self.assertEqual(protocol.rest, b'')
评论列表
文章目录