<commit_before># encoding: UTF-8

"""
Utilities for handling configuration file.
"""

from __future__ import print_function

import os.path, json

from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError


OPTION_BETA = "beta"

OPTION_LENGTH = "length"

OPTION_VOLTAGE = "voltage"

OPTION_FREQUENCY = "frequency"

OPTION_DIAMETER = "diameter"

OPTION_SETTINGS_FILE = "settings_file"

OPTION_XLF_FILE = "xlf_file"

OPTION_FIELD_DATA_DIR = "impact_rfdata_dir"


class Configuration(SafeConfigParser):
    """
    Configuration wrapps the standand python config parser
    to provide convenient helper methods.
    """
    
    _DEFAULT_SECTION = "DEFAULT"

    def get_default(self, option):
        return self.get(self._DEFAULT_SECTION, option)

    def getint_default(self, option):
        return self.getint(self._DEFAULT_SECTION, option)

    def getfloat_default(self, option):
        return self.getfloat(self._DEFAULT_SECTION, option)

    def has_default(self, option):
        return self.has_option(self._DEFAULT_SECTION, option)

    def get(self, section, option, check_default=True):
        if self.has_option(section, option, False):
            return SafeConfigParser.get(self, section, option)
        elif check_default and self.has_default(option):
            return self.get_default(option)
        elif not self.has_section(section):
            raise NoSectionError("No section found: " + str(section))
        else:
            raise NoOptionError("No option found: " + str(option))

    def getint(self, section, option, check_default=True):
        if self.has_option(section, option, False):
            return SafeConfigParser.getint(self, section, option)
        elif check_default and self.has_default(option):
            return self.getint_default(option)
        elif not self.has_section(section):
            raise NoSectionError("No section found: " + str(section))
        else:
            raise NoOptionError("No option found: " + str(option))

    def getfloat(self, section, option, check_default=True):
        if self.has_option(section, option, False):
            return SafeConfigParser.getfloat(self, section, option)
        elif check_default and self.has_default(option):
            return self.getfloat_default(option)
        elif not self.has_section(section):
            raise NoSectionError("No section found: " + str(section))
        else:
            raise NoOptionError("No option found: " + str(option))


    def has_option(self, section, option, check_default=True):
        return SafeConfigParser.has_option(self, section, option) or (check_default and self.has_default(option))



class FactoryWithConfig(object):
    """
    FactoryWithConfig is base class for building configuration based factories.
    """
    def __init__(self, config=None):
        if config != None:
            self.config = config
        else:
            self.config = Configuration()


    @property
    def config(self):
        return self._config

    @config.setter
    def config(self, config):
        if not isinstance(config, Configuration):
            raise TypeError("FactoryWithConfig: config must be of type Configuration")
        self._config = config<commit_msg>Remove unused helper class, FactoryWithConfig, from configuration module.<commit_after># encoding: UTF-8

"""
Utilities for handling configuration file.
"""

from __future__ import print_function

import os.path, json

from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError


OPTION_BETA = "beta"

OPTION_LENGTH = "length"

OPTION_VOLTAGE = "voltage"

OPTION_FREQUENCY = "frequency"

OPTION_DIAMETER = "diameter"

OPTION_SETTINGS_FILE = "settings_file"

OPTION_XLF_FILE = "xlf_file"

OPTION_FIELD_DATA_DIR = "impact_rfdata_dir"


class Configuration(SafeConfigParser):
    """
    Configuration wrapps the standand python config parser
    to provide convenient helper methods.
    """
    
    _DEFAULT_SECTION = "DEFAULT"

    def get_default(self, option):
        return self.get(self._DEFAULT_SECTION, option)

    def getint_default(self, option):
        return self.getint(self._DEFAULT_SECTION, option)

    def getfloat_default(self, option):
        return self.getfloat(self._DEFAULT_SECTION, option)

    def has_default(self, option):
        return self.has_option(self._DEFAULT_SECTION, option)

    def get(self, section, option, check_default=True):
        if self.has_option(section, option, False):
            return SafeConfigParser.get(self, section, option)
        elif check_default and self.has_default(option):
            return self.get_default(option)
        elif not self.has_section(section):
            raise NoSectionError("No section found: " + str(section))
        else:
            raise NoOptionError("No option found: " + str(option))

    def getint(self, section, option, check_default=True):
        if self.has_option(section, option, False):
            return SafeConfigParser.getint(self, section, option)
        elif check_default and self.has_default(option):
            return self.getint_default(option)
        elif not self.has_section(section):
            raise NoSectionError("No section found: " + str(section))
        else:
            raise NoOptionError("No option found: " + str(option))

    def getfloat(self, section, option, check_default=True):
        if self.has_option(section, option, False):
            return SafeConfigParser.getfloat(self, section, option)
        elif check_default and self.has_default(option):
            return self.getfloat_default(option)
        elif not self.has_section(section):
            raise NoSectionError("No section found: " + str(section))
        else:
            raise NoOptionError("No option found: " + str(option))


    def has_option(self, section, option, check_default=True):
        return SafeConfigParser.has_option(self, section, option) or (check_default and self.has_default(option))


{'fraction_non_alphanumeric': 0.0903010033444816, 'fraction_numerical': 0.00033444816053511704, 'mean_word_length': 3.309077809798271, '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': '7422277', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1668, 'n_words': 429}