<commit_before>from abc import abstractmethod, ABCMeta
from six import with_metaclass
from eventsourcing.infrastructure.event_store import EventStore
from eventsourcing.infrastructure.persistence_subscriber import PersistenceSubscriber
from eventsourcing.infrastructure.stored_events.cassandra_stored_events import setup_cassandra_connection, \
    get_cassandra_setup_params, shutdown_cassandra_connection, CassandraStoredEventRepository
from eventsourcing.infrastructure.stored_events.rdbms import get_scoped_session_facade, SQLAlchemyStoredEventRepository


class EventSourcingApplication(with_metaclass(ABCMeta)):

    def __init__(self):
        self.stored_event_repo = self.create_stored_event_repo()
        self.event_store = self.create_event_store()
        self.persistence_subscriber = self.create_persistence_subscriber()

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.close()

    def close(self):
        self.persistence_subscriber.close()

    @abstractmethod
    def create_stored_event_repo(self):
        raise NotImplementedError()

    def create_event_store(self):
        return EventStore(stored_event_repo=self.stored_event_repo)

    def create_persistence_subscriber(self):
        return PersistenceSubscriber(event_store=self.event_store)


class EventSourcingWithSQLAlchemy(EventSourcingApplication):

    def __init__(self, db_session=None, db_uri=None):
        self.db_session = db_session if db_session is not None else self.create_db_session(db_uri)
        super(EventSourcingWithSQLAlchemy, self).__init__()

    @staticmethod
    def create_db_session(uri):
        return get_scoped_session_facade(uri)

    def create_stored_event_repo(self):
        return SQLAlchemyStoredEventRepository(db_session=self.db_session)


class EventSourcingWithCassandra(EventSourcingApplication):

    def __init__(self):
        self.setup_cassandra_connection()
        super(EventSourcingWithCassandra, self).__init__()

    def setup_cassandra_connection(self):
        setup_cassandra_connection(*get_cassandra_setup_params())

    def create_stored_event_repo(self):
        return CassandraStoredEventRepository()

    def close(self):
        super(EventSourcingWithCassandra, self).close()
        shutdown_cassandra_connection()<commit_msg>Exposed Cassandra connection params as application constructor params.<commit_after>from abc import abstractmethod, ABCMeta
from six import with_metaclass
from eventsourcing.infrastructure.event_store import EventStore
from eventsourcing.infrastructure.persistence_subscriber import PersistenceSubscriber
from eventsourcing.infrastructure.stored_events.cassandra_stored_events import setup_cassandra_connection, \
    get_cassandra_setup_params, shutdown_cassandra_connection, CassandraStoredEventRepository
from eventsourcing.infrastructure.stored_events.rdbms import get_scoped_session_facade, SQLAlchemyStoredEventRepository


class EventSourcingApplication(with_metaclass(ABCMeta)):

    def __init__(self):
        self.stored_event_repo = self.create_stored_event_repo()
        self.event_store = self.create_event_store()
        self.persistence_subscriber = self.create_persistence_subscriber()

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.close()

    def close(self):
        self.persistence_subscriber.close()

    @abstractmethod
    def create_stored_event_repo(self):
        raise NotImplementedError()

    def create_event_store(self):
        return EventStore(stored_event_repo=self.stored_event_repo)

    def create_persistence_subscriber(self):
        return PersistenceSubscriber(event_store=self.event_store)


class EventSourcingWithSQLAlchemy(EventSourcingApplication):

    def __init__(self, db_session=None, db_uri=None):
        self.db_session = db_session if db_session is not None else self.create_db_session(db_uri)
        super(EventSourcingWithSQLAlchemy, self).__init__()

    @staticmethod
    def create_db_session(uri):
        return get_scoped_session_facade(uri)

    def create_stored_event_repo(self):
        return SQLAlchemyStoredEventRepository(db_session=self.db_session)


class EventSourcingWithCassandra(EventSourcingApplication):

    def __init__(self, hosts=('localhost',), consistency='QUORUM', default_keyspace='eventsourcing', port=9042,
                               protocol_version=2, username=None, password=<PASSWORD>):
        self.setup_cassandra_connection(hosts, consistency, default_keyspace, port, protocol_version, username,
                                        password)
        super(EventSourcingWithCassandra, self).__init__()

    def setup_cassandra_connection(self, *args):
        setup_cassandra_connection(*get_cassandra_setup_params(*args))

    def create_stored_event_repo(self):
        return CassandraStoredEventRepository()

    def close(self):
        super(EventSourcingWithCassandra, self).close()
        shutdown_cassandra_connection()
{'fraction_non_alphanumeric': 0.06801507039460639, 'fraction_numerical': 0.00099147332936744, 'mean_word_length': 4.865116279069768, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2742709', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1427, 'n_words': 240}