예제 #1
0
    def test_bytestr_encode(self):
        self.assertEqual(bytestr_encode(b'Hello, World'), b'\x0cHello, World')
        self.assertEqual(bytestr_encode('Hi!'), b'\x03Hi!')

        long_bstr = b'.' * 200
        # encoded 200 = 01111111 (127) + 01001001 (73) = 0x7f49
        self.assertEqual(bytestr_encode(long_bstr), b'\x7f\x49' + long_bstr)
예제 #2
0
    def test_bytestr_encode(self):
        self.assertEqual(bytestr_encode(b'Hello, World'), b'\x0cHello, World')
        self.assertEqual(bytestr_encode('Hi!'), b'\x03Hi!')

        long_bstr = b'.' * 200
        # encoded 200 = 01111111 (127) + 01001001 (73) = 0x7f49
        self.assertEqual(bytestr_encode(long_bstr), b'\x7f\x49' + long_bstr)
예제 #3
0
    def test_bytestr_uncode_encode(self):
        hello = 'Привет'
        self.assertEqual(bytestr_encode(hello, encoding='utf-8'), 
            int_to_byte(len(hello.encode('utf-8'))) + hello.encode('utf-8'))

        long_hello = hello * 100
        self.assertEqual(bytestr_encode(long_hello, encoding='utf-8'), 
            uint_encode(len(long_hello.encode('utf-8')), n=7) + long_hello.encode('utf-8'))
예제 #4
0
    def test_bytestr_uncode_encode(self):
        hello = 'Привет'
        self.assertEqual(
            bytestr_encode(hello, encoding='utf-8'),
            int_to_byte(len(hello.encode('utf-8'))) + hello.encode('utf-8'))

        long_hello = hello * 100
        self.assertEqual(
            bytestr_encode(long_hello, encoding='utf-8'),
            uint_encode(len(long_hello.encode('utf-8')), n=7) +
            long_hello.encode('utf-8'))