예제 #1
0
def handle_getlist(key):
    """Return a tuple containing True if the key contained a list and
    the message to send back to the client."""
    return_value = exists, value = handle_get(key)
    if not isinstance(value, list):
        return (
            False,
            'ERROR: Key [{}] contains non-list value ([{}])'.format(key, value)
        )
    else:
        return return_value
예제 #2
0
def handle_append(key, value):
    """Return a tuple containing True if the key's value could be appended to
    and the message to send back to the client."""
    exists, list_value = handle_get(key)

    try:
        DATABASE_DICT[key]
        DATABASE_DICT[key].append(value)
    except KeyError:
        operation_status = False
        return_msg = 'ERROR: Key [{}] does not exists'.format(key)
    except AttributeError:
        operation_status = False
        return_msg = 'ERROR: Key [{}] contains non-list value ([{}])'.format(key, value)
    else:
        operation_status = True
        return_msg = 'Key [{}] had value [{}] appended'.format(key, value)

    return operation_status, return_msg
예제 #3
0
def handle_increment(key):
    """Return a tuple containing True if the key's value could be incremented
    and the message to send back to the client."""
    exists, value = handle_get(key)

    try:
        DATABASE_DICT[key]
        DATABASE_DICT[key] = value + 1
    except KeyError:
        operation_status = False
        return_msg = 'ERROR: Key [{}] does not exists'.format(key)
    except TypeError:
        operation_status = False
        return_msg = 'ERROR: Key [{}] contains non-int value ([{}])'.format(key, value)
    else:
        operation_status = True
        return_msg = 'Key [{}] incremented'.format(key)

    return operation_status, return_msg