<commit_before>from datetime import datetime

from flask import render_template
from flask_babel import gettext as _
from werkzeug.utils import secure_filename

from config import Config
from opwen_webapp import app
from opwen_webapp import db
from opwen_webapp import uploads
from opwen_webapp.models import Addressee
from opwen_webapp.models import Attachment
from opwen_webapp.models import Email
from opwen_webapp.models import User
from utils.networking import use_interface
from utils.strings import normalize_caseless
from utils.temporary import removing


def _find_emails_by(user):
    """
    :type user: User

    """
    def query_user_email():
        return Email.sender.is_(user.email)

    def query_user_name():
        return Email.sender.is_(user.name)

    if user.email and user.name:
        return query_user_email() | query_user_name()
    elif user.email:
        return query_user_email()
    elif user.name:
        return query_user_name()
    raise ValueError('one of user.email or user.name must be set')


def _find_user_by(name_or_email):
    """
    :type name_or_email: str

    """
    if not name_or_email:
        return None

    name_or_email = normalize_caseless(name_or_email)
    return User.query.filter(User.name.is_(name_or_email) |
                             User.email.is_(name_or_email)).first()


def user_exists(name_or_email):
    """
    :type name_or_email: str

    """
    user = _find_user_by(name_or_email)
    return user is not None


def outbox_emails_for(user):
    """
    :type user: User
    :rtype: flask_sqlalchemy.BaseQuery

    """<commit_msg>Add some more type annotations<commit_after>from datetime import datetime

from flask import render_template
from flask_babel import gettext as _
from werkzeug.utils import secure_filename

from config import Config
from opwen_webapp import app
from opwen_webapp import db
from opwen_webapp import uploads
from opwen_webapp.models import Addressee
from opwen_webapp.models import Attachment
from opwen_webapp.models import Email
from opwen_webapp.models import User
from utils.networking import use_interface
from utils.strings import normalize_caseless
from utils.temporary import removing


def _find_emails_by(user):
    """
    :type user: User
    :rtype: flask_sqlalchemy.BaseQuery
    :raises ValueError: if the user instance is invalid

    """
    def query_user_email():
        return Email.sender.is_(user.email)

    def query_user_name():
        return Email.sender.is_(user.name)

    if user.email and user.name:
        return query_user_email() | query_user_name()
    elif user.email:
        return query_user_email()
    elif user.name:
        return query_user_name()
    raise ValueError('one of user.email or user.name must be set')


def _find_user_by(name_or_email):
    """
    :type name_or_email: str
    :rtype: User | None

    """
    if not name_or_email:
        return None

    name_or_email = normalize_caseless(name_or_email)
    return User.query.filter(User.name.is_(name_or_email) |
                             User.email.is_(name_or_email)).first()


def user_exists(name_or_email):
    """
    :type name_or_email: str

    """
    user = _find_user_by(name_or_email)
    return user is not None


def outbox_emails_for(user):
    """
    :type user: User
    :rtype: flask_sqlalchemy.BaseQuery

    """
{'fraction_non_alphanumeric': 0.07317073170731707, 'fraction_numerical': 0.0, 'mean_word_length': 3.4484126984126986, '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': '2855847', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1043, 'n_words': 281}