import copy


def _confs_per_period(configs, keys):
    """Return a list of configs; each config in the given list is copied into one
    config per date in its date_index, and these configs have additional
    properties taken from that date_index based on the given keys.

    For exapmle, if a list of just one config is passed in, and its date_index
    has two periods in it, Jan 2007 and Feb 2007, then
    _confs_per_period(configs, ['year', 'month']) returns a list of 2 configs;
    in addition to the properties they initially had, the first has {'year':
    2007, 'month': 1} and the second has {'year': 2007, month: 2}.

    """
    confs = []

    for conf in configs:
        for date in conf['date_index']:
            c = copy.deepcopy(conf)
            for key in keys:
                c[key] = getattr(date, key)
            confs.append(c)

    return confs