<commit_before>import json
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.serializers.json import DjangoJSONEncoder
from django.template.loader import render_to_string
from django.utils.module_loading import import_string


class WebpackConstants(object):
    @classmethod
    def get_constant_processors(cls):
        processors = getattr(settings, 'WEBPACK_CONSTANT_PROCESSORS', ['tg_react.webpack.default_constants'])

        if not isinstance(processors, (list, tuple)):
            raise ImproperlyConfigured('WEBPACK_CONSTANT_PROCESSORS must be a list or tuple')

        return processors

    @classmethod
    def collect(cls):
        """ Load all constant generators from settings.WEBPACK_CONSTANT_PROCESSORS
            and concat their values.
        """
        constants = {}

        for method_path in WebpackConstants.get_constant_processors():
            method = import_string(method_path)

            if not callable(method):
                raise ImproperlyConfigured('Constant processor "%s" is not callable' % method_path)

            result = method(constants)

            if isinstance(result, dict):<commit_msg>Django <1.7 support<commit_after>import json

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.template.loader import render_to_string

try:
    from django.utils.module_loading import import_string

except ImportError:
    from django.utils.module_loading import import_by_path as import_string


class WebpackConstants(object):
    @classmethod
    def get_constant_processors(cls):
        processors = getattr(settings, 'WEBPACK_CONSTANT_PROCESSORS', ['tg_react.webpack.default_constants'])

        if not isinstance(processors, (list, tuple)):
            raise ImproperlyConfigured('WEBPACK_CONSTANT_PROCESSORS must be a list or tuple')

        return processors

    @classmethod
    def collect(cls):
        """ Load all constant generators from settings.WEBPACK_CONSTANT_PROCESSORS
            and concat their values.
        """
        constants = {}

        for method_path in WebpackConstants.get_constant_processors():
            method = import_string(method_path)

            if not callable(method):
                raise ImproperlyConfigured('Constant processor "%s" is not callable' % method_path)

            result = method(constants)

            if isinstance(result, dict):
{'fraction_non_alphanumeric': 0.06954046360309069, 'fraction_numerical': 0.0008133387555917039, 'mean_word_length': 3.353982300884956, 'pattern_counts': {'":': 0, '<': 4, '<?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': '3351537', 'n_tokens_mistral': 640, 'n_tokens_neox': 634, 'n_words': 170}