<commit_before>from copy import copy
import pickle

import redis


class RedisDriver(object):
    EXPIRE_SECONDS = 24 * 60 * 60
    DEFAULT_STORAGE_IDENTIFIERS = {
        'db_sessions': 0,
        'db_notifications': 1,
    }

    dataset = None

    def __init__(self, manager, settings):
        self.manager = manager
        self.settings = settings

    def load(self, dataset):
        self.dataset = dataset

    def set(self, session_id, session):
        pickled_session = pickle.dumps(session)
        self.__setup_dataset()
        self.dataset.set(session_id, pickled_session)
        self.dataset.expire(session_id, self.EXPIRE_SECONDS)

    def get(self, session_id):
        self.__setup_dataset()
        raw_session = self.dataset.get(session_id)

        return self.__to_dict(raw_session)

    def __to_dict(self, raw_session):
        if raw_session is None:
            return {}
        else:
            return pickle.loads(raw_session)

    def __setup_dataset(self):
        if self.dataset is None:
            self.dataset = redis.Redis(**self.settings)


class DriverFactory(object):
    STORAGE_CATEGORIES = ('db_sessions', 'db_notifications')

    def create(self, name, storage_settings, storage_category):
        return self.create_redis(storage_settings, storage_category)

    def create_redis(self, storage_settings, storage_category):
        storage_settings = copy(storage_settings)
        default_storage_identifier = RedisDriver.DEFAULT_STORAGE_IDENTIFIERS[storage_category]
        storage_settings['db'] = storage_settings.get(storage_category, default_storage_identifier)
        for storage_category in self.STORAGE_CATEGORIES:
            if storage_category in storage_settings.keys():
                del storage_settings[storage_category]

        return RedisDriver(self, storage_settings)<commit_msg>Removing useless parameter from RedisDriver constructor<commit_after>from copy import copy
import pickle

import redis


class RedisDriver(object):
    EXPIRE_SECONDS = 24 * 60 * 60
    DEFAULT_STORAGE_IDENTIFIERS = {
        'db_sessions': 0,
        'db_notifications': 1,
    }

    dataset = None

    def __init__(self, settings):
        self.settings = settings

    def load(self, dataset):
        self.dataset = dataset

    def set(self, session_id, session):
        pickled_session = pickle.dumps(session)
        self.__setup_dataset()
        self.dataset.set(session_id, pickled_session)
        self.dataset.expire(session_id, self.EXPIRE_SECONDS)

    def get(self, session_id):
        self.__setup_dataset()
        raw_session = self.dataset.get(session_id)

        return self.__to_dict(raw_session)

    def __to_dict(self, raw_session):
        if raw_session is None:
            return {}
        else:
            return pickle.loads(raw_session)

    def __setup_dataset(self):
        if self.dataset is None:
            self.dataset = redis.Redis(**self.settings)


class DriverFactory(object):
    STORAGE_CATEGORIES = ('db_sessions', 'db_notifications')

    def create(self, name, storage_settings, storage_category):
        return self.create_redis(storage_settings, storage_category)

    def create_redis(self, storage_settings, storage_category):
        storage_settings = copy(storage_settings)
        default_storage_identifier = RedisDriver.DEFAULT_STORAGE_IDENTIFIERS[storage_category]
        storage_settings['db'] = storage_settings.get(storage_category, default_storage_identifier)
        for storage_category in self.STORAGE_CATEGORIES:
            if storage_category in storage_settings.keys():
                del storage_settings[storage_category]

        return RedisDriver(storage_settings)
{'fraction_non_alphanumeric': 0.08049702863317126, 'fraction_numerical': 0.004321988114532685, 'mean_word_length': 3.151345291479821, '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': '6389627', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1070, 'n_words': 218}