<commit_before>import logbook


class LazyDatabaseMixin(object):
    """
    A mixin class that gives the subclass lazy access to the database layer

    The lazy attribute self.db is added, and the database class is gotten from
    self.config, and an instance is made and returned.

    """

    _db = None

    @property
    def db(self):
        assert hasattr(self, 'config') and self.config is not None, \
            'Database accessed before self.config was set.'

        if self._db is None:
            self._db = self.config.get_database(self.config)
            self._db.setup()

        return self._db


# Let's name this DatabaseBase. 'tis a silly name.
class DatabaseBase(object):
    """
    Abstract class representing a persistance layer

    """

    def __init__(self):
        self.log = logbook.Logger(self.__class__.__name__)

    def init(self, ns):
        raise NotImplementedError()


class DbCLI(LazyDatabaseMixin):<commit_msg>Allow setting of a LazyDatabaseMixin db.<commit_after>import logbook


class LazyDatabaseMixin(object):
    """
    A mixin class that gives the subclass lazy access to the database layer

    The lazy attribute self.db is added, and the database class is gotten from
    self.config, and an instance is made and returned.

    """

    _db = None

    def _get_db(self):
        if self._db is None:
            assert hasattr(self, 'config') and self.config is not None, \
                'Database accessed before self.config was set.'

            self._db = self.config.get_database(self.config)
            self._db.setup()

        return self._db

    def _set_db(self, val):
        # This is actually mostly for tests so that we don't have to do the
        # mock-out-the-property dance for all the tests that hit the db.
        self._db = val

    db = property(_get_db, _set_db)


# Let's name this DatabaseBase. 'tis a silly name.
class DatabaseBase(object):
    """
    Abstract class representing a persistance layer

    """

    def __init__(self):
        self.log = logbook.Logger(self.__class__.__name__)

    def init(self, ns):
        raise NotImplementedError()


class DbCLI(LazyDatabaseMixin):
{'fraction_non_alphanumeric': 0.08218549127640037, 'fraction_numerical': 0.0, 'mean_word_length': 2.543089430894309, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7272646', 'n_tokens_mistral': 637, 'n_tokens_neox': 600, 'n_words': 221}