def _map_header(keymap, dold, nulldict=None):
    """
    Returns a dictionary of values from dictionary dold,
    mapped to new key, if provided.

    Parameters
    ----------
    keymap: dict
        The map between old and new dictionary keys.
        Of the form {oldkey: newkey, ...}
    dold: dict
        The values to hand over.
    nulldict: dict, optional
        Dictionary representing null values in source dictionary.
        Matching values will not be transferred.

    Returns: dict

    """
    dnew = {}
    if nulldict:
        for oldkey, newkey in keymap.items():
            try:
                if dold[oldkey] != nulldict[oldkey]:
                    if isinstance(dold[oldkey], str):
                        dnew[newkey] = dold[oldkey].strip()
                    else:
                        dnew[newkey] = dold[oldkey]
            except KeyError:
                pass
    else:
        for oldkey, newkey in keymap.items():
            try:
                if isinstance(dold[oldkey], str):
                    dnew[newkey] = dold[oldkey].strip()
                else:
                    dnew[newkey] = dold[oldkey]
            except KeyError:
                pass
    return dnew
