import configparser
import re
import warnings


def read(fIni):
    """Reads an *.INI file object and returns a two-level dict of
       section: key: value collections.
    """
    parser = configparser.ConfigParser()
    parser.read_file(fIni)
    config = {}
    for section in parser.sections():
        fields = parser[section]
        config[section] = {}
        for k, v in fields.items():
            if re.match(r"^\d+$", v):
                config[section][k] = int(v)
            elif re.match(r"^\".+\"$", v):
                config[section][k] = v[1:-1]
            elif re.match(r"^(true|false)$", v.lower()):
                config[section][k] = v.lower() == "true"
            else:
                warnings.warn("Unparsable value for key '%s', skipping" % k)
    return config