Ejemplo n.º 1
0
 def test_split_16to8_big(self):
     r = Repacker(Endian.BIG, 16, 8)
     self.assertEqual(r.repack_unit, 16)
     self.assertEqual(r.repack_size(3), 2)
     self.assertEqual(r.repackable_size(3), 6)
     a = BinData(16, [0x1234, 0x5678, 0x9abc])
     b = r.repack(a, 1, 3)
     self.assertEqual(b, BinData.from_spaced_hex(8, '56 78 9a'))
Ejemplo n.º 2
0
 def test_simple_copy(self):
     r = Repacker(endian=Endian.LITTLE, from_width=8, to_width=8)
     self.assertEqual(r.repack_unit, 8)
     self.assertEqual(r.repack_size(num_elements=2), 2)
     self.assertEqual(r.repackable_size(from_size=2), 2)
     a = BinData(8, [1, 2, 3, 4])
     b = r.repack(a, start=1, num_elements=2)
     self.assertEqual(b, BinData(8, [2, 3]))
     self.assertEqual(r.repack(a), a)
Ejemplo n.º 3
0
 def test_padded_8to23_mixed_big(self):
     r = Repacker(Endian.BIG, 8, 23, low_pad=8, high_pad=1)
     self.assertEqual(r.repack_unit, 32)
     self.assertEqual(r.repack_size(2), 8)
     self.assertEqual(r.repackable_size(7), 1)
     self.assertEqual(r.repackable_size(8), 2)
     a = BinData.from_spaced_hex(8, '11 22 33 44 55 66 77 88 99 aa')
     b = r.repack(a, 1, 2)
     self.assertEqual(b, BinData.from_spaced_hex(23, '223344 667788'))
Ejemplo n.º 4
0
 def test_padded_8to23_right_little(self):
     r = Repacker(Endian.LITTLE, 8, 23, low_pad=9)
     self.assertEqual(r.repack_unit, 32)
     self.assertEqual(r.repack_size(2), 8)
     self.assertEqual(r.repackable_size(7), 1)
     self.assertEqual(r.repackable_size(8), 2)
     a = BinData.from_spaced_hex(8, '11 22 33 44 55 66 77 88 99 aa')
     b = r.repack(a, 1, 2)
     self.assertEqual(b, BinData.from_spaced_hex(23, '2aa219 4cc43b'))
Ejemplo n.º 5
0
 def test_split_60to20_big(self):
     r = Repacker(Endian.BIG, 60, 20)
     self.assertEqual(r.repack_unit, 60)
     self.assertEqual(r.repack_size(1), 1)
     self.assertEqual(r.repack_size(2), 1)
     self.assertEqual(r.repack_size(3), 1)
     self.assertEqual(r.repack_size(4), 2)
     self.assertEqual(r.repackable_size(1), 3)
     a = BinData(60, [0xfedcba987654321])
     b = r.repack(a)
     self.assertEqual(b, BinData.from_spaced_hex(20, 'fedcb a9876 54321'))
Ejemplo n.º 6
0
 def test_null(self):
     a = BinData(8)
     self.assertEqual(a.width, 8)
     self.assertEqual(a.raw_data, b'')
     self.assertEqual(a.octets_per_element(), 1)
     self.assertEqual(a.octets(), 0)
     self.assertEqual(len(a), 0)
     self.assertEqual(list(a), [])
     self.assertEqual(a, a[:])
     self.assertEqual(str(a), '')
     self.assertEqual(repr(a),
                      'BinData.from_spaced_hex(8, \'\')')
Ejemplo n.º 7
0
 def test_init_bytes(self):
     a = BinData(8, bytearray(b'12'))
     self.assertEqual(a.width, 8)
     self.assertEqual(a.raw_data, b'12')
     self.assertEqual(a.octets_per_element(), 1)
     self.assertEqual(a.octets(), 2)
     self.assertEqual(len(a), 2)
     self.assertEqual(list(a), [0x31, 0x32])
     self.assertEqual(a, a[:])
     self.assertEqual(str(a), '31 32')
     self.assertEqual(repr(a),
                      'BinData.from_spaced_hex(8, \'31 32\')')
