def _dict_diff(old, new):
    """
    Compares two dicts, returning two iterables: the keys that have been added
    or changed, and the keys that have been deleted.
    """
    oldkeys = set(old.keys())
    newkeys = set(new.keys())
    changed = newkeys - oldkeys
    deleted = oldkeys - newkeys
    for key in newkeys & oldkeys:
        if new[key] != old[key]:
            changed.add(key)

    assert len(changed & deleted) == 0
    return changed, deleted