<commit_before>import os
import cgi
import sqlite3
import dumptruck
import demjson

def authorizer_readonly(action_code, tname, cname, sql_location, trigger):
    readonlyops = [ sqlite3.SQLITE_SELECT, sqlite3.SQLITE_READ, sqlite3.SQLITE_DETACH, 31 ]  # 31=SQLITE_FUNCTION missing from library.  codes: http://www.sqlite.org/c3ref/c_alter_table.html
    if action_code in readonlyops:
        return sqlite3.SQLITE_OK

    if action_code == sqlite3.SQLITE_PRAGMA:
        if tname in ["table_info", "index_list", "index_info", "page_size", "synchronous"]:
            return sqlite3.SQLITE_OK

    # SQLite FTS (full text search) requires this permission even when reading, and
    # this doesn't let ordinary queries alter sqlite_master because of PRAGMA writable_schema
    if action_code == sqlite3.SQLITE_UPDATE and tname == "sqlite_master":
        return sqlite3.SQLITE_OK

    return sqlite3.SQLITE_DENY

def dumptruck_web(query, dbname):
    if os.path.isfile(dbname):
        # Check for the database file
        dt = dumptruck.DumpTruck(dbname)

    else:
        # Use a memory database if there is no dumptruck.db
        dt = dumptruck.DumpTruck(':memory:')

    dt.connection.set_authorizer(authorizer_readonly)

    if "q" not in query:
        data = u'Error: No query specified'
        code = 400
    else:
        sql = query['q']

        try:
            data = dt.execute(sql)
        except sqlite3.OperationalError, e:<commit_msg>tidy the dumptruck_web.py file<commit_after>import os
import cgi
import sqlite3
import dumptruck
import demjson

def authorizer_readonly(action_code, tname, cname, sql_location, trigger):
    readonlyops = [
        sqlite3.SQLITE_SELECT,
        sqlite3.SQLITE_READ,
        sqlite3.SQLITE_DETACH,

        # 31=SQLITE_FUNCTION missing from library.
        # codes: http://www.sqlite.org/c3ref/c_alter_table.html
        31,
    ]
    if action_code in readonlyops:
        return sqlite3.SQLITE_OK

    if action_code == sqlite3.SQLITE_PRAGMA:
        tnames_ok = {
            "table_info",
            "index_list",
            "index_info",
            "page_size",
            "synchronous"
        }
        if tname in tnames_ok:
            return sqlite3.SQLITE_OK

    # SQLite FTS (full text search) requires this permission even when reading,
    # and this doesn't let ordinary queries alter sqlite_master because of
    # PRAGMA writable_schema
    if action_code == sqlite3.SQLITE_UPDATE and tname == "sqlite_master":
        return sqlite3.SQLITE_OK

    return sqlite3.SQLITE_DENY

def dumptruck_web(query, dbname):
    if os.path.isfile(dbname):
        # Check for the database file
        dt = dumptruck.DumpTruck(dbname)

    else:
        # Use a memory database if there is no dumptruck.db
        dt = dumptruck.DumpTruck(':memory:')

    dt.connection.set_authorizer(authorizer_readonly)

    if "q" not in query:
        data = u'Error: No query specified'
        code = 400
    else:
        sql = query['q']

        try:
            data = dt.execute(sql)
        except sqlite3.OperationalError, e:
{'fraction_non_alphanumeric': 0.08066083576287658, 'fraction_numerical': 0.012309685779073534, 'mean_word_length': 2.6982035928143713, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1627687', 'n_tokens_mistral': 1027, 'n_tokens_neox': 963, 'n_words': 254}