# Path: typtop/dbaccess.py
# def get_logging_path(username):
# def get_time():
# def entropy(typo):
#     def __str__(self):
#     def __init__(self, user, debug_mode=False):
#     def __del__(self):
#     def init_typtop(self, pw, allow_typo_login=True):
#     def reinit_typtop(self, newPw):
#     def is_typtop_init(self):
#     def getdb(self, tabname):
#     def get_db_path(self):
#     def assert_initialized(self):
#     def is_allowed(self, what):
#     def allow(self, what, how):
#     def allow_upload(self, allow):
#     def allow_login(self, allow=True):
#     def is_allowed_login(self):
#     def is_allowed_upload(self):
#     def is_real_pw(self, pw):
#     def _fill_waitlist_w_garbage(self):
#         def randomstring(k):
#     def _fill_cache_w_garbage(self):
#     def get_installation_id(self):
#     def get_last_unsent_logs_iter(self, force=False):
#     def update_last_log_sent_time(self, sent_time=0, delete_old_logs=True):
#     def insert_log(self, typo, in_cache, ts=None):
#     def _add_typo_to_waitlist(self, typo):
#     def _decrypt_n_filter_waitlist(self):
#     def get_table_size(self, table_name):
#     def get_typo_cache_size():
#     def get_pk(self):
#     def cache_insert_policy(old_t_c, new_t_c):
#     def clear_waitlist(self):
#     def check_login_count(self, update=False):
#     def check(self, pw):
#     def get_from_auxtdb(self, key):
#     def set_in_auxtdb(self, key, value):
#     def validate(self, orig_pw, typo):
#     def _update_typo_cache_by_waitlist(self, typo_cache, freq_counts):
#     def get_prompt(self):
#     def set_status(self, status):
# def check_system_status(typo_db):
# def on_correct_password(typo_db, password):
# def on_wrong_password(typo_db, password):
# def call_check(exchk_ret_val, user, password):
# class UserTypoDB(object):
#     class TypoDBError(Exception):
#     class NoneInitiatedDB(TypoDBError):
#     class CorruptedDB(TypoDBError):


import os
import json
import typtop.config as config
import typtop.dbaccess as dbaccess
import yaml
import pytest
import time
import pwd
    import stat
from typtop.dbaccess import (
    UserTypoDB, get_time, on_wrong_password,
    on_correct_password, logT, auxT,
    FREQ_COUNTS, INDEX_J, WAITLIST_SIZE,
    WAIT_LIST, pkdecrypt,
    NUMBER_OF_ENTRIES_TO_ALLOW_TYPO_LOGIN,
    logT, auxT, call_check
)
        return typoDB
    # TODO: assert some property of logT


# this test takes a bit longer
def test_disabling_first_30_times(isStandAlone = True):
    # checks that entry with a typo is allowed
    # only after the real pw was entered more than 30 times
    typoDB = start_DB()
    assert not on_wrong_password(typoDB, pws[0])
    assert not on_wrong_password(typoDB, pws[1])
    assert on_correct_password(typoDB, get_pw())
    # count = 1
    # 29 left
    for i in xrange(29):
        print("{}th try".format(i))
        assert not on_wrong_password(typoDB, pws[0])
        assert not on_wrong_password(typoDB, pws[1])
        assert on_correct_password(typoDB, get_pw())
    # 30 entries have been done
    assert on_wrong_password(typoDB,pws[0])
    assert on_wrong_password(typoDB,pws[1])

    if isStandAlone:
        remove_DB()
    else:
        return typoDB


def add_pw(pw, correct=False):

# Path: typtop/dbaccess.py
# def get_logging_path(username):
# def get_time():
# def entropy(typo):
#     def __str__(self):
#     def __init__(self, user, debug_mode=False):
#     def __del__(self):
#     def init_typtop(self, pw, allow_typo_login=True):
#     def reinit_typtop(self, newPw):
#     def is_typtop_init(self):
#     def getdb(self, tabname):
#     def get_db_path(self):
#     def assert_initialized(self):
#     def is_allowed(self, what):
#     def allow(self, what, how):
#     def allow_upload(self, allow):
#     def allow_login(self, allow=True):
#     def is_allowed_login(self):
#     def is_allowed_upload(self):
#     def is_real_pw(self, pw):
#     def _fill_waitlist_w_garbage(self):
#         def randomstring(k):
#     def _fill_cache_w_garbage(self):
#     def get_installation_id(self):
#     def get_last_unsent_logs_iter(self, force=False):
#     def update_last_log_sent_time(self, sent_time=0, delete_old_logs=True):
#     def insert_log(self, typo, in_cache, ts=None):
#     def _add_typo_to_waitlist(self, typo):
#     def _decrypt_n_filter_waitlist(self):
#     def get_table_size(self, table_name):
#     def get_typo_cache_size():
#     def get_pk(self):
#     def cache_insert_policy(old_t_c, new_t_c):
#     def clear_waitlist(self):
#     def check_login_count(self, update=False):
#     def check(self, pw):
#     def get_from_auxtdb(self, key):
#     def set_in_auxtdb(self, key, value):
#     def validate(self, orig_pw, typo):
#     def _update_typo_cache_by_waitlist(self, typo_cache, freq_counts):
#     def get_prompt(self):
#     def set_status(self, status):
# def check_system_status(typo_db):
# def on_correct_password(typo_db, password):
# def on_wrong_password(typo_db, password):
# def call_check(exchk_ret_val, user, password):
# class UserTypoDB(object):
#     class TypoDBError(Exception):
#     class NoneInitiatedDB(TypoDBError):
#     class CorruptedDB(TypoDBError):


# Path: tests/test_dbaccess.py
import os
import json
import typtop.config as config
import typtop.dbaccess as dbaccess
import yaml
import pytest
import time
import pwd
    import stat
from typtop.dbaccess import (
    UserTypoDB, get_time, on_wrong_password,
    on_correct_password, logT, auxT,
    FREQ_COUNTS, INDEX_J, WAITLIST_SIZE,
    WAIT_LIST, pkdecrypt,
    NUMBER_OF_ENTRIES_TO_ALLOW_TYPO_LOGIN,
    logT, auxT, call_check
)

        return typoDB
    # TODO: assert some property of logT


# this test takes a bit longer
def test_disabling_first_30_times(isStandAlone = True):
    # checks that entry with a typo is allowed
    # only after the real pw was entered more than 30 times
    typoDB = start_DB()
    assert not on_wrong_password(typoDB, pws[0])
    assert not on_wrong_password(typoDB, pws[1])
    assert on_correct_password(typoDB, get_pw())
    # count = 1
    # 29 left
    for i in xrange(29):
        print("{}th try".format(i))
        assert not on_wrong_password(typoDB, pws[0])
        assert not on_wrong_password(typoDB, pws[1])
        assert on_correct_password(typoDB, get_pw())
    # 30 entries have been done
    assert on_wrong_password(typoDB,pws[0])
    assert on_wrong_password(typoDB,pws[1])

    if isStandAlone:
        remove_DB()
    else:
        return typoDB


def add_pw(pw, correct=False):

    db = UserTypoDB(get_username(), debug_mode=False)