<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def __parse(self, stream, has_orgs):
 """Parse identities and organizations using mailmap format. Mailmap format is a text plain document that stores on each line a map between an email address and its aliases. Each line follows any of the next formats: Proper Name <commit@email.xx> <proper@email.xx> <commit@email.xx> Proper Name <proper@email.xx> <commit@email.xx> Proper Name <proper@email.xx> Commit Name <commit@email.xx> When the flag `has_orgs` is set, the stream maps organizations an identities, following the next format: Organization Name <org@email.xx> Proper Name <proper@email.xx> :parse data: mailmap stream to parse :raise InvalidFormatError: raised when the format of the stream is not valid. """

        if has_orgs:
            self.__parse_organizations(stream)
        else:
            self.__parse_identities(stream)