<commit_before>from django import template
from django.conf import settings
try:
    from django.core.cache import caches
except:
    from django.core.cache import get_cache as caches

if caches.__module__.startswith('debug_toolbar'):
    from debug_toolbar.panels.cache import base_get_cache as caches

get_cache = lambda cache_name: caches(cache_name) if hasattr(caches, '__call__') else caches[cache_name]
register = template.Library()

class CacheStats(template.Node):
    """
    Reads the cache stats out of the memcached cache backend. Returns `None`
    if no cache stats supported.
    """
    def render(self, context):
        cache_stats = []
        for cache_backend_nm, cache_backend_attrs in settings.CACHES.iteritems():
            try:
                cache_backend = get_cache(cache_backend_nm)
                this_backend_stats = cache_backend._cache.get_stats()
                # returns list of (name, stats) tuples
                for server_name, server_stats in this_backend_stats:
                    cache_stats.append(("%s: %s" % (
                        cache_backend_nm, server_name), server_stats))
            except AttributeError: # this backend probably doesn't support that
                continue
        context['cache_stats'] = cache_stats
        return ''

@register.tag
def get_cache_stats(parser, token):
    return CacheStats()

@register.filter
def prettyname(name):<commit_msg>Fix for django debug toolbar.<commit_after>from django import template
from django.conf import settings
try:
    from django.core.cache import caches
except:
    from django.core.cache import get_cache as caches

if caches.__module__.startswith('debug_toolbar'):
    from debug_toolbar.panels.cache import original_get_cache as caches

get_cache = lambda cache_name: caches(cache_name) if hasattr(caches, '__call__') else caches[cache_name]
register = template.Library()

class CacheStats(template.Node):
    """
    Reads the cache stats out of the memcached cache backend. Returns `None`
    if no cache stats supported.
    """
    def render(self, context):
        cache_stats = []
        for cache_backend_nm, cache_backend_attrs in settings.CACHES.iteritems():
            try:
                cache_backend = get_cache(cache_backend_nm)
                this_backend_stats = cache_backend._cache.get_stats()
                # returns list of (name, stats) tuples
                for server_name, server_stats in this_backend_stats:
                    cache_stats.append(("%s: %s" % (
                        cache_backend_nm, server_name), server_stats))
            except AttributeError: # this backend probably doesn't support that
                continue
        context['cache_stats'] = cache_stats
        return ''

@register.tag
def get_cache_stats(parser, token):
    return CacheStats()

@register.filter
def prettyname(name):
{'fraction_non_alphanumeric': 0.07973537604456825, 'fraction_numerical': 0.0, 'mean_word_length': 2.9248633879781423, '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': '4901222', 'n_tokens_mistral': 790, 'n_tokens_neox': 774, 'n_words': 221}