Ejemplo n.º 8
0
 def test_split_8to1_little(self):
     r = Repacker(Endian.LITTLE, 8, 1)
     self.assertEqual(r.repack_unit, 8)
     self.assertEqual(r.repack_size(12), 2)
     self.assertEqual(r.repack_size(8), 1)
     self.assertEqual(r.repack_size(9), 2)
     self.assertEqual(r.repack_size(17), 3)
     self.assertEqual(r.repackable_size(1), 8)
     a = BinData.from_spaced_hex(8, '12 34 56')
     b = r.repack(a, 1, 12)
     c = BinData.from_spaced_hex(1, ' '.join(format(0x634, '012b')[::-1]))
     self.assertEqual(b, c)
Ejemplo n.º 9
0
 def test_add(self):
     a = BinData.from_spaced_hex(19, '11111 22222 33333')
     b = BinData.from_spaced_hex(19, '44444 55555')
     c = BinData.from_spaced_hex(20, '66666 77777')
     d = BinData.from_spaced_hex(19, '11111 22222 33333 44444 55555')
     self.assertEqual(a + b, d)
     with self.assertRaises(ValueError):
         a + c
     with self.assertRaises(TypeError):
         a + 'zlew'
     with self.assertRaises(TypeError):
         'zlew' + a
Ejemplo n.º 10
0
 def test_init_num(self):
     a = BinData(12, 12)
     self.assertEqual(a.width, 12)
     self.assertEqual(a.raw_data, bytes(bytearray(24)))
     self.assertEqual(a.octets_per_element(), 2)
     self.assertEqual(a.octets(), 24)
     self.assertEqual(len(a), 12)
     self.assertEqual(list(a), [0] * 12)
     self.assertEqual(a, a[:])
     s = ' '.join('000' for _ in range(12))
     self.assertEqual(str(a), s)
     self.assertEqual(repr(a),
                      'BinData.from_spaced_hex(12, \'{}\')'.format(s))
Ejemplo n.º 11
0
 def test_simple(self):
     a = BinData(8, [0x12])
     self.assertEqual(a.width, 8)
     self.assertEqual(a.raw_data, b'\x12')
     self.assertEqual(a.octets_per_element(), 1)
     self.assertEqual(a.octets(), 1)
     self.assertEqual(len(a), 1)
     self.assertEqual(a[0], 0x12)
     self.assertEqual(a[-1], 0x12)
     self.assertEqual(list(a), [0x12])
     self.assertEqual(a, a[:])
     self.assertEqual(str(a), '12')
     self.assertEqual(repr(a),
                      'BinData.from_spaced_hex(8, \'12\')')
Ejemplo n.º 12
0
 def test_gather_8to16_big(self):
     r = Repacker(endian=Endian.BIG, from_width=8, to_width=16)
     self.assertEqual(r.repack_unit, 16)
     self.assertEqual(r.repack_size(2), 4)
     self.assertEqual(r.repackable_size(2), 1)
     self.assertEqual(r.repackable_size(3), 1)
     self.assertEqual(r.repackable_size(4), 2)
     a = BinData(8, [1, 2, 3, 4, 5, 6])
     b = r.repack(a, start=1, num_elements=2)
     self.assertEqual(b, BinData.from_spaced_hex(16, '0203 0405'))
     c = r.repack(a, start=1)
     self.assertEqual(b, c)
     d = r.repack(a)
     self.assertEqual(d, BinData.from_spaced_hex(16, '0102 0304 0506'))
