def _buildhdr(keymap, rec):
    """
    Map attributes in rec into a dictionary, with keyname translations applied.

    Raises
    ------
    AttributeError
        rec does not have attributes (is None?)

    """
    hdr = {}
    for key1, key2 in keymap.items():
        try:
            hdr[key1] = getattr(rec, key2)
        except AttributeError:
            pass
    return hdr
