def update(config1, config2):
    """Merges configs 1 and 2 by section, which (unlike dict.update()) ensures
       no fields in overlapping sections are lost. Result is in effect the
       union of settings from both files, with settings from config2 overriding
       those in config1. Does not modify either original config dictionary.
    """
    config3 = config1.copy()
    for section in config2.keys():
        if section in config3:
            config3[section].update(config2[section])
        else:
            config3[section] = config2[section]
    return config3