<commit_before>import json
import random

import logging
import logging.config

logging.config.fileConfig("logging.conf")
logging.getLogger('distribute')

class MemberMgr:
    '''
    Class that is responsible of dealing with the members of the list.

    The members are stored as a json file. An example is found in the
    members.json.example file.
    '''

    def __init__(self, config):
        self._members = self._members = json.load(open(config['members']))

    def active_members(self, sender = ''):
        '''
        Returns the email addresses of all the active members of the
        list, except of the sender, if one is given.
        '''
        # Normalize
        sender = sender.lower()
        return [member['email'] for member in self._members['members']
                if member['active'] and member['email'] != sender]

    def find_member(self, email):
        '''
        Returns the member with the given email address, or None if
        there is not one.
        '''
        # Normalize
        email = email.lower()
        for member in self._members['members']:
            if member['email'].lower() in email:
                logging.debug('find_member found %s' % member)
                return member
        logging.error('find_member for %s had no results' % email)
        return None

    def iswhitelisted(self, addr):
        '''Checks if the given email address appears in the
        whitelist.'''
        return addr.lower() in self._members['whitelist']

    def choose_name(self, member):
        '''Randomly chooses a name for the given member, between her
        name and aliases.'''
        if member.has_key('aliases'):
            return random.choice([member['name']] + member['aliases'])
        return member['name']<commit_msg>rewrite member search with a generator<commit_after>import json
import random

import logging
import logging.config

logging.config.fileConfig("logging.conf")
logging.getLogger('distribute')

class MemberMgr:
    '''
    Class that is responsible of dealing with the members of the list.

    The members are stored as a json file. An example is found in the
    members.json.example file.
    '''

    def __init__(self, config):
        self._members = self._members = json.load(open(config['members']))

    def active_members(self, sender = ''):
        '''
        Returns the email addresses of all the active members of the
        list, except of the sender, if one is given.
        '''
        # Normalize
        sender = sender.lower()
        return [member['email'] for member in self._members['members']
                if member['active'] and member['email'] != sender]

    def find_member(self, email):
        '''
        Returns the member with the given email address, or None if
        there is not one.
        '''
        # Normalize
        email = email.lower()
        try:
            member = (m for m in self._members['members']
                      if m['email'].lower() in email).next()
        except StopIteration:
            logging.error('find_member for %s had no results' % email)
            return None
        logging.debug('find_member found %s' % member)
        return member

    def iswhitelisted(self, addr):
        '''Checks if the given email address appears in the
        whitelist.'''
        return addr.lower() in self._members['whitelist']

    def choose_name(self, member):
        '''Randomly chooses a name for the given member, between her
        name and aliases.'''
        if member.has_key('aliases'):
            return random.choice([member['name']] + member['aliases'])
        return member['name']
{'fraction_non_alphanumeric': 0.10382513661202186, 'fraction_numerical': 0.0, 'mean_word_length': 2.3741935483870966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5856245', 'n_tokens_mistral': 952, 'n_tokens_neox': 934, 'n_words': 343}