def upsert_role_requests(cursor, uuid_, roles):
if not isinstance(roles, (list, set, tuple)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>.format(type(roles)))<EOL><DEDENT>acceptors = set([(x['<STR_LIT>'], x['<STR_LIT>'],) for x in roles])<EOL>cursor.execute("""<STR_LIT>""", (uuid_,))<EOL>existing_roles = cursor.fetchall()<EOL>existing_acceptors = set([(r, t,) for r, t, _ in existing_roles])<EOL>new_acceptors = acceptors.difference(existing_acceptors)<EOL>for acceptor, type_ in new_acceptors:<EOL><INDENT>has_accepted = [x.get('<STR_LIT>', None)<EOL>for x in roles<EOL>if acceptor == x['<STR_LIT>'] and type_ == x['<STR_LIT>']][<NUM_LIT:0>]<EOL>cursor.execute("""<STR_LIT>""", (uuid_, acceptor, type_, has_accepted,))<EOL><DEDENT>acceptors = set([<EOL>(x['<STR_LIT>'], x['<STR_LIT>'], x.get('<STR_LIT>', None),)<EOL>for x in roles<EOL>if (x['<STR_LIT>'], x.get('<STR_LIT>', None),) not in new_acceptors<EOL>])<EOL>existing_acceptors = set([<EOL>x for x in existing_roles<EOL>if (x[<NUM_LIT:0>], x[<NUM_LIT:1>],) not in new_acceptors<EOL>])<EOL>tobe_updated_acceptors = acceptors.difference(existing_acceptors)<EOL>for uid, type_, has_accepted in tobe_updated_acceptors:<EOL><INDENT>cursor.execute("""<STR_LIT>""",<EOL>(has_accepted, uuid_, uid, type_,))<EOL><DEDENT>
Given a ``uuid`` and list of dicts containing the ``uid`` and
    ``role`` for creating a role acceptance entry. The ``roles`` dict
    can optionally contain a ``has_accepted`` value, which will default
    to true.