<commit_before># -*- coding: utf-8 -*-

"""Provide a Pyramid confguration entry point."""

import logging
logger = logging.getLogger(__name__)

import os

from .hooks import GetRedisClient

stub = os.environ.get('REDIS_KEY', 'REDIS')
REDIS_DB = '{0}_DB'.format(stub)
REDIS_URL = '{0}_URL'.format(stub)
REDIS_MAX_CONNECTIONS = '{0}_MAX_CONNECTIONS'.format(stub)
DEFAULT_SETTINGS = {
    'db': os.environ.get(REDIS_DB, 0),
    'url': os.environ.get(REDIS_URL, 'redis://localhost:6379'),
    'max_connections': os.environ.get(REDIS_MAX_CONNECTIONS, None),
}

class IncludeMe(object):
    """Unpack the settings and provide ``request.redis``."""
    
    def __init__(self, **kwargs):
        self.default_settings = kwargs.get('default_settings', DEFAULT_SETTINGS)
        self.get_redis = kwargs.get('get_redis', GetRedisClient())
    
    def __call__(self, config):
        settings = config.get_settings()
        for key, value in self.default_settings.items():
            settings.setdefault('redis.{0}'.format(key), value)
        config.add_request_method(self.get_redis, 'redis', reify=True)
    

includeme = IncludeMe().__call__<commit_msg>defaults: add explicit namespace to default settings.<commit_after># -*- coding: utf-8 -*-

"""Provide a Pyramid confguration entry point."""

import logging
logger = logging.getLogger(__name__)

import os

from .hooks import GetRedisClient

stub = os.environ.get('REDIS_KEY', 'REDIS')
REDIS_DB = '{0}_DB'.format(stub)
REDIS_URL = '{0}_URL'.format(stub)
REDIS_MAX_CONNECTIONS = '{0}_MAX_CONNECTIONS'.format(stub)
DEFAULT_SETTINGS = {
    'redis.db': os.environ.get(REDIS_DB, 0),
    'redis.url': os.environ.get(REDIS_URL, 'redis://localhost:6379'),
    'redis.max_connections': os.environ.get(REDIS_MAX_CONNECTIONS, None),
}

class IncludeMe(object):
    """Unpack the settings and provide ``request.redis``."""
    
    def __init__(self, **kwargs):
        self.default_settings = kwargs.get('default_settings', DEFAULT_SETTINGS)
        self.get_redis = kwargs.get('get_redis', GetRedisClient())
    
    def __call__(self, config):
        settings = config.get_settings()
        for key, value in self.default_settings.items():
            settings.setdefault(key, value)
        config.add_request_method(self.get_redis, 'redis', reify=True)
    

includeme = IncludeMe().__call__
{'fraction_non_alphanumeric': 0.14597602739726026, 'fraction_numerical': 0.008133561643835616, 'mean_word_length': 4.228187919463087, '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': '5499786', 'n_tokens_mistral': 790, 'n_tokens_neox': 794, 'n_words': 149}