<commit_before>from pony.thirdparty import sqlite

from pony.thirdparty.sqlite import (Warning, Error, InterfaceError, DatabaseError,
                                    DataError, OperationalError, IntegrityError, InternalError,
                                    ProgrammingError, NotSupportedError)

from pony import dbapiprovider
from pony.utils import localbase
from os import path

paramstyle = 'qmark'

class Local(localbase):
    def __init__(self):
        self.connections = {}

local = Local()

def quote_name(connection, name):
    return dbapiprovider.quote_name(name)

def connect(filename, create=False):
    conn = local.connections.get(filename)
    if conn is None:
        if not create and filename != ':memory:' and not path.exists(filename):
            raise IOError("Database file is not found: %r" % filename)
        local.connections[filename] = conn = sqlite.connect(filename)
    return conn

def release(connection):
    pass

def ast2sql(con, ast):
    b = dbapiprovider.SQLBuilder(ast)
    return b.sql, b.adapter
<commit_msg>Share one instance of SQLite :memory: db between all threads<commit_after>from pony.thirdparty import sqlite

from pony.thirdparty.sqlite import (Warning, Error, InterfaceError, DatabaseError,
                                    DataError, OperationalError, IntegrityError, InternalError,
                                    ProgrammingError, NotSupportedError)

from pony import dbapiprovider
from pony.utils import localbase
from os import path

paramstyle = 'qmark'

class Local(localbase):
    def __init__(self):
        self.connections = {}

local = Local()

memory_db_conn = None

def quote_name(connection, name):
    return dbapiprovider.quote_name(name)

def connect(filename, create=False):
    if filename == ':memory:':
        global memory_db_conn
        if memory_db_conn is None:
            try: memory_db_conn = sqlite.connect(':memory:', check_same_thread=False)
            except TypeError, e:
                if 'check_same_thread' in e.args[0]:
                    raise TypeError("Please upgrade sqlite or use file database instead of :memory:")
        return memory_db_conn

    conn = local.connections.get(filename)
    if conn is None:
        if not create and not path.exists(filename):
            raise IOError("Database file is not found: %r" % filename)
        local.connections[filename] = conn = sqlite.connect(filename)
    return conn

def release(connection):
    pass

def ast2sql(con, ast):
    b = dbapiprovider.SQLBuilder(ast)
    return b.sql, b.adapter

{'fraction_non_alphanumeric': 0.0802118804388952, 'fraction_numerical': 0.0011350737797956867, 'mean_word_length': 2.607094133697135, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7190352', 'n_tokens_mistral': 768, 'n_tokens_neox': 699, 'n_words': 211}