def _process_scopes(scopes):
  """Parse a scopes list into a set of all scopes and a set of sufficient scope sets.

     scopes: A list of strings, each of which is a space-separated list of scopes.
       Examples: ['scope1']
                 ['scope1', 'scope2']
                 ['scope1', 'scope2 scope3']

     Returns:
       all_scopes: a set of strings, each of which is one scope to check for
       sufficient_scopes: a set of sets of strings; each inner set is
         a set of scopes which are sufficient for access.
         Example: {{'scope1'}, {'scope2', 'scope3'}}
  """
  all_scopes = set()
  sufficient_scopes = set()
  for scope_set in scopes:
    scope_set_scopes = frozenset(scope_set.split())
    all_scopes.update(scope_set_scopes)
    sufficient_scopes.add(scope_set_scopes)
  return all_scopes, sufficient_scopes