def process_constraints(data, constraint_fields):
    """
    Callback to move constrained fields from incoming data into a 'constraints'
    key.

    :param data:
        Incoming argument dict

    :param constraint_fields:
        Constrained fields to move into 'constraints' dict
    """
    # Always use a list so that we can handle bulk operations
    objects = data if isinstance(data, list) else [data]

    # Enforce that pattern is a string.
    if data['pattern'] is None:
        data['pattern'] = ''

    for obj in objects:
        constraints = {}
        for c_field in constraint_fields:
            try:
                c_value = obj.pop(c_field)
            except __HOLE__:
                continue
            else:
                # If the value is not set, translate it to False
                if c_value is None:
                    c_value = False
                constraints[c_field] = c_value
        obj['constraints'] = constraints
    return data
dataset/ETHPy150Open dropbox/pynsot/pynsot/commands/callbacks.py/process_constraints