def castToBuiltCorrectCredType(cred, section, key, value, update=False):
    'Will cast value to the correct type depending on the cred class, section and key'
    keep_original_value = None

    if cred == 'MtMessagingCredential':
        if section == 'Authorization':
            if value.lower() in TrueBoolCastMap:
                value = True
            elif value.lower() in FalseBoolCastMap:
                value = False
        elif section == 'Quota':
            if value.lower() == 'none':
                value = None
            elif update and value[:1] in ['+', '-']:
                if (key in ['balance', 'early_decrement_balance_percent',
                            'http_throughput', 'smpps_throughput']):
                    keep_original_value = float(value)
                    if keep_original_value > 0:
                        # Since 'plus' sign will vanish, this is a way to keep track of it ...
                        # 'plus' and type of the value are encoded
                        keep_original_value = '+f%s' % float(value)
                    value = abs(float(value))
                elif key == 'submit_sm_count':
                    keep_original_value = int(value)
                    if keep_original_value > 0:
                        # Since 'plus' sign will vanish, this is a way to keep track of it ...
                        # 'plus' and type of the value are encoded
                        keep_original_value = '+i%s' % int(value)
                    value = abs(int(value))
            elif (key in ['balance', 'early_decrement_balance_percent',
                          'http_throughput', 'smpps_throughput']):
                value = float(value)
            elif key == 'submit_sm_count':
                value = int(value)

        # Make a final validation: pass value to a temporarly MtMessagingCredential
        # object, an exception will be raised if the type is not correct
        _o = MtMessagingCredential()
        getattr(_o, 'set%s' % section)(key, value)
    elif cred == 'SmppsCredential':
        if section == 'Authorization':
            if value.lower() in TrueBoolCastMap:
                value = True
            elif value.lower() in FalseBoolCastMap:
                value = False
        elif section == 'Quota':
            if value.lower() == 'none':
                value = None
            elif update and value[:1] in ['+', '-']:
                if key == 'max_bindings':
                    keep_original_value = int(value)
                    if keep_original_value > 0:
                        # Since 'plus' sign will vanish, this is a way to keep track of it ...
                        # 'plus' and type of the value are encoded
                        keep_original_value = '+i%s' % int(value)
                    value = abs(int(value))
            elif key == 'max_bindings':
                value = int(value)

        # Make a final validation: pass value to a temporarly SmppsCredential
        # object, an exception will be raised if the type is not correct
        _o = SmppsCredential()
        getattr(_o, 'set%s' % section)(key, value)

    if keep_original_value is not None:
        return keep_original_value
    else:
        return value
dataset/ETHPy150Open jookies/jasmin/jasmin/protocols/cli/usersm.py/castToBuiltCorrectCredType/original