<commit_before>import uuid
from flask.ext.login import UserMixin
from datetime import datetime, timedelta
from werkzeug.security import generate_password_hash, check_password_hash

from portality.dao import DomainObject as DomainObject
from portality.core import app
from portality.authorise import Authorise

class Account(DomainObject, UserMixin):
    __type__ = 'account'

    @classmethod
    def make_account(cls, username, name=None, email=None, roles=[], associated_journal_ids=[]):
        a = cls.pull(username)
        if a:
            return a

        a = Account(id=username)
        a.set_name(name) if name else None
        a.set_email(email) if email else None

        for role in roles:
            a.add_role(role)

        for jid in associated_journal_ids:
            a.add_journal(jid)
        reset_token = uuid.uuid4().hex
        # give them 14 days to create their first password if timeout not specified in config
        a.set_reset_token(reset_token, app.config.get("PASSWORD_CREATE_TIMEOUT", app.config.get('PASSWORD_RESET_TIMEOUT', 86400) * 14))
        return a

    @classmethod
    def pull_by_email(cls, email):
        res = cls.query(q='email:"' + email + '"')
        if res.get('hits', {}).get('total', 0) == 1:
            return cls(**res['hits']['hits'][0]['_source'])
        else:
            return None<commit_msg>do not use empty lists as argument defaults, they are mutable, get passed around, and entail nasty bugs<commit_after>import uuid
from flask.ext.login import UserMixin
from datetime import datetime, timedelta
from werkzeug.security import generate_password_hash, check_password_hash

from portality.dao import DomainObject as DomainObject
from portality.core import app
from portality.authorise import Authorise

class Account(DomainObject, UserMixin):
    __type__ = 'account'

    @classmethod
    def make_account(cls, username, name=None, email=None, roles=None, associated_journal_ids=None):
        if not roles:
            roles = []

        if not associated_journal_ids:
            associated_journal_ids = []

        a = cls.pull(username)
        if a:
            return a

        a = Account(id=username)
        a.set_name(name) if name else None
        a.set_email(email) if email else None

        for role in roles:
            a.add_role(role)

        for jid in associated_journal_ids:
            a.add_journal(jid)
        reset_token = <KEY>
        # give them 14 days to create their first password if timeout not specified in config
        a.set_reset_token(reset_token, app.config.get("PASSWORD_CREATE_TIMEOUT", app.config.get('PASSWORD_RESET_TIMEOUT', 86400) * 14))
        return a

    @classmethod
    def pull_by_email(cls, email):
        res = cls.query(q='email:"' + email + '"')
        if res.get('hits', {}).get('total', 0) == 1:
            return cls(**res['hits']['hits'][0]['_source'])
        else:
            return None
{'fraction_non_alphanumeric': 0.09574105621805792, 'fraction_numerical': 0.008517887563884156, 'mean_word_length': 2.8938992042440317, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1654577', 'n_tokens_mistral': 883, 'n_tokens_neox': 861, 'n_words': 248}