def get_constants(module, prefix, named=True, unprefixed=True, valued=True,
    lowercase=True, value_only=False):
    """ Mapping of constants by several ways to specify them """
    result = {}
    for name in dir(module):
        if not name.startswith(prefix):
            continue
        shortname = name[len(prefix):]
        value = getattr(module, name)
        if value_only:
            item = value
        else:
            item = dict(value=value, name=name, shortname=shortname)
        if named:
            result[name] = item
            if lowercase:
                result[name.lower()] = item
        if unprefixed:
            result[shortname] = item
            if lowercase:
                result[shortname.lower()] = item
        if valued:
            result[value] = item
    return result
