<commit_before># -*- coding: utf-8 -*-
"""
    flask.ext.cache
    ~~~~~~~~~~~~~~

    Adds cache support to your application.

    :copyright: (c) 2010 by <NAME>.
    :license: BSD, see LICENSE for more details
"""

__version__ = '0.12'
__versionfull__ = __version__

import base64
import uuid
import hashlib
import inspect
import functools
import warnings
import logging

from werkzeug import import_string
from flask import request, current_app


logger = logging.getLogger(__name__)

TEMPLATE_FRAGMENT_KEY_TEMPLATE = '_template_fragment_cache_%s%s'


def function_namespace(f, args=None):
    """
    Attempts to returns unique namespace for function
    """
    m_args = inspect.getargspec(f)[0]

    if len(m_args) and args:
        if m_args[0] == 'self':
            return '%s.%s.%s' % (f.__module__, args[0].__class__.__name__, f.__name__)
        elif m_args[0] == 'cls':
            return '%s.%s.%s' % (f.__module__, args[0].__name__, f.__name__)

    if hasattr(f, '__func__'):
        return '%s.%s.%s' % (f.__module__, f.__self__.__class__.__name__, f.__name__)
    elif hasattr(f, '__class__'):
        return '%s.%s.%s' % (f.__module__, f.__class__.__name__, f.__name__)
    else:
        return '%s.%s' % (f.__module__, f.__name__)


def make_template_fragment_key(fragment_name, vary_on=[]):
    """
    Make a cache key for a specific fragment name
    """
    if vary_on:
        fragment_name = "%s_" % fragment_name
    return TEMPLATE_FRAGMENT_KEY_TEMPLATE % (fragment_name, "_".join(vary_on))


#: Cache Object
################

class Cache(object):
    """
    This class is used to control the cache objects.
    """

    def __init__(self, app=None, with_jinja2_ext=True, config=None):
        self.with_jinja2_ext = with_jinja2_ext
        self.config = config

        self.app = app
        if app is not None:
            self.init_app(app, config)

    def init_app(self, app, config=None):
        "This is used to initialize cache with your app object"
        if not (config is None or isinstance(config, dict)):
            raise ValueError("`config` must be an instance of dict or None")

        if config is None:
            config = self.config
        if config is None:
            config = app.config

        config.setdefault('CACHE_DEFAULT_TIMEOUT', 300)
        config.setdefault('CACHE_THRESHOLD', 500)
        config.setdefault('CACHE_KEY_PREFIX', 'flask_cache_')
        config.setdefault('CACHE_MEMCACHED_SERVERS', None)
        config.setdefault('CACHE_DIR', None)
        config.setdefault('CACHE_OPTIONS', None)
        config.setdefault('CACHE_ARGS', [])
        config.setdefault('CACHE_TYPE', 'null')
        config.setdefault('CACHE_NO_NULL_WARNING', False)

        if config['CACHE_TYPE'] == 'null' and not config['CACHE_NO_NULL_WARNING']:
            warnings.warn("Flask-Cache: CACHE_TYPE is set to null, "
                          "caching is effectively disabled.")<commit_msg>Chain configs together instead of using just one. Closes #86<commit_after># -*- coding: utf-8 -*-
"""
    flask.ext.cache
    ~~~~~~~~~~~~~~

    Adds cache support to your application.

    :copyright: (c) 2010 by <NAME>.
    :license: BSD, see LICENSE for more details
"""

__version__ = '0.12'
__versionfull__ = __version__

import base64
import uuid
import hashlib
import inspect
import functools
import warnings
import logging

from werkzeug import import_string
from flask import request, current_app


logger = logging.getLogger(__name__)

TEMPLATE_FRAGMENT_KEY_TEMPLATE = '_template_fragment_cache_%s%s'


def function_namespace(f, args=None):
    """
    Attempts to returns unique namespace for function
    """
    m_args = inspect.getargspec(f)[0]

    if len(m_args) and args:
        if m_args[0] == 'self':
            return '%s.%s.%s' % (f.__module__, args[0].__class__.__name__, f.__name__)
        elif m_args[0] == 'cls':
            return '%s.%s.%s' % (f.__module__, args[0].__name__, f.__name__)

    if hasattr(f, '__func__'):
        return '%s.%s.%s' % (f.__module__, f.__self__.__class__.__name__, f.__name__)
    elif hasattr(f, '__class__'):
        return '%s.%s.%s' % (f.__module__, f.__class__.__name__, f.__name__)
    else:
        return '%s.%s' % (f.__module__, f.__name__)


def make_template_fragment_key(fragment_name, vary_on=[]):
    """
    Make a cache key for a specific fragment name
    """
    if vary_on:
        fragment_name = "%s_" % fragment_name
    return TEMPLATE_FRAGMENT_KEY_TEMPLATE % (fragment_name, "_".join(vary_on))


#: Cache Object
################

class Cache(object):
    """
    This class is used to control the cache objects.
    """

    def __init__(self, app=None, with_jinja2_ext=True, config=None):
        self.with_jinja2_ext = with_jinja2_ext
        self.config = config

        self.app = app
        if app is not None:
            self.init_app(app, config)

    def init_app(self, app, config=None):
        "This is used to initialize cache with your app object"
        if not (config is None or isinstance(config, dict)):
            raise ValueError("`config` must be an instance of dict or None")

        base_config = app.config.copy()
        if self.config:
            base_config.update(self.config)
        if config:
            base_config.update(config)
        config = base_config

        config.setdefault('CACHE_DEFAULT_TIMEOUT', 300)
        config.setdefault('CACHE_THRESHOLD', 500)
        config.setdefault('CACHE_KEY_PREFIX', 'flask_cache_')
        config.setdefault('CACHE_MEMCACHED_SERVERS', None)
        config.setdefault('CACHE_DIR', None)
        config.setdefault('CACHE_OPTIONS', None)
        config.setdefault('CACHE_ARGS', [])
        config.setdefault('CACHE_TYPE', 'null')
        config.setdefault('CACHE_NO_NULL_WARNING', False)

        if config['CACHE_TYPE'] == 'null' and not config['CACHE_NO_NULL_WARNING']:
            warnings.warn("Flask-Cache: CACHE_TYPE is set to null, "
                          "caching is effectively disabled.")
{'fraction_non_alphanumeric': 0.12572759022118743, 'fraction_numerical': 0.008315316813570598, 'mean_word_length': 2.9539776462853387, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4590104', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1854, 'n_words': 476}