<commit_before>from ConfigParser import SafeConfigParser
import os
import sys

REQUIRED_KEYS = [
    'access_key',
    'secret_key',
    'associate_tag',
    'locale',
]

BOTO_FILES = [
    '/etc/boto.cfg',
    '~/.boto',
]
CONFIG_FILES = [
    '/etc/amazon-product-api.cfg',
    '~/.amazon-product-api'
]


def load_boto_config():
    """
    Loads config dict from a boto config file [#]_ found in ``/etc/boto.cfg``
    or ``~/.boto``. A boto config file looks like this::

        [Credentials]
        aws_access_key_id = <your access key>
        aws_secret_access_key = <your secret key>

    Note that the only config section that will be used in ``Credentials``.

    .. _#: http://code.google.com/p/boto/wiki/BotoConfig
    """
    config = SafeConfigParser()
    config.read(BOTO_FILES)

    mapper = {
        'access_key': 'aws_access_key_id',
        'secret_key': 'aws_secret_access_key',
    }
    return dict(
        (key, config.get('Credentials', boto))
        for key, boto in mapper.items()
        if config.has_option('Credentials', boto)
    )


def load_file_config():
    """
    Loads dict from config files ``/etc/amazon-product-api.cfg`` or
    ``~/.amazon-product-api``. ::

        [Credentials]
        access_key = <your access key>
        secret_key = <your secret key>
        locale = us

    """
    config = SafeConfigParser()
    config.read(CONFIG_FILES)

    if not config.has_section('Credentials'):
        return {}
    return dict((key, val) for key, val in config.items('Credentials'))


def load_environment_config():
    """
    Loads config dict from environmental variables (if set):

    * AWS_ACCESS_KEY
    * AWS_SECRET_ACCESS_KEY
    * AWS_ASSOCIATE_TAG
    * AWS_LOCALE
    """
    mapper = {
        'access_key': 'AWS_ACCESS_KEY',
        'secret_key': 'AWS_SECRET_ACCESS_KEY',
        'associate_tag': 'AWS_ASSOCIATE_TAG',
        'locale': 'AWS_LOCALE',
    }
    return dict(
        (key, os.environ.get(val))
        for key, val in mapper.items()
        if os.environ.has_key(val)
    )<commit_msg>Bugfix: Expand user paths for config files.<commit_after>from ConfigParser import SafeConfigParser
import os
import sys

REQUIRED_KEYS = [
    'access_key',
    'secret_key',
    'associate_tag',
    'locale',
]

BOTO_FILES = [
    '/etc/boto.cfg',
    '~/.boto',
]
CONFIG_FILES = [
    '/etc/amazon-product-api.cfg',
    '~/.amazon-product-api'
]


def load_boto_config():
    """
    Loads config dict from a boto config file [#]_ found in ``/etc/boto.cfg``
    or ``~/.boto``. A boto config file looks like this::

        [Credentials]
        aws_access_key_id = <your access key>
        aws_secret_access_key = <your secret key>

    Note that the only config section that will be used in ``Credentials``.

    .. _#: http://code.google.com/p/boto/wiki/BotoConfig
    """
    config = SafeConfigParser()
    config.read([os.path.expandvars(path) for path in BOTO_FILES])

    mapper = {
        'access_key': 'aws_access_key_id',
        'secret_key': 'aws_secret_access_key',
    }
    return dict(
        (key, config.get('Credentials', boto))
        for key, boto in mapper.items()
        if config.has_option('Credentials', boto)
    )


def load_file_config():
    """
    Loads dict from config files ``/etc/amazon-product-api.cfg`` or
    ``~/.amazon-product-api``. ::

        [Credentials]
        access_key = <your access key>
        secret_key = <your secret key>
        locale = us

    """
    config = SafeConfigParser()
    config.read([os.path.expandvars(path) for path in CONFIG_FILES])

    if not config.has_section('Credentials'):
        return {}
    return dict((key, val) for key, val in config.items('Credentials'))


def load_environment_config():
    """
    Loads config dict from environmental variables (if set):

    * AWS_ACCESS_KEY
    * AWS_SECRET_ACCESS_KEY
    * AWS_ASSOCIATE_TAG
    * AWS_LOCALE
    """
    mapper = {
        'access_key': 'AWS_ACCESS_KEY',
        'secret_key': 'AWS_SECRET_ACCESS_KEY',
        'associate_tag': 'AWS_ASSOCIATE_TAG',
        'locale': 'AWS_LOCALE',
    }
    return dict(
        (key, os.environ.get(val))
        for key, val in mapper.items()
        if os.environ.has_key(val)
    )
{'fraction_non_alphanumeric': 0.13172804532577903, 'fraction_numerical': 0.0, 'mean_word_length': 2.6090289608177173, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5072564', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1426, 'n_words': 322}