コード例 #1
0
    def test_loadb_message_tailnoise(self):
        """

        """
        packet = bytes([
            0x30,
            0x3a,
            0x2c,
            0x68,
            0x65,
            0x6c,
            0x6c,
            0x6f,
            0x20,
            0x77,
            0x6f,
            0x72,
            0x6c,
            0x64,
            0x21,
        ])
        decoder = loadb()
        msg = decoder.send(None)
        self.assertIs(None, msg)

        msg = decoder.send(packet)
        self.assertEqual("", msg)
コード例 #2
0
    def test_loadb_badmessage(self):
        packet = bytes([
            0x30,
            0x3a,
            0x68,
            0x65,
            0x6c,
            0x6c,
            0x6f,
            0x20,
            0x77,
            0x6f,
            0x72,
            0x6c,
            0x64,
            0x21,
            0x2c,
        ])
        decoder = loadb()
        msg = decoder.send(None)
        self.assertIs(None, msg)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            msg = decoder.send(packet)
            self.assertIs(None, msg)
            self.assertTrue(issubclass(w[-1].category, UserWarning))
            self.assertIn("Framing error", str(w[-1].message))

        msg = decoder.send(bytes([0x30, 0x3a, 0x2c]))
        self.assertEqual("", msg)
コード例 #3
0
ファイル: udp.py プロジェクト: tundish/turberfield-ipc
 def __init__(self, loop, token, types, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.loop = loop
     self.token = token
     self.types = types
     self.decoder = loadb(encoding="utf-8")
     self.decoder.send(None)
     self.transport = None
コード例 #4
0
 def __init__(self, loop, token, types, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.loop = loop
     self.token = token
     self.types = types
     self.decoder = loadb(encoding="utf-8")
     self.decoder.send(None)
     self.transport = None
コード例 #5
0
    def test_loadb_empty_message(self):
        """
        The empty string is encoded as "0:,".

        """
        packet = bytes([0x30, 0x3a, 0x2c])
        decoder = loadb()
        msg = decoder.send(None)
        self.assertIs(None, msg)

        msg = decoder.send(packet)
        self.assertEqual("", msg)
コード例 #6
0
    def test_loadb_message_headnoise(self):
        packet = bytes([
            0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
            0x30,
            0x3a,
            0x2c
        ])
        decoder = loadb()
        msg = decoder.send(None)
        self.assertIs(None, msg)

        msg = decoder.send(packet)
        self.assertEqual("", msg)
コード例 #7
0
    def test_loadb_full_message(self):
        """
        The string "hello world!" is encoded as <31 32 3a 68
        65 6c 6c 6f 20 77 6f 72 6c 64 21 2c>, i.e., "12:hello world!,".
        """
        packet = bytes([
            0x31, 0x32, 0x3a, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f,
            0x72, 0x6c, 0x64, 0x21, 0x2c
        ])
        decoder = loadb()
        msg = decoder.send(None)
        self.assertIs(None, msg)

        msg = decoder.send(packet)
        self.assertEqual("hello world!", msg)
コード例 #8
0
    def test_loadb_empty_message(self):
        """
        The empty string is encoded as "0:,".

        """
        packet = bytes([
            0x30,
            0x3a,
            0x2c
        ])
        decoder = loadb()
        msg = decoder.send(None)
        self.assertIs(None, msg)

        msg = decoder.send(packet)
        self.assertEqual("", msg)
コード例 #9
0
    def test_loadb_full_message(self):
        """
        The string "hello world!" is encoded as <31 32 3a 68
        65 6c 6c 6f 20 77 6f 72 6c 64 21 2c>, i.e., "12:hello world!,".
        """
        packet = bytes([
            0x31, 0x32,
            0x3a,
            0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
            0x2c
        ])
        decoder = loadb()
        msg = decoder.send(None)
        self.assertIs(None, msg)

        msg = decoder.send(packet)
        self.assertEqual("hello world!", msg)
コード例 #10
0
    def test_loadb_badmessage(self):
        packet = bytes([
            0x30,
            0x3a,
            0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
            0x2c,
        ])
        decoder = loadb()
        msg = decoder.send(None)
        self.assertIs(None, msg)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            msg = decoder.send(packet)
            self.assertIs(None, msg)
            self.assertTrue(
                issubclass(w[-1].category, UserWarning))
            self.assertIn("Framing error", str(w[-1].message))

        msg = decoder.send(bytes([0x30, 0x3a, 0x2c]))
        self.assertEqual("", msg)