import re


def check_constraint(constraint, user):
    """
    Given a constraint list from the voters definition for some election,
    those constraints are checked against user attributes. In the first non-matching
    attribute, returns False
    """
    try:
        for key, value in constraint.items():
            # some user attributes may be multivalued
            user_attrs = re.split('[,;]',user.info['attributes'][key])
            ctr_list = re.split('[,;]',constraint[key])    
            has_attr = False
            for ctr in ctr_list:
                if ctr.strip() in user_attrs:
                    has_attr = True
            if not has_attr: # if one attribute isn't available, return False
                return False
    except KeyError:
        return False

    return True