How to use the ws4py.framing.Frame function in ws4py

To help you get started, we’ve selected a few ws4py examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Lawouach / WebSocket-for-Python / test / test_stream.py View on Github external
def test_invalid_encoded_bytes_on_continuation(self):
        s = Stream()

        f = Frame(opcode=OPCODE_TEXT, body=b'hello',
                  fin=0, masking_key=os.urandom(4)).build()
        s.parser.send(f)
        next(s.parser)

        f = Frame(opcode=OPCODE_CONTINUATION, body=b'h\xc3llo',
                  fin=1, masking_key=os.urandom(4)).build()
        s.parser.send(f)
        next(s.parser)

        self.assertNotEqual(s.errors, [])
        self.assertIsInstance(s.errors[0], CloseControlMessage)
        self.assertEqual(s.errors[0].code, 1007)
github Lawouach / WebSocket-for-Python / test / test_frame.py View on Github external
def test_incremental_parsing_small_7_bit_length(self):
        bytes = Frame(opcode=OPCODE_TEXT, body=b'hello', fin=1).build()

        f = Frame()
        map_on_bytes(f.parser.send, bytes)
        self.assertTrue(f.masking_key is None)
        self.assertEqual(f.payload_length, 5)
github Lawouach / WebSocket-for-Python / test / test_stream.py View on Github external
msg = os.urandom(16)
        key = os.urandom(4)
        f = Frame(opcode=OPCODE_BINARY, body=msg, fin=0, masking_key=key).build()
        s = Stream()
        self.assertEqual(s.has_message, False)
        s.parser.send(f)
        self.assertEqual(s.has_message, False)

        for i in range(3):
            f = Frame(opcode=OPCODE_CONTINUATION, body=msg, fin=0, masking_key=key).build()
            s.parser.send(f)
            self.assertEqual(s.has_message, False)
            self.assertEqual(s.message.completed, False)
            self.assertEqual(s.message.opcode, OPCODE_BINARY)

        f = Frame(opcode=OPCODE_CONTINUATION, body=msg, fin=1, masking_key=key).build()
        s.parser.send(f)
        self.assertEqual(s.has_message, True)
        self.assertEqual(s.message.completed, True)
        self.assertEqual(s.message.opcode, OPCODE_BINARY)
github Lawouach / WebSocket-for-Python / test / test_frame.py View on Github external
def test_non_zero_nor_one_fin(self):
        f = Frame(opcode=OPCODE_TEXT,
                  body=b'', fin=2)
        self.assertRaises(ValueError, f.build)
github Lawouach / WebSocket-for-Python / test / test_stream.py View on Github external
def test_incremental_text_message_received(self):
        msg = b'hello there'
        f = Frame(opcode=OPCODE_TEXT, body=msg, fin=1, masking_key=os.urandom(4)).build()
        s = Stream()
        self.assertEqual(s.has_message, False)
        bytes = f
        for index, byte in enumerate(bytes):
            s.parser.send(bytes[index:index+1])
        self.assertEqual(s.has_message, True)
github Lawouach / WebSocket-for-Python / test / test_stream.py View on Github external
def test_text_message_with_continuation_received(self):
        msg = b'hello there'
        f = Frame(opcode=OPCODE_TEXT, body=msg, fin=0, masking_key=os.urandom(4)).build()
        s = Stream()
        self.assertEqual(s.has_message, False)
        s.parser.send(f)
        self.assertEqual(s.message.completed, False)

        for i in range(3):
            f = Frame(opcode=OPCODE_CONTINUATION, body=msg, fin=0, masking_key=os.urandom(4)).build()
            s.parser.send(f)
            self.assertEqual(s.has_message, False)
            self.assertEqual(s.message.completed, False)
            self.assertEqual(s.message.opcode, OPCODE_TEXT)

        f = Frame(opcode=OPCODE_CONTINUATION, body=msg, fin=1, masking_key=os.urandom(4)).build()
        s.parser.send(f)
        self.assertEqual(s.has_message, True)
        self.assertEqual(s.message.completed, True)
github Lawouach / WebSocket-for-Python / test / test_frame.py View on Github external
def test_63_bit_length(self):
        f = Frame(opcode=OPCODE_TEXT,
                  body=b'*' * 65536, fin=1)
        self.assertEqual(len(f.build()), 65546)

        mask = os.urandom(4)
        f = Frame(opcode=OPCODE_TEXT,
                  body=b'*' * 65536, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 65550)
github Lawouach / WebSocket-for-Python / test / test_stream.py View on Github external
def test_using_masking_key_when_unexpected(self):
        f = Frame(opcode=OPCODE_TEXT, body=b'hello', fin=1, masking_key=os.urandom(4)).build()
        s = Stream(expect_masking=False)
        s.parser.send(f)
        next(s.parser)
        self.assertNotEqual(s.errors, [])
        self.assertIsInstance(s.errors[0], CloseControlMessage)
        self.assertEqual(s.errors[0].code, 1002)
github Lawouach / WebSocket-for-Python / test / test_client.py View on Github external
def _exchange2(self, *args, **kwargs):
        yield Frame(opcode=OPCODE_CLOSE, body=b'',
                    fin=1).build()
github Lawouach / WebSocket-for-Python / test / test_frame.py View on Github external
def test_frame_header_parsing(self):
        bytes = Frame(opcode=OPCODE_TEXT, body=b'hello', fin=1).build()

        f = Frame()
        self.assertEqual(f.parser.send(bytes[0:1]), 1)
        self.assertEqual(f.fin, 1)
        self.assertEqual(f.rsv1, 0)
        self.assertEqual(f.rsv2, 0)
        self.assertEqual(f.rsv3, 0)
        self.assertEqual(f.parser.send(bytes[1:2]), 5)
        self.assertTrue(f.masking_key is None)
        self.assertEqual(f.payload_length, 5)
        f.parser.close()