def test_afterFinished(self): """ L{_ChunkedTransferEncoding.dataReceived} raises L{RuntimeError} if it is called after it has seen the last chunk. """ p = http._ChunkedTransferEncoding(None, lambda bytes: None) p.dataReceived('0\r\n\r\n') self.assertRaises(RuntimeError, p.dataReceived, 'hello')
def test_extra(self): """ L{_ChunkedTransferEncoding.dataReceived} passes any bytes which come after the terminating zero-length chunk to the completion callback. """ finished = [] p = http._ChunkedTransferEncoding(None, finished.append) p.dataReceived('0\r\n\r\nhello') self.assertEqual(finished, ['hello'])
def test_extensions(self): """ L{_ChunkedTransferEncoding.dataReceived} disregards chunk-extension fields. """ L = [] p = http._ChunkedTransferEncoding(L.append, None) p.dataReceived('3; x-foo=bar\r\nabc\r\n') self.assertEqual(L, ['abc'])
def test_newlines(self): """ L{_ChunkedTransferEncoding.dataReceived} doesn't treat CR LF pairs embedded in chunk bodies specially. """ L = [] p = http._ChunkedTransferEncoding(L.append, None) p.dataReceived('2\r\n\r\n\r\n') self.assertEqual(L, ['\r\n'])
def test_finish(self): """ L{_ChunkedTransferEncoding.dataReceived} interprets a zero-length chunk as the end of the chunked data stream and calls the completion callback. """ finished = [] p = http._ChunkedTransferEncoding(None, finished.append) p.dataReceived('0\r\n\r\n') self.assertEqual(finished, [''])
def test_decoding(self): """ L{_ChunkedTransferEncoding.dataReceived} decodes chunked-encoded data and passes the result to the specified callback. """ L = [] p = http._ChunkedTransferEncoding(L.append, None) p.dataReceived('3\r\nabc\r\n5\r\n12345\r\n') p.dataReceived('a\r\n0123456789\r\n') self.assertEqual(L, ['abc', '12345', '0123456789'])
def test_short(self): """ L{_ChunkedTransferEncoding.dataReceived} decodes chunks broken up and delivered in multiple calls. """ L = [] finished = [] p = http._ChunkedTransferEncoding(L.append, finished.append) for s in '3\r\nabc\r\n5\r\n12345\r\n0\r\n\r\n': p.dataReceived(s) self.assertEqual(L, ['a', 'b', 'c', '1', '2', '3', '4', '5']) self.assertEqual(finished, [''])