Ejemplo n.º 13
0
 def test_eq(self):
     a = BinData(8, [0x00])
     b = BinData(8, [0x00])
     c = BinData(8, [0x01])
     d = BinData(7, [0x00])
     e = BinData(8, [])
     self.assertEqual(a, b)
     self.assertEqual(hash(a), hash(b))
     self.assertNotEqual(a, c)
     self.assertNotEqual(a, d)
     self.assertNotEqual(a, e)
     self.assertNotEqual(a, 3.0)
     self.assertNotEqual(a, [0])
     self.assertNotEqual(a, b'\x00')
     self.assertNotEqual(a, 'zlew')
Ejemplo n.º 14
0
 def test_fib_7(self):
     a = BinData(7, [1, 2, 3, 5, 8])
     self.assertEqual(a.width, 7)
     self.assertEqual(a.raw_data, b'\x01\x02\x03\x05\x08')
     self.assertEqual(a.octets_per_element(), 1)
     self.assertEqual(a.octets(), 5)
     self.assertEqual(len(a), 5)
     self.assertEqual(a[0], 1)
     self.assertEqual(a[4], 8)
     self.assertEqual(a[-1], 8)
     self.assertEqual(list(a), [1, 2, 3, 5, 8])
     self.assertEqual(a, a[:])
     self.assertEqual(str(a), '01 02 03 05 08')
     self.assertEqual(repr(a),
                      'BinData.from_spaced_hex(7, \'01 02 03 05 08\')')
Ejemplo n.º 15
0
 def test_19(self):
     a = BinData(19, [0x12345, 0x6789a])
     self.assertEqual(a.width, 19)
     self.assertEqual(a.raw_data, b'\x45\x23\x01\x9a\x78\x06')
     self.assertEqual(a.octets_per_element(), 3)
     self.assertEqual(a.octets(), 6)
     self.assertEqual(len(a), 2)
     self.assertEqual(a[0], 0x12345)
     self.assertEqual(a[1], 0x6789a)
     self.assertEqual(a[-1], 0x6789a)
     self.assertEqual(list(a), [0x12345, 0x6789a])
     self.assertEqual(a, a[:])
     self.assertEqual(str(a), '12345 6789a')
     self.assertEqual(repr(a),
                      'BinData.from_spaced_hex(19, \'12345 6789a\')')
Ejemplo n.º 16
0
 def test_fib_9(self):
     a = BinData(9, [1, 2, 3, 5, 8])
     self.assertEqual(a.width, 9)
     self.assertEqual(a.raw_data,
                      b'\x01\x00\x02\x00\x03\x00\x05\x00\x08\x00')
     self.assertEqual(a.octets_per_element(), 2)
     self.assertEqual(a.octets(), 10)
     self.assertEqual(len(a), 5)
     self.assertEqual(a[0], 1)
     self.assertEqual(a[4], 8)
     self.assertEqual(a[-1], 8)
     self.assertEqual(list(a), [1, 2, 3, 5, 8])
     self.assertEqual(a, a[:])
     self.assertEqual(str(a), '001 002 003 005 008')
     self.assertEqual(repr(a),
                      'BinData.from_spaced_hex(9, \'001 002 003 005 008\')')
Ejemplo n.º 17
0
 def test_mash_8to12_little(self):
     r = Repacker(Endian.LITTLE, 8, 12)
     self.assertEqual(r.repack_unit, 24)
     self.assertEqual(r.repack_size(1), 2)
     self.assertEqual(r.repack_size(2), 3)
     self.assertEqual(r.repackable_size(1), 0)
     self.assertEqual(r.repackable_size(2), 1)
     self.assertEqual(r.repackable_size(3), 2)
     self.assertEqual(r.repackable_size(4), 2)
     a = BinData.from_spaced_hex(8, '12 34 56 78 9a')
     b = r.repack(a, 1, 2)
     self.assertEqual(b, BinData.from_spaced_hex(12, '634 785'))
     c = r.repack(a, 1)
     self.assertEqual(b, c)
     d = r.repack(a)
     self.assertEqual(d, BinData.from_spaced_hex(12, '412 563 a78'))
