<commit_before>#!/usr/bin/env python

"""
``Config`` module holds all the configuration-related implementations 
used in ``listdb`` package.

"""

import ConfigParser
import os
from ..utils import die_msg, PROG_NAME

class PdaConfig(object):
    """
    ``PdaConfig`` is a class which implements configuration abstraction 
    for ``ListDB`` class in ``GithubIssues`` module.

    """

    DEFAULTS = {
        'database-path': '/tmp/.pdastore',
        'username'     : None,
        'repo-name'    : None,
        'auth-token'   : None
    }

    def __init__(self, test_cfg=None):
        """
        :param test_cfg: :class: `file <file>` object or None
        """

        try:
            # load configurations from several possible locations
            self.__config = ConfigParser.RawConfigParser(self.DEFAULTS)

            if not test_cfg:
                self.__config.read([os.path.expanduser('~/.pdaconfig')])
            else:
                self.__config.readfp(test_cfg)

        except ConfigParser.ParsingError, err:
            # crash pda when configuration file is ill-formatted
            die_msg(PROG_NAME, msg=err)

    @property
    def local_db_path(self):
        """local_db_path attribute getter
        """
<commit_msg>adapted code to support both python 2 and 3<commit_after>#!/usr/bin/env python

"""
``Config`` module holds all the configuration-related implementations 
used in ``listdb`` package.

"""

try:
    import configparser as ConfigParser # python 3.3, 3.4
except ImportError:
    import ConfigParser # python 2.6, 2.7

import os
from ..utils import die_msg, PROG_NAME

class PdaConfig(object):
    """
    ``PdaConfig`` is a class which implements configuration abstraction 
    for ``ListDB`` class in ``GithubIssues`` module.

    """

    DEFAULTS = {
        'database-path': '/tmp/.pdastore',
        'username'     : None,
        'repo-name'    : None,
        'auth-token'   : None
    }

    def __init__(self, test_cfg=None):
        """
        :param test_cfg: :class: `file <file>` object or None
        """

        try:
            # load configurations from several possible locations
            self.__config = ConfigParser.RawConfigParser(self.DEFAULTS)

            if not test_cfg:
                self.__config.read([os.path.expanduser('~/.pdaconfig')])
            else:
                self.__config.readfp(test_cfg)

        except ConfigParser.ParsingError as err:
            # crash pda when configuration file is ill-formatted
            die_msg(PROG_NAME, msg=err)

    @property
    def local_db_path(self):
        """local_db_path attribute getter
        """

{'fraction_non_alphanumeric': 0.11081694402420575, 'fraction_numerical': 0.0037821482602118004, 'mean_word_length': 2.2816377171215882, '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': '4186112', 'n_tokens_mistral': 787, 'n_tokens_neox': 755, 'n_words': 204}