pytricia
pytricia copied to clipboard
Look up by bytes fails
The byte lookup is coded for Little Endian systems and breaks on Big Endian machines, yes S390 is alive and kicking.
self = <test.PyTriciaTests testMethod=testNonStringKey>
def testNonStringKey(self):
pyt = pytricia.PyTricia()
# insert as string
pyt['10.1.2.3/24'] = 'abc'
# lookup as string
for i in range(256):
self.assertEqual(pyt['10.1.2.{}'.format(i)], 'abc')
# lookup as bytes (or, ugh, another str in python2)
b = socket.inet_aton('10.1.2.3')
self.assertEqual(pyt[b], 'abc')
# bytes in py3k. python2 stinks.
if sys.version_info.major == 3 and sys.version_info.minor >= 4:
i = b[0] * 2**24 + b[1] * 2**16 + b[2] * 2**8
for j in range(256):
> self.assertEqual(pyt[i+j], 'abc')
E KeyError: 'Prefix not found.'