Ejemplo n.º 18
0
 def test_mash_8to12_big(self):
     r = Repacker(Endian.BIG, 8, 12)
     self.assertEqual(r.repack_unit, 24)
     self.assertEqual(r.repack_size(1), 2)
     self.assertEqual(r.repack_size(2), 3)
     self.assertEqual(r.repackable_size(1), 0)
     self.assertEqual(r.repackable_size(2), 1)
     self.assertEqual(r.repackable_size(3), 2)
     self.assertEqual(r.repackable_size(4), 2)
     a = BinData.from_spaced_hex(8, '12 34 56 78 9a')
     b = r.repack(a, 1, 2)
     self.assertEqual(b, BinData.from_spaced_hex(12, '345 678'))
     c = r.repack(a, 1)
     self.assertEqual(b, c)
     d = r.repack(a)
     self.assertEqual(d, BinData.from_spaced_hex(12, '123 456 789'))
Ejemplo n.º 19
0
 def test_setitem(self):
     a = BinData(19, [0x12345, 0x6789a, 0x3cdef])
     b = a[:]
     a[0] = 0x54321
     a[-1] = 0x7edcb
     self.assertEqual(a[-3], 0x54321)
     self.assertEqual(a[-2], 0x6789a)
     self.assertEqual(a[-1], 0x7edcb)
     self.assertEqual(a[0], 0x54321)
     self.assertEqual(a[1], 0x6789a)
     self.assertEqual(a[2], 0x7edcb)
     self.assertEqual(b[-3], 0x12345)
     self.assertEqual(b[-2], 0x6789a)
     self.assertEqual(b[-1], 0x3cdef)
     self.assertEqual(b[0], 0x12345)
     self.assertEqual(b[1], 0x6789a)
     self.assertEqual(b[2], 0x3cdef)
     with self.assertRaises(TypeError):
         a['zlew'] = 0x12345
     with self.assertRaises(TypeError):
         a[2.0] = 0x12345
     with self.assertRaises(IndexError):
         a[-4] = 0x12345
     with self.assertRaises(IndexError):
         a[3] = 0x12345
     with self.assertRaises(TypeError):
         a[0] = 'zlew'
     with self.assertRaises(TypeError):
         a[0] = 3.0
     with self.assertRaises(ValueError):
         a[2] = 0xbcdef
Ejemplo n.º 20
0
 def load_obj(cls, code, data):
     if code == EXT_NODE_ID:
         return nodeid.NodeID(data)
     elif code == EXT_BINDATA:
         width = int_from_bytes(data[:4], 'little')
         return BinData.from_raw_data(width, data[4:])
     elif code == EXT_BIGINT:
         return bigint_decode(data)
     return msgpack.ExtType(code, data)
Ejemplo n.º 21
0
 def test_init_str(self):
     a = BinData.from_spaced_hex(12, '12')
     self.assertEqual(a.width, 12)
     self.assertEqual(a.raw_data, b'\x12\x00')
     self.assertEqual(a.octets_per_element(), 2)
     self.assertEqual(a.octets(), 2)
     self.assertEqual(len(a), 1)
     self.assertEqual(list(a), [0x12])
     self.assertEqual(a, a[:])
     self.assertEqual(str(a), '012')
     self.assertEqual(repr(a),
                      'BinData.from_spaced_hex(12, \'012\')')
