Esempio n. 1
0
 def testMaskData(self):
     masking_key = int2bytes(0x37, 0xFA, 0x21, 0x3D)
     f = Frame("Hello", masking_key=masking_key, final=True)
     self.assertTrue(f.final)
     msg = int2bytes(0x81, 0x85, 0x37, 0xFA, 0x21, 0x3D, 0x7F, 0x9F, 0x4D, 0x51, 0x58)
     self.assertTrue(f.masked)
     self.assertEqual(msg, f.msg)
Esempio n. 2
0
 def testUnmaskedDataFrame(self):
     f = Frame("Hello", final=True)
     self.assertEqual(f.opcode, 0x1)
     self.assertEqual(f.payload_length, 5)
     self.assertFalse(f.masked)
     self.assertEqual(len(f.msg), 7)
     self.assertEqual(int2bytes(0x81, 0x05, 0x48, 0x65, 0x6C, 0x6C, 0x6F), f.msg)
     f1 = Frame("Hel")
     f2 = Frame.continuation("lo", final=True)
     self.assertEqual(int2bytes(0x01, 0x03, 0x48, 0x65, 0x6C), f1.msg)
     self.assertEqual(int2bytes(0x80, 0x02, 0x6C, 0x6F), f2.msg)
Esempio n. 3
0
 def testControlFrames(self):
     f = Frame.close()
     self.assertEqual(f.opcode, 0x8)
     self.assertTrue(f.payload_length <= 125)
     f = Frame.ping("Hello")
     self.assertEqual(f.opcode, 0x9)
     self.assertEqual(int2bytes(0x89, 0x05, 0x48, 0x65, 0x6C, 0x6C, 0x6F), f.msg)
     self.assertTrue(f.payload_length <= 125)
     r = f.on_received()
     self.assertTrue(r)
     self.assertEqual(r.opcode, 0xA)
     f = Frame.pong()
     self.assertEqual(f.opcode, 0xA)
     self.assertTrue(f.payload_length <= 125)