Beispiel #1
0
    def test_that_escape_decode_raw_message_with_broken_escaping_should_raise_exception(
            self):
        wrong_escape_sequence = ESCAPE_CHARACTER + b'\xff'

        assert wrong_escape_sequence not in ESCAPE_SEQUENCES.values()

        with self.assertRaises(BrokenEscapingInFrameMiddlemanProtocolError):
            escape_decode_raw_message(wrong_escape_sequence)
Beispiel #2
0
async def handle_frame_receive_async(reader: asyncio.StreamReader,
                                     public_key: bytes) -> AbstractFrame:
    raw_data = await reader.readuntil(FRAME_SEPARATOR)
    index = raw_data.index(FRAME_SEPARATOR)
    raw_data_without_separator = escape_decode_raw_message(raw_data[:index])
    deserialized_data = AbstractFrame.deserialize(raw_data_without_separator,
                                                  public_key)
    return deserialized_data
Beispiel #3
0
    def test_that_frame_separator_followed_by_related_escape_sequence_should_be_encoded_and_decoded_correctly(
            self):
        raw = FRAME_SEPARATOR + ESCAPE_SEQUENCES[FRAME_SEPARATOR]

        raw_escaped = escape_encode_raw_message(raw)
        raw_unescaped = escape_decode_raw_message(raw_escaped)

        self.assertEqual(raw, raw_unescaped)
Beispiel #4
0
    def test_that_escape_decode_raw_message_should_replace_occurrences_of_escape_sequences(
            self):
        raw = FRAME_SEPARATOR + b'123' + ESCAPE_CHARACTER

        raw_escaped = escape_encode_raw_message(raw)
        raw_unescaped = escape_decode_raw_message(raw_escaped)

        self.assertEqual(raw, raw_unescaped)
Beispiel #5
0
    def test_that_escape_character_followed_by_related_escape_sequence_should_be_encoded_and_decoded_correctly(
            self):
        raw = ESCAPE_CHARACTER + ESCAPE_SEQUENCES[ESCAPE_CHARACTER]

        raw_escaped = escape_encode_raw_message(raw)
        raw_unescaped = escape_decode_raw_message(raw_escaped)

        self.assertEqual(raw, raw_unescaped)