def __iter__(self):
bill = self.bill<EOL>sponsors = bill['<STR_LIT>']<EOL>dictwrapper = type('<STR_LIT>', (dict,), {})<EOL>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self._legislators = {}<EOL>ids = list(filter(None, map(operator.itemgetter('<STR_LIT>'), sponsors)))<EOL>legislators = db.legislators.find({'<STR_LIT>': {'<STR_LIT>': ids}})<EOL>for obj in legislators:<EOL><INDENT>for _id in obj['<STR_LIT>']:<EOL><INDENT>self._legislators[_id] = obj<EOL><DEDENT><DEDENT><DEDENT>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self._committees = {}<EOL>ids = [s.get('<STR_LIT>')<EOL>for s in sponsors if s.get('<STR_LIT>') is not None]<EOL>if ids:<EOL><INDENT>committees = db.committees.find({'<STR_LIT>': {'<STR_LIT>': ids}})<EOL><DEDENT>else:<EOL><INDENT>committees = []<EOL><DEDENT>for obj in committees:<EOL><INDENT>self._committees[obj['<STR_LIT>']] = obj<EOL><DEDENT><DEDENT>for sponsor in sponsors:<EOL><INDENT>leg_id = sponsor.get('<STR_LIT>')<EOL>committee_id = sponsor.get('<STR_LIT>', None)<EOL>if leg_id is not None and leg_id in self._legislators:<EOL><INDENT>legislator = self._legislators[leg_id]<EOL>legislator.update(sponsor)<EOL>legislator.bill = bill<EOL>yield legislator<EOL><DEDENT>elif committee_id is not None and committee_id in self._committees:<EOL><INDENT>committee = self._committees[committee_id]<EOL>committee.update(sponsor)<EOL>committee.bill = bill<EOL>yield committee<EOL><DEDENT>else:<EOL><INDENT>spons = dictwrapper(sponsor)<EOL>spons.bill = bill<EOL>yield spons<EOL><DEDENT><DEDENT>
Lazily fetch all legislator objects from the db.