def _get_int_value(self, message, value): bin_len = self.length.decode_lengths(message)[0] * 8 min = pow(-2, (bin_len - 1)) max = pow(2, (bin_len - 1)) - 1 if not min <= to_int(value) <= max: raise AssertionError('Value %s out of range (%d..%d)' % (value, min, max)) return to_twos_comp(value, bin_len)
def _matches(self, header, fields, header_filter): if header_filter: if header_filter not in fields: raise AssertionError('Trying to filter messages by header field %s, but no value has been set for %s' % (header_filter, header_filter)) field = header[header_filter] if field._type == 'chars': if fields[header_filter].startswith('REGEXP:'): try: regexp = fields[header_filter].split(':')[1].strip() return bool(re.match(regexp, field.ascii)) except re.error as e: raise Exception("Invalid RegEx Error : " + str(e)) return field.ascii == fields[header_filter] if field._type == 'uint': return field.uint == to_int(fields[header_filter]) if header[header_filter].bytes != to_bin(fields[header_filter]): return False return True
def _matches(self, header, fields, header_filter): if header_filter: if header_filter not in fields: raise AssertionError( 'Trying to filter messages by header field %s, but no value has been set for %s' % (header_filter, header_filter)) field = header[header_filter] if field._type == 'chars': if fields[header_filter].startswith('REGEXP:'): try: regexp = fields[header_filter].split(':')[1].strip() return bool(re.match(regexp, field.ascii)) except re.error as e: raise Exception("Invalid RegEx Error : " + str(e)) return field.ascii == fields[header_filter] if field._type == 'uint': return field.uint == to_int(fields[header_filter]) if header[header_filter].bytes != to_bin(fields[header_filter]): return False return True
def _apply_mask_to_values(self, forced_pattern, value): val = forced_pattern[1:-1].split('&')[0].strip() mask = forced_pattern[1:-1].split('&')[1].strip() return to_int(val) & to_int(mask), to_int( to_0xhex(value)) & to_int(mask)
def _apply_mask_to_values(self, forced_pattern, value): val = forced_pattern[1:-1].split('&')[0].strip() mask = forced_pattern[1:-1].split('&')[1].strip() return to_int(val) & to_int(mask), to_int(to_0xhex(value)) & to_int(mask)