<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.8.0'
__versionfull__ = __version__

import uuid
import hashlib
import inspect
import warnings
import exceptions

from types import NoneType
from functools import wraps

from werkzeug import import_string
from werkzeug.contrib.cache import BaseCache, NullCache
from flask import request, current_app

JINJA_CACHE_ATTR_NAME = '_template_fragment_cache'

def function_namespace(f):
    """
    Attempts to returns unique namespace for function
    """

    if hasattr(f, 'im_func'):
        return '%s.%s.%s' % (f.__module__, f.im_class.__name__, f.__name__)
    else:
        return '%s.%s' % (f.__module__, f.__name__)

#: 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.cache = None

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

        self._memoized = []

    def init_app(self, app, config=None):
        "This is used to initialize cache with your app object"

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

        if not isinstance(self.config, (NoneType, dict)):
            raise ValueError("`config` must be an instance of dict or NoneType")

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

        if self.with_jinja2_ext:
            setattr(app.jinja_env, JINJA_CACHE_ATTR_NAME, self)

            from flask.ext.cache.jinja2ext import CacheExtension
            app.jinja_env.add_extension(CacheExtension)

        self.app = app

        self._set_cache()

    def _set_cache(self):
        import_me = self.config['CACHE_TYPE']
        if '.' not in import_me:
            import_me = 'flask.ext.cache.backends.' + \
                        import_me

        cache_obj = import_string(import_me)
        cache_args = self.config['CACHE_ARGS'][:]
        cache_options = dict(default_timeout= \
                             self.config['CACHE_DEFAULT_TIMEOUT'])

        if self.config['CACHE_OPTIONS']:
            cache_options.update(self.config['CACHE_OPTIONS'])

        self.cache = cache_obj(self.app, self.config, cache_args, cache_options)

        if not isinstance(self.cache, BaseCache):
            raise TypeError("Cache object must subclass "
                            "werkzeug.contrib.cache.BaseCache")

    def get(self, *args, **kwargs):
        "Proxy function for internal cache object."
        try:
            return self.cache.get(*args, **kwargs)
        except exceptions.Exception:
            return None
<commit_msg>not catching exceptions from internal cache object<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.8.0'
__versionfull__ = __version__

import uuid
import hashlib
import inspect
import warnings
import exceptions

from types import NoneType
from functools import wraps

from werkzeug import import_string
from werkzeug.contrib.cache import BaseCache, NullCache
from flask import request, current_app

JINJA_CACHE_ATTR_NAME = '_template_fragment_cache'

def function_namespace(f):
    """
    Attempts to returns unique namespace for function
    """

    if hasattr(f, 'im_func'):
        return '%s.%s.%s' % (f.__module__, f.im_class.__name__, f.__name__)
    else:
        return '%s.%s' % (f.__module__, f.__name__)

#: 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.cache = None

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

        self._memoized = []

    def init_app(self, app, config=None):
        "This is used to initialize cache with your app object"

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

        if not isinstance(self.config, (NoneType, dict)):
            raise ValueError("`config` must be an instance of dict or NoneType")

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

        if self.with_jinja2_ext:
            setattr(app.jinja_env, JINJA_CACHE_ATTR_NAME, self)

            from flask.ext.cache.jinja2ext import CacheExtension
            app.jinja_env.add_extension(CacheExtension)

        self.app = app

        self._set_cache()

    def _set_cache(self):
        import_me = self.config['CACHE_TYPE']
        if '.' not in import_me:
            import_me = 'flask.ext.cache.backends.' + \
                        import_me

        cache_obj = import_string(import_me)
        cache_args = self.config['CACHE_ARGS'][:]
        cache_options = dict(default_timeout= \
                             self.config['CACHE_DEFAULT_TIMEOUT'])

        if self.config['CACHE_OPTIONS']:
            cache_options.update(self.config['CACHE_OPTIONS'])

        self.cache = cache_obj(self.app, self.config, cache_args, cache_options)

        if not isinstance(self.cache, BaseCache):
            raise TypeError("Cache object must subclass "
                            "werkzeug.contrib.cache.BaseCache")

    def get(self, *args, **kwargs):
        "Proxy function for internal cache object."
        return self.cache.get(*args, **kwargs)

{'fraction_non_alphanumeric': 0.10905564672534686, 'fraction_numerical': 0.005669103386543339, 'mean_word_length': 2.5265649658074696, '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': '6054881', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1943, 'n_words': 481}