def modbus_context_decoder(mapping_blocks):
 blocks = defaultdict(dict)
 for block in mapping_blocks.itervalues():
  for mapping in block.itervalues():
   value = int(mapping['value'])
   address = int(mapping['address'])
   function = mapping['function']
   blocks[function][address] = value
 return ModbusSlaveContext(**blocks)

def modbus_context_decoder ( mapping_blocks ) : blocks = defaultdict ( dict ) for block in mapping_blocks . itervalues ( ) : for mapping in block . itervalues ( ) : value = int ( mapping [ 'value' ] ) address = int ( mapping [ 'address' ] ) function = mapping [ 'function' ] blocks [ function ] [ address ] = value return ModbusSlaveContext ( ** blocks )
given a mapping block input .