def __parse_identities(self, stream):
        def __create_sh_identities(name, emails, yaml_entry):
            ids = []
            ids.append(Identity(name=name, source=self.source))
            if emails:
                for m in emails:
                    ids.append(Identity(email=m, source=self.source))
            for pb in PERCEVAL_BACKENDS:
                if pb not in yaml_entry:
                    continue
                for username in yaml_entry[pb]:
                    identity = Identity(username=username, source=pb)
                    ids.append(identity)
            return ids
        yaml_file = self.__load_yml(stream)
        yid_counter = 0
        try:
            for yid in yaml_file:
                profile = yid['profile']
                if profile is None:
                    raise AttributeError('profile')
                name = yid['profile']['name']
                is_bot = profile.get('is_bot', False)
                emails = yid.get('email', None)
                if emails and self.email_validation:
                    self.__validate_email(emails[0])
                enrollments = yid.get('enrollments', None)
                uuid = str(yid_counter)
                yid_counter += 1
                uid = UniqueIdentity(uuid=uuid)
                prf = Profile(name=name, is_bot=is_bot)
                uid.profile = prf
                sh_identities = __create_sh_identities(name, emails, yid)
                uid.identities += sh_identities
                if enrollments:
                    affiliations = self.__parse_affiliations_yml(enrollments)
                    uid.enrollments += affiliations
                self._identities[uuid] = uid
        except KeyError as e:
            error = "Attribute %s not found" % e.args
            msg = self.GRIMOIRELAB_INVALID_FORMAT % {'error': error}
            raise InvalidFormatError(cause=msg)