<commit_before>#-*- coding: utf-8 -*-
from django.conf import settings
from django.core import exceptions
from django.utils.importlib import import_module


class PriceModifiersPool():

    def __init__(self):
        self._modifiers_list = []

    def get_modifiers_list(self):
        if not self._modifiers_list:
            self._modifiers_list = self._load_modifiers_list()
        return self._modifiers_list

    def _load_modifiers_list(self):
        '''
        Heavily inspired by django.core.handlers.base...
        '''
        result = []
        for modifier_path in settings.SHOP_PRICE_MODIFIERS:
            try:
                mod_module, mod_classname = modifier_path.rsplit('.', 1)
            except ValueError:
                raise exceptions.ImproperlyConfigured('%s isn\'t a price modifier module' % modifier_path)
            try:
                mod = import_module(mod_module)
            except ImportError, e:
                raise exceptions.ImproperlyConfigured('Error importing modifier %s: "%s"' % (mod_module, e))
            try:
                mod_class = getattr(mod, mod_classname)
            except AttributeError:
                raise exceptions.ImproperlyConfigured('Price modifier module "%s" does not define a "%s" class' % (mod_module, mod_classname))
            try:
                mod_instance = mod_class()
            except exceptions.MiddlewareNotUsed:<commit_msg>Added a variable controlling caching behavior (for testing purposes)<commit_after>#-*- coding: utf-8 -*-
from django.conf import settings
from django.core import exceptions
from django.utils.importlib import import_module


class PriceModifiersPool():
    
    USE_CACHE = True
    
    def __init__(self):
        self._modifiers_list = []

    def get_modifiers_list(self):
        if not self.USE_CACHE or not self._modifiers_list:
            self._modifiers_list = self._load_modifiers_list()
        return self._modifiers_list

    def _load_modifiers_list(self):
        '''
        Heavily inspired by django.core.handlers.base...
        '''
        result = []
        for modifier_path in settings.SHOP_PRICE_MODIFIERS:
            try:
                mod_module, mod_classname = modifier_path.rsplit('.', 1)
            except ValueError:
                raise exceptions.ImproperlyConfigured('%s isn\'t a price modifier module' % modifier_path)
            try:
                mod = import_module(mod_module)
            except ImportError, e:
                raise exceptions.ImproperlyConfigured('Error importing modifier %s: "%s"' % (mod_module, e))
            try:
                mod_class = getattr(mod, mod_classname)
            except AttributeError:
                raise exceptions.ImproperlyConfigured('Price modifier module "%s" does not define a "%s" class' % (mod_module, mod_classname))
            try:
                mod_instance = mod_class()
            except exceptions.MiddlewareNotUsed:
{'fraction_non_alphanumeric': 0.08545269582909461, 'fraction_numerical': 0.0013563919972872161, 'mean_word_length': 2.274139844617092, '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': '7563072', 'n_tokens_mistral': 819, 'n_tokens_neox': 777, 'n_words': 198}