<commit_before>import configparser
import os

from predicthq.exceptions import ConfigError


CONFIG_LOCATIONS = (
    '/etc/predicthq.conf',
    os.path.join(os.path.expanduser('~'), '.predicthq', 'predicthq.conf'),
    os.path.join(os.getcwd(), 'predicthq.conf'),
)


class Config(object):

    _config_sections = (
        'endpoint',
        'oauth2',
        'logging',
    )

    _defaults = {
        "ENDPOINT_URL": "https://api.predicthq.com",
        "OAUTH2_CLIENT_ID": None,
        "OAUTH2_CLIENT_SECRET": None,
        "OAUTH2_SCOPE": None,
        "OAUTH2_ACCESS_TOKEN": None,
        "LOGGING_LOG_LEVEL": "WARNING",
    }

    _config = {}

    def __init__(self, *config_locations):
        self.load_defaults()
        self.load_defaults_from_locations(config_locations)
        self.load_defaults_from_environment()

    def load_defaults(self):
        for key, value in self._defaults.items():
            self._config[key] = value

    def load_defaults_from_locations(self, config_locations):
        cp = configparser.SafeConfigParser()
        for file_location in config_locations:
            if os.path.isfile(file_location):
                with open(file_location) as fp:
                    cp.readfp(fp)
                for section in self._config_sections:
                    try:
                        for key, value in cp.items(section):
                            self._config["{0}_{1}".format(section.upper(), key.upper())] = value
                    except configparser.NoSectionError:  # pragma: nocover<commit_msg>Address config parser warnings<commit_after>import configparser
import os

from predicthq.exceptions import ConfigError


CONFIG_LOCATIONS = (
    '/etc/predicthq.conf',
    os.path.join(os.path.expanduser('~'), '.predicthq', 'predicthq.conf'),
    os.path.join(os.getcwd(), 'predicthq.conf'),
)


class Config(object):

    _config_sections = (
        'endpoint',
        'oauth2',
        'logging',
    )

    _defaults = {
        "ENDPOINT_URL": "https://api.predicthq.com",
        "OAUTH2_CLIENT_ID": None,
        "OAUTH2_CLIENT_SECRET": None,
        "OAUTH2_SCOPE": None,
        "OAUTH2_ACCESS_TOKEN": None,
        "LOGGING_LOG_LEVEL": "WARNING",
    }

    _config = {}

    def __init__(self, *config_locations):
        self.load_defaults()
        self.load_defaults_from_locations(config_locations)
        self.load_defaults_from_environment()

    def load_defaults(self):
        for key, value in self._defaults.items():
            self._config[key] = value

    def load_defaults_from_locations(self, config_locations):
        cp = configparser.ConfigParser()
        for file_location in config_locations:
            if os.path.isfile(file_location):
                with open(file_location) as f:
                    cp.read_file(f)
                for section in self._config_sections:
                    try:
                        for key, value in cp.items(section):
                            self._config["{0}_{1}".format(section.upper(), key.upper())] = value
                    except configparser.NoSectionError:  # pragma: nocover
{'fraction_non_alphanumeric': 0.11373801916932907, 'fraction_numerical': 0.0044728434504792336, 'mean_word_length': 2.2751046025104604, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3470974', 'n_tokens_mistral': 980, 'n_tokens_neox': 939, 'n_words': 168}