Ejemplo n.º 22
0
    def test_dump(self):
        a = Piwo(a=True)
        da = a.dump()
        self.assertEqual(da, {'a': True})
        for x in da:
            self.assertIsInstance(x, six.text_type)

        b = Zlew(b=[{'a': BinData(8, []), 'b': BinData(12, [0x123])}, {}])
        db = b.dump()
        self.assertEqual(db, {
            'b': [
                {
                    'a': BinData(8, []),
                    'b': BinData(12, [0x123]),
                },
                {},
            ]
        })
        for x in db:
            self.assertIsInstance(x, six.text_type)

        c = TurboZlew(b=[{}], c={b'abc', b'def'}, d=Piwo(a=False), e=7)
        dc = c.dump()
        self.assertEqual(dc, {
            'b': [{}],
            'c': dc['c'],
            'd': {'a': False},
            'e': 7,
        })
        self.assertIsInstance(dc['c'], list)
        self.assertEqual(set(dc['c']), {b'abc', b'def'})

        d = TurboZlew(d=a)
        dd = d.dump()
        self.assertEqual(dd, {
            'b': [],
            'c': [],
            'd': {'a': True},
            'e': 3,
        })
Ejemplo n.º 23
0
 def test_init_crap(self):
     with self.assertRaises(TypeError):
         BinData(8.0)
     with self.assertRaises(ValueError):
         BinData(0)
     with self.assertRaises(ValueError):
         BinData(-8)
     with self.assertRaises(TypeError):
         BinData(8, [3.0])
     with self.assertRaises(TypeError):
         BinData(8, 3.0)
     with self.assertRaises(TypeError):
         BinData(8, u'meh')
     BinData(7, [0x7f])
     with self.assertRaises(ValueError):
         BinData(7, [0x80])
     with self.assertRaises(ValueError):
         BinData(8, [-1])
Ejemplo n.º 24
0
 def test_bindata(self):
     a = fields.BinData()
     data = BinData(8, [0x12, 0x34])
     a.validate(data)
     with self.assertRaises(SchemaError):
         a.validate(b'abcd')
     with self.assertRaises(SchemaError):
         a.validate(1234)
     self.assertEqual(a.dump(data), data)
     self.assertEqual(a.load(data), data)
     with self.assertRaises(SchemaError):
         a.load(b'abcd')
     with self.assertRaises(SchemaError):
         a.load(1234)
Ejemplo n.º 25
0
 def test_getitem(self):
     a = BinData(19, [0x12345, 0x6789a, 0x3cdef])
     self.assertEqual(a[-3], 0x12345)
     self.assertEqual(a[-2], 0x6789a)
     self.assertEqual(a[-1], 0x3cdef)
     self.assertEqual(a[0], 0x12345)
     self.assertEqual(a[1], 0x6789a)
     self.assertEqual(a[2], 0x3cdef)
     with self.assertRaises(TypeError):
         a['zlew']
     with self.assertRaises(TypeError):
         a[2.0]
     with self.assertRaises(IndexError):
         a[-4]
     with self.assertRaises(IndexError):
         a[3]
Ejemplo n.º 26
0
     if len(p) not in {2, 3, 5}:
         raise ValueError('File command needs 1, 2, or 4 arguments')
     if len(p) > 2:
         base = int(p[2], 16)
     else:
         base = 0
     with open(p[1], "rb") as df:
         if len(p) > 3:
             df.seek(int(p[3], 16))
             sz = int(p[4], 16)
             data = df.read(sz)
             if len(data) != sz:
                 raise ValueError('not enough data in the file')
         else:
             data = df.read()
         data = BinData(8, data)
     segment = MachineSegment(isa, data, base, None)
 else:
     if cmd == 'func':
         if len(p) not in (2, 3):
             raise ValueError('fun command needs 1 or 2 arguments')
         fun_start = int(p[1], 16)
         if len(p) >= 3:
             fun_name = p[2]
         else:
             fun_name = None
         fun = forest.mark_function(forest.mark_block(MachineBlock, segment, fun_start))
         fun.set_name(fun_name)
         last_func = fun
     elif cmd == 'nossa':
         if len(p) != 3:
