<commit_before>from tornado import gen
import rethinkdb as r
import cryptohelper

from .connection import connection
from .encryption import get_user_publickey


@gen.coroutine
def pop_deauth_request(id):
    conn = yield connection()
    result = yield r.table('deauth').\
        get(id).delete(return_changes=True).run(conn)
    if result['changes']:
        return result['changes'][0]['old_val']
    return None


@gen.coroutine
def create_deauth_request(id, user_id):
    conn = yield connection()
    result = yield r.table('deauth').insert(
        {"id": id, "user_id": user_id},
        conflict='update'
    ).run(conn)
    return result


@gen.coroutine
def delete_user_data(user_id):
    conn = yield connection()
    auth = yield r.table('auth').get(user_id).delete().run(conn)
    user = yield r.table('users').get(user_id).delete().run(conn)
    encryption = yield r.table('encryption_user')\
        .get(user_id).delete().run(conn)
    return auth, user, encryption


@gen.coroutine
def save_token(provider, user_id, token_data):
    publickey = yield get_user_publickey(user_id)
    token_data_enc = cryptohelper.encrypt_blob(publickey, token_data)
    conn = yield connection()
    data = {
        "id": user_id,
        provider: token_data_enc,<commit_msg>fixed small bug in deauth process<commit_after>from tornado import gen
import rethinkdb as r
import cryptohelper

from .connection import connection
from .encryption import get_user_publickey


@gen.coroutine
def pop_deauth_request(id):
    conn = yield connection()
    result = yield r.table('deauth').\
        get(id).delete(return_changes=True).run(conn)
    if result['changes']:
        return result['changes'][0]['old_val']
    return None


@gen.coroutine
def create_deauth_request(id, user_id):
    conn = yield connection()
    result = yield r.table('deauth').insert(
        {"id": id, "user_id": user_id},
        conflict='update'
    ).run(conn)
    return result


@gen.coroutine
def delete_user_data(user_id):
    conn = yield connection()
    auth = yield r.table('auth').get(user_id).delete().run(conn)
    user = yield r.table('users').get(user_id).delete().run(conn)
    res = yield r.table('reservations').filter(r.row['user_id'] == user_id).delete().run(conn)
    encryption = yield r.table('encryption_user')\
        .get(user_id).delete().run(conn)
    return auth, user, encryption


@gen.coroutine
def save_token(provider, user_id, token_data):
    publickey = yield get_user_publickey(user_id)
    token_data_enc = cryptohelper.encrypt_blob(publickey, token_data)
    conn = yield connection()
    data = {
        "id": user_id,
        provider: token_data_enc,
{'fraction_non_alphanumeric': 0.12869435091657314, 'fraction_numerical': 0.0007482229704451926, 'mean_word_length': 3.8706739526411655, 'pattern_counts': {'":': 6, '<': 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': '5284186', 'n_tokens_mistral': 857, 'n_tokens_neox': 858, 'n_words': 190}