示例#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)
示例#2
0
文件: frame.py 项目: japaks/pulsar
 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)
示例#3
0
 def testUnmaskedDataFrame(self):
     parser = FrameParser(kind=2)
     f = parser.encode('Hello')
     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 = parser.encode('Hel', final=False)
     f2 = parser.continuation('lo', final=True)
     self.assertEqual(int2bytes(0x01,0x03,0x48,0x65,0x6c), f1.msg)
     self.assertEqual(int2bytes(0x80,0x02,0x6c,0x6f), f2.msg)
示例#4
0
文件: frame.py 项目: japaks/pulsar
 def testUnmaskedDataFrame(self):
     parser = FrameParser(kind=2)
     f = parser.encode('Hello')
     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 = parser.encode('Hel', final=False)
     f2 = parser.continuation('lo', final=True)
     self.assertEqual(int2bytes(0x01, 0x03, 0x48, 0x65, 0x6c), f1.msg)
     self.assertEqual(int2bytes(0x80, 0x02, 0x6c, 0x6f), f2.msg)
示例#5
0
 def testControlFrames(self):
     parser = FrameParser()
     f = parser.close()
     self.assertEqual(f.opcode, 0x8)
     self.assertTrue(f.payload_length <= 125)
     f = parser.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 = parser.replay_to(f)
     self.assertTrue(r)
     self.assertEqual(r.opcode, 0xA)
     f = parser.pong()
     self.assertEqual(f.opcode, 0xA)
     self.assertTrue(f.payload_length <= 125)
示例#6
0
文件: frame.py 项目: japaks/pulsar
 def testControlFrames(self):
     parser = FrameParser()
     f = parser.close()
     self.assertEqual(f.opcode, 0x8)
     self.assertTrue(f.payload_length <= 125)
     f = parser.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 = parser.replay_to(f)
     self.assertTrue(r)
     self.assertEqual(r.opcode, 0xA)
     f = parser.pong()
     self.assertEqual(f.opcode, 0xA)
     self.assertTrue(f.payload_length <= 125)