<commit_before># -*- coding: utf-8 -*-

import re
import random
import string

from SECRET import SECRET1, SECRET2

from Crypto.Hash import SHA256, HMAC
from database import User, Page


def check_username(username):
    USER_RE = re.compile(r'^[a-zA-Z0-9_-]{3,20}$')
    return USER_RE.match(username)


def used_username(username):
    q = User.query(User.username == username)
    return q.get()


def check_password(password):
    PASSWORD_RE = re.compile(r'^.{3,20}$')
    return PASSWORD_RE.match(password)


def check_verify(password, verify):
    return password == verify


def signup_errors(username, password, verify):
    username_error = password_error = verify_error = ''

    if check_username(username) is None:
        username_error = 'Please enter a valid username'
    elif used_username(username):
        username_error = 'This username is already in use'

    if check_password(password) is None:
        password_error = 'Please enter a valid password'
    if not check_verify(password, verify):
        verify_error = 'Your passwords do not match'

    return username_error, password_error, verify_error


def make_salt():
    return ''.join([random.choice(string.ascii_letters
                                  + string.digits
                                  for i in range(16))])


def hash_password(password, salt):
    h = HMAC.new(salt, password + SECRET1, SHA256)
    return h.hexdigest()


def valid_password(password, salt, hashed):
    return hash_password(password, salt) == hashed


def make_cookie(username):
    h = HMAC.new(SECRET2, username, SHA256)
    return '{}|{}'.format(username, h.hexdigest())


def valid_cookie(cookie):
    username, hashed = cookie.split('|')
    return make_cookie(username) == cookie


def create_user(username, password, email):
    salt = make_salt()
    hashed = hash_password(password, salt)
    u = User(username=username,
             email=email,
             salt=salt,
             password=<PASSWORD>)
    u.put()


def login(username, password):
    u = User.query(User.username == username).get()

    if u and valid_password(password, u.salt, u.password):
        error = ''
    else:
        error = 'Invalid login!'
    return error


def create_page(PAGE_RE, content):
    p = Page(page=PAGE_RE,
             content=content)
    p.put()


def get_page(PAGE_RE):
    p = Page.query(Page.page == PAGE_RE).get()
    return p


def update_page(PAGE_RE, content):
    p = get_page(PAGE_RE)
    p.content = content
    p.put()
<commit_msg>Fix errors and change varialbe names<commit_after># -*- coding: utf-8 -*-

import re
import random
import string

from SECRET import SECRET1, SECRET2

from Crypto.Hash import SHA256, HMAC
from database import User, Page


def check_username(username):
    USER_RE = re.compile(r'^[a-zA-Z0-9_-]{3,20}$')
    return USER_RE.match(username)


def used_username(username):
    q = User.query(User.username == username)
    return q.get()


def check_password(password):
    PASSWORD_RE = re.compile(r'^.{3,20}$')
    return PASSWORD_RE.match(password)


def check_verify(password, verify):
    return password == verify


def signup_errors(username, password, verify):
    username_error = password_error = verify_error = ''

    if check_username(username) is None:
        username_error = 'Please enter a valid username'
    elif used_username(username):
        username_error = 'This username is already in use'

    if check_password(password) is None:
        password_error = 'Please enter a valid password'
    if not check_verify(password, verify):
        verify_error = 'Your passwords do not match'

    return username_error, password_error, verify_error


def make_salt():
    return ''.join([random.choice(string.ascii_letters + string.digits)
                    for i in range(16)])


def hash_password(password, salt):
    h = HMAC.new(salt, password + SECRET1, SHA256)
    return h.hexdigest()


def valid_password(password, salt, hashed):
    return hash_password(password, salt) == hashed


def make_cookie(username):
    h = HMAC.new(SECRET2, username, SHA256)
    return '{}|{}'.format(username, h.hexdigest())


def valid_cookie(cookie):
    username, hashed = cookie.split('|')
    return make_cookie(username) == cookie


def create_user(username, password, email):
    salt = make_salt()
    hashed = hash_password(password, salt)
    u = User(username=username,
             email=email,
             salt=salt,
             password=hashed)
    u.put()


def login(username, password):
    u = User.query(User.username == username).get()

    if u and valid_password(password, u.salt, u.password):
        error = ''
    else:
        error = 'Invalid login!'
    return error


def create_page(name, content):
    p = Page(name=name,
             content=content)
    p.put()
    return p


def get_page(name):
    p = Page.query(Page.name == name).get()
    return p


def update_page(name, content):
    p = get_page(name)
    p.content = content
    p.put()
    return p

{'fraction_non_alphanumeric': 0.11387616961974915, 'fraction_numerical': 0.009556042205853077, 'mean_word_length': 3.1315789473684212, '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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3150361', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1543, 'n_words': 407}