def castInputToBuiltInType(key, value):
    'Will cast value to the correct type depending on the key'

    try:
        if key in ['bind_npi', 'dst_npi', 'src_npi']:
            return addr_npi_value_map[value]
        elif key in ['bind_ton', 'dst_ton', 'src_ton']:
            return addr_ton_value_map[value]
        elif key == 'ripf':
            return replace_if_present_flap_value_map[value]
        elif key == 'priority':
            return priority_flag_value_map[value]
        elif key in ['con_fail_retry', 'con_loss_retry', 'ssl']:
            if value == 'yes':
                return True
            elif value == 'no':
                return False
            else:
                raise KeyError('Boolean value must be expressed by yes or no.')
        elif (key == 'loglevel' and
                value not in [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]):
            raise KeyError('loglevel must be numeric value of 10, 20, 30, 40 or 50.')
        elif isinstance(value, str) == str and value.lower() == 'none':
            value = None
    except KeyError:
        raise UnknownValue('Unknown value for key %s: %s' % (key, value))

    return value
dataset/ETHPy150Open jookies/jasmin/jasmin/protocols/cli/smppccm.py/castInputToBuiltInType/original