Ejemplo n.º 27
0
 def test_data(self):
     db = DbBackend(None)
     node = Node(id=NodeID(),
                 tags={'my_tag'},
                 attr={'my_attr': 'my_val'},
                 pos_start=0x123,
                 pos_end=0x456,
                 data={'my_key'},
                 bindata={'my_bindata': 12345})
     id2 = NodeID()
     db.create(node)
     db.set_data(node.id, 'int', 123)
     db.set_data(node.id, 'bool', False)
     db.set_data(node.id, 'none', None)
     db.set_data(node.id, 'bytes', b'\x01\x02\x03')
     db.set_data(node.id, 'str', 'abc')
     db.set_data(node.id, 'list', (1, 2, 3))
     db.set_data(node.id, 'dict', {'a': 'b', 'c': 'd'})
     db.set_data(node.id, 'id', id2)
     db.set_data(node.id, 'bindata', BinData.from_spaced_hex(12, '123 456'))
     db.set_data(node.id, 'long', 0x123456789abcdef123456789abcdef)
     db.set_data(node.id, 'neglong', -0x123456789abcdef123456789abcdef)
     n2 = db.get(node.id)
     self.assertEqual(
         n2.data, {
             'int',
             'bool',
             'bytes',
             'str',
             'list',
             'dict',
             'id',
             'bindata',
             'long',
             'neglong',
         })
     self.assertEqual(db.get_data(node.id, 'int'), 123)
     self.assertEqual(db.get_data(node.id, 'bool'), False)
     self.assertEqual(db.get_data(node.id, 'none'), None)
     self.assertEqual(db.get_data(node.id, 'meh'), None)
     b = db.get_data(node.id, 'bytes')
     s = db.get_data(node.id, 'str')
     self.assertEqual(b, b'\x01\x02\x03')
     self.assertEqual(s, 'abc')
     self.assertIsInstance(b, bytes)
     self.assertIsInstance(s, six.text_type)
     self.assertEqual(db.get_data(node.id, 'list'), [1, 2, 3])
     self.assertEqual(db.get_data(node.id, 'dict'), {'a': 'b', 'c': 'd'})
     self.assertEqual(db.get_data(node.id, 'id'), id2)
     self.assertEqual(db.get_data(node.id, 'bindata'),
                      BinData.from_spaced_hex(12, '123 456'))
     self.assertEqual(db.get_data(node.id, 'long'),
                      0x123456789abcdef123456789abcdef)
     self.assertEqual(db.get_data(node.id, 'neglong'),
                      -0x123456789abcdef123456789abcdef)
     with self.assertRaises(TypeError):
         db.set_data(node.id, b'zlew', 'zlew')
     with self.assertRaises(TypeError):
         db.set_data(node.id, 123, 456)
     with self.assertRaises(TypeError):
         db.get_data(node.id, b'zlew')
     with self.assertRaises(TypeError):
         db.get_data(node.id, 123)
Ejemplo n.º 28
0
 def test_from_raw_crap(self):
     with self.assertRaises(TypeError):
         BinData.from_raw_data(9.0, b'\x12')
     with self.assertRaises(TypeError):
         BinData.from_raw_data(9, u'meh')
     with self.assertRaises(ValueError):
         BinData.from_raw_data(-8, b'\x12')
     with self.assertRaises(ValueError):
         BinData.from_raw_data(0, b'\x12')
     with self.assertRaises(ValueError):
         BinData.from_raw_data(9, b'\x12')
     BinData.from_raw_data(9, b'\x12\x01')
     with self.assertRaises(ValueError):
         BinData.from_raw_data(9, b'\x12\x02')
     BinData.from_raw_data(9, b'\xff\x01\xff\x01')
     with self.assertRaises(ValueError):
         BinData.from_raw_data(9, b'\xff\x02\xff\x01')
     with self.assertRaises(ValueError):
         BinData.from_raw_data(9, b'\xff\x01\xff\x02')
     with self.assertRaises(ValueError):
         BinData.from_raw_data(9, b'\xff\x01\xff\x80')
     BinData.from_raw_data(15, b'\xff\x7f\xff\x7f')
     with self.assertRaises(ValueError):
         BinData.from_raw_data(15, b'\xff\xff\xff\x7f')
     with self.assertRaises(ValueError):
         BinData.from_raw_data(15, b'\xff\x7f\xff\xff')
Ejemplo n.º 29
0
 def test_setslice(self):
     a = BinData(19, [0x12345, 0x6789a, 0x3cdef])
     a[:] = BinData.from_spaced_hex(19, '54321 29876 7edcb')
     self.assertEqual(a, BinData.from_spaced_hex(19, '54321 29876 7edcb'))
     a[:] = BinData.from_spaced_hex(19, '11111 22222')
     self.assertEqual(a, BinData.from_spaced_hex(19, '11111 22222'))
     a = BinData(19, [0x12345, 0x6789a, 0x3cdef])
     a[1:2] = BinData.from_spaced_hex(19, '54321 29876 7edcb')
     c = BinData.from_spaced_hex(19, '12345 54321 29876 7edcb 3cdef')
     self.assertEqual(a, c)
     a[::-2] = BinData.from_spaced_hex(19, '11111 22222 33333')
     c = BinData.from_spaced_hex(19, '33333 54321 22222 7edcb 11111')
     self.assertEqual(a, c)
     with self.assertRaises(TypeError):
         a[3.0:] = BinData.from_spaced_hex(19, '11111 22222')
     with self.assertRaises(TypeError):
         a[:3.0] = BinData.from_spaced_hex(19, '11111 22222')
     with self.assertRaises(TypeError):
         a[::3.0] = BinData.from_spaced_hex(19, '11111 22222')
     with self.assertRaises(TypeError):
         a['zlew':] = BinData.from_spaced_hex(19, '11111 22222')
     with self.assertRaises(TypeError):
         a[:] = 'zlew'
     with self.assertRaises(TypeError):
         a[:] = [1, 2, 3]
     with self.assertRaises(TypeError):
         a[:] = b'\x12\x34'
     with self.assertRaises(ValueError):
         a[:] = BinData.from_spaced_hex(20, '11111 22222 33333')
     with self.assertRaises(ValueError):
         a[::2] = BinData.from_spaced_hex(19, '11111 22222')
Ejemplo n.º 30
0
 def test_getslice(self):
     a = BinData(19, [0x12345, 0x6789a, 0x3cdef])
     self.assertEqual(a[:], a)
     self.assertEqual(a[:],
                      BinData.from_spaced_hex(19, '12345 6789a 3cdef'))
     self.assertEqual(a[1:], BinData.from_spaced_hex(19, '6789a 3cdef'))
     self.assertEqual(a[4:], BinData.from_spaced_hex(19, ''))
     self.assertEqual(a[-1:], BinData.from_spaced_hex(19, '3cdef'))
     self.assertEqual(a[:-1], BinData.from_spaced_hex(19, '12345 6789a'))
     self.assertEqual(a[:1], BinData.from_spaced_hex(19, '12345'))
     self.assertEqual(a[1:2], BinData.from_spaced_hex(19, '6789a'))
     self.assertEqual(a[2:1], BinData.from_spaced_hex(19, ''))
     self.assertEqual(a[::-1],
                      BinData.from_spaced_hex(19, '3cdef 6789a 12345'))
     self.assertEqual(a[::2], BinData.from_spaced_hex(19, '12345 3cdef'))
     self.assertEqual(a[1::2], BinData.from_spaced_hex(19, '6789a'))
     b = [5 ** x for x in range(5)]
     c = BinData(10, b)
     for start in range(-10, 10):
         for end in range(-10, 10):
             for stride in range(-10, 10):
                 if stride != 0:
                     t = b[start:end:stride]
                     self.assertEqual(list(c[start:end:stride]), t)
     with self.assertRaises(TypeError):
         a[3.0:]
     with self.assertRaises(TypeError):
         a[:3.0]
     with self.assertRaises(TypeError):
         a[::3.0]
     with self.assertRaises(TypeError):
         a['zlew':]