<commit_before>import logging
import os

from ConfigParser import ConfigParser, Error as ConfigParserError
from decimal import Decimal

from django import forms
from django.conf import settings as django_settings
from django.utils import importlib


__all__ = ('AVAILABLE_SETTINGS', 'parse_config')


DEFAULT_SETTINGS_FILENAME = 'settings.cfg'
logger = logging.getLogger('setman')


class Setting(object):
    """
    Base class for setting values that can provided in configuration definition
    file.
    """
    default = None
    field_args = ('label', 'help_text', 'initial', 'validators')
    field_klass = None
    field_kwargs = {}
    help_text = None
    label = None
    name = None
    type = None
    validators = None

    def __init__(self, **kwargs):
        restricted = ('field_klass', 'field_args', 'field_kwargs')

        for key, _ in kwargs.items():
            if not hasattr(self, key):
                kwargs.pop(key)

            if key in restricted:
                kwargs.pop(key)

        self.__dict__.update(kwargs)
        self.validators = self._parse_validators(self.validators)

    def __repr__(self):
        return u'<%s: %s>' % (self.__class__.__name__, self.__unicode__())

    def __unicode__(self):
        return u'%s = %r' % (self.name, self.initial)

    @property
    def initial(self):
        """
        Read real setting value from database or if impossible - just send
        default setting value.
        """
        from setman import settings
        return getattr(settings, self.name, self.default)

    def to_field(self):
        """
        Convert current setting instance to form field.
        """
        if not self.field_klass:
            raise ValueError('Please, supply `field_klass` attribute first.')

        kwargs = {}

        for arg in self.field_args:
            kwargs.update({arg: getattr(self, arg)})

        kwargs.update(**self.field_kwargs)
        logger.warning('%s, %s', self.name, kwargs)
        return self.field_klass(**kwargs)

    def to_python(self, value):
        """
        Convert setting value to necessary Python type. By default, returns
        same value without any conversion.<commit_msg>Feature #4791: Remove unnecessary logging statement.<commit_after>import logging
import os

from ConfigParser import ConfigParser, Error as ConfigParserError
from decimal import Decimal

from django import forms
from django.conf import settings as django_settings
from django.utils import importlib


__all__ = ('AVAILABLE_SETTINGS', 'parse_config')


DEFAULT_SETTINGS_FILENAME = 'settings.cfg'
logger = logging.getLogger('setman')


class Setting(object):
    """
    Base class for setting values that can provided in configuration definition
    file.
    """
    default = None
    field_args = ('label', 'help_text', 'initial', 'validators')
    field_klass = None
    field_kwargs = {}
    help_text = None
    label = None
    name = None
    type = None
    validators = None

    def __init__(self, **kwargs):
        restricted = ('field_klass', 'field_args', 'field_kwargs')

        for key, _ in kwargs.items():
            if not hasattr(self, key):
                kwargs.pop(key)

            if key in restricted:
                kwargs.pop(key)

        self.__dict__.update(kwargs)
        self.validators = self._parse_validators(self.validators)

    def __repr__(self):
        return u'<%s: %s>' % (self.__class__.__name__, self.__unicode__())

    def __unicode__(self):
        return u'%s = %r' % (self.name, self.initial)

    @property
    def initial(self):
        """
        Read real setting value from database or if impossible - just send
        default setting value.
        """
        from setman import settings
        return getattr(settings, self.name, self.default)

    def to_field(self):
        """
        Convert current setting instance to form field.
        """
        if not self.field_klass:
            raise ValueError('Please, supply `field_klass` attribute first.')

        kwargs = {}

        for arg in self.field_args:
            kwargs.update({arg: getattr(self, arg)})

        kwargs.update(**self.field_kwargs)
        return self.field_klass(**kwargs)

    def to_python(self, value):
        """
        Convert setting value to necessary Python type. By default, returns
        same value without any conversion.
{'fraction_non_alphanumeric': 0.0975609756097561, 'fraction_numerical': 0.0009117848187827673, 'mean_word_length': 2.5703824247355573, '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': '2433661', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1184, 'n_words': 368}