<commit_before>
import uuid

from six import string_types
from werkzeug import generate_password_hash, check_password_hash

from bokeh.exceptions import DataIntegrityException

from .docs import Doc
from .. import models

def apiuser_from_request(app, request):
    apikey = request.headers.get('BOKEHUSER-API-KEY')
    if not apikey:
        return None
    username = request.headers['BOKEHUSER']
    bokehuser = User.load(app.servermodel_storage, username)
    if bokehuser.apikey == apikey:
        return bokehuser
    else:
        return None

def new_user(client, username, password, apikey=None, docs=None):
    """there is probably a race condition here if the same user
    is registered at the same time since redis doesn't have transactions
    """
    if apikey is None:
        apikey = str(uuid.uuid4())
    passhash = generate_password_hash(password, method='sha1')
    user = User(username, passhash, apikey, docs=docs)
    user.create(client)<commit_msg>should return none if user does not exist<commit_after>
import uuid

from six import string_types
from werkzeug import generate_password_hash, check_password_hash

from bokeh.exceptions import DataIntegrityException

from .docs import Doc
from .. import models

def apiuser_from_request(app, request):
    apikey = request.headers.get('BOKEHUSER-API-KEY')
    if not apikey:
        return None
    username = request.headers['BOKEHUSER']
    bokehuser = User.load(app.servermodel_storage, username)
    if bokehuser is None:
        return None
    if bokehuser.apikey == apikey:
        return bokehuser
    else:
        return None

def new_user(client, username, password, apikey=None, docs=None):
    """there is probably a race condition here if the same user
    is registered at the same time since redis doesn't have transactions
    """
    if apikey is None:
        apikey = str(uuid.uuid4())
    passhash = generate_password_hash(password, method='sha1')
    user = User(username, passhash, apikey, docs=docs)
    user.create(client)
{'fraction_non_alphanumeric': 0.07871287128712871, 'fraction_numerical': 0.0019801980198019802, 'mean_word_length': 3.744131455399061, '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': '2855125', 'n_tokens_mistral': 602, 'n_tokens_neox': 600, 'n_words': 190}