Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
match = self.pattern.match(name)
bits = int(match.group(1))
if bits % 8:
raise Exception('Size of %r not a multiple of 8 bits' % name)
super().__init__(log, name, bits // 8, float)
if self.size not in self.size_to_format:
raise Exception('Cannot unpack %d bytes as a float' % self.size)
format = self.size_to_format[self.size]
self.formats = ['<%d' + format, '>%d' + format]
self.bad = self._pack_bad(2 ** bits - 1)
def parse(self, data, count, endian):
return self._unpack(data, self.formats, self.bad, count, endian)
class Mapping(AbstractType):
def __init__(self, log, row, rows, types):
name = row[0]
base_type_name = row[1]
base_type = types.profile_to_type(base_type_name, auto_create=True)
super().__init__(log, name, base_type.size, base_type=base_type)
self._profile_to_internal = ErrorDict(log, 'No internal value for profile %r')
self._internal_to_profile = ErrorDict(log, 'No profile value for internal %r')
for row in rows:
if row[0] or row[2] is None or row[3] is None:
rows.prepend(row)
break
self.__add_mapping(row)
# log.debug('Parsed %d values' % len(self._profile_to_internal))
def profile_to_internal(self, cell_contents):
def __init__(self, log, name, size, base_type=None):
super().__init__(log, name)
self.base_type = base_type
self.size = size
@abstractmethod
def profile_to_internal(self, cell_contents):
raise NotImplementedError('%s: %s' % (self.__class__.__name__, self.name))
@abstractmethod
def parse(self, bytes, count, endian):
raise NotImplementedError('%s: %s' % (self.__class__.__name__, self.name))
class BaseType(AbstractType):
def __init__(self, log, name, size, func):
super().__init__(log, name, size)
self.__func = func
def profile_to_internal(self, cell_contents):
return self.__func(cell_contents)
class StructSupport(BaseType):
def _pack_bad(self, value):
bad = (bytearray(self.size), bytearray(self.size))
for endian in (LITTLE, BIG):
bytes = value
for i in range(self.size):