def testPartialParsing(self): p = FrameParser() frame = Frame(self.large_bdata, opcode=0x2, final=True, masking_key="ciao") self.assertEqual(p.execute(frame.msg[:1]), None) self.assertEqual(p.execute(frame.msg[1:5]), None) self.assertEqual(p.execute(frame.msg[5:50]), None) pframe = p.execute(frame.msg[50:]) self.assertTrue(pframe) self.assertEqual(pframe.payload_length, len(self.large_bdata)) self.assertEqual(pframe.body, self.large_bdata)
def testParser(self): p = FrameParser() self.assertEqual(p.execute(b""), None) frame = Frame("Hello", final=True) self.assertRaises(WebSocketProtocolError, p.execute, frame.msg) frame = Frame("Hello", masking_key="ciao", final=True) pframe = p.execute(frame.msg) self.assertTrue(pframe) self.assertEqual(pframe.body, "Hello") self.assertEqual(pframe.payload_length, 5) self.assertEqual(pframe.masking_key, b"ciao")
def testParserBinary(self): p = FrameParser() frame = Frame(self.bdata, opcode=0x2, final=True, masking_key="ciao") pframe = p.execute(frame.msg) self.assertTrue(pframe) self.assertEqual(pframe.payload_length, 256) self.assertEqual(pframe.body, self.bdata) frame = Frame(self.large_bdata, opcode=0x2, final=True, masking_key="ciao") pframe = p.execute(frame.msg) self.assertTrue(pframe) self.assertEqual(pframe.payload_length, len(self.large_bdata)) self.assertEqual(pframe.body, self.large_bdata)