def find_delegated_role(roles, delegated_role):
<EOL>securesystemslib.formats.ROLELIST_SCHEMA.check_match(roles)<EOL>securesystemslib.formats.ROLENAME_SCHEMA.check_match(delegated_role)<EOL>role_index = None<EOL>for index in six.moves.xrange(len(roles)):<EOL><INDENT>role = roles[index]<EOL>name = role.get('<STR_LIT:name>')<EOL>if name is None:<EOL><INDENT>no_name_message = '<STR_LIT>'<EOL>raise securesystemslib.exceptions.RepositoryError(no_name_message)<EOL><DEDENT>else:<EOL><INDENT>if name == delegated_role:<EOL><INDENT>if role_index is None:<EOL><INDENT>role_index = index<EOL><DEDENT>else:<EOL><INDENT>duplicate_role_message = '<STR_LIT>' + str(delegated_role) + '<STR_LIT>'<EOL>raise securesystemslib.exceptions.RepositoryError(<EOL>'<STR_LIT>' + str(delegated_role) + '<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.debug('<STR_LIT>' + repr(delegated_role))<EOL><DEDENT><DEDENT><DEDENT>return role_index<EOL>
<Purpose>
  Find the index, if any, of a role with a given name in a list of roles.

<Arguments>
  roles:
    The list of roles, each of which must have a 'name' attribute.

  delegated_role:
    The name of the role to be found in the list of roles.

<Exceptions>
  securesystemslib.exceptions.RepositoryError, if the list of roles has
  invalid data.

<Side Effects>
  No known side effects.

<Returns>
  The unique index, an interger, in the list of roles.  if 'delegated_role'
  does not exist, 'None' is returned.