def _scan(self, t, func): if t: t = [str(i) for i in ensure_listy(t)] result = [] for option in self.options: if len(option) == 2 and is_listy(option): label, value = option if label in t or str(value) in t: result.append(func(option)) elif option in t: result.append(option) return result return []
def make_recipients_list(recipients): """build a well formed list of recipients >>> make_recipients_list('*****@*****.**') [('*****@*****.**', '*****@*****.**')] >>> v = make_recipients_list('[email protected];[email protected]') >>> v == [ ... ('*****@*****.**', '*****@*****.**'), ... ('*****@*****.**', '*****@*****.**') ... ] True >>> make_recipients_list(['*****@*****.**']) [('*****@*****.**', '*****@*****.**')] >>> v = make_recipients_list( ... [ ... '*****@*****.**', ... ('Sally', '*****@*****.**') ... ]) >>> v == [ ... ('*****@*****.**', '*****@*****.**'), ... ('Sally', '*****@*****.**') ... ] True """ if isinstance(recipients, str): if ';' in recipients: recipients = list(zip(recipients.split(';'), recipients.split(';'))) else: recipients = (recipients, recipients) recipients = isinstance(recipients, list) and recipients or [recipients] # if it's a list we interpret it as a list of addresses since # (name, address) pairs are always tuples. recipients = ensure_listy(recipients) recipients = [isinstance(x, str) and (x, x) or x for x in recipients] return recipients