""" This module offers some utilities, in a way they are work in both Python 2 and 3 """ import binascii import logging import sys from struct import unpack log = logging.getLogger(__name__) if sys.version_info[0] == 2: import Queue as queue else: import queue as queue queue = queue # just to use it def check_unpack(seq, index, pattern, size): """Check that we got size bytes, if so, unpack using pattern""" data = seq[index: index + size] if len(data) == size: return unpack(pattern, data)[0] else: log.warning( "Unpacking of %s bytes failed, insufficient data: %r", size, seq[index:] ) raise ValueError(data, "Expected %s bytes" % (size,)) def usbyte(seq, index): return check_unpack(seq, index, "