'Returns a list of `astropy.io.fits.card.Card` objects.
This function will return the desired header cards, taking into
account the user\'s preference to see the compressed or uncompressed
version.
Parameters
hdukey : int or str
Key of a single HDU in the HDUList.
keywords : list of str, optional
Keywords for which the cards should be returned.
compressed : boolean, optional
If True, shows the header describing the compression.
Raises
ExtensionNotFoundException
If the hdukey does not correspond to an extension.'

def _get_cards(self, hdukey, keywords, compressed):

    try:
        if compressed:
            header = self._hdulist[hdukey]._header
        else:
            header = self._hdulist[hdukey].header
    except (IndexError, KeyError):
        message = '{0}:    Extension    {1}    not    found.'.format(self.filename, hdukey)
        log.warning(message)
        raise ExtensionNotFoundException(message)
    if (not keywords):
        cards = header.cards
    else:
        cards = []
        for kw in keywords:
            try:
                crd = header.cards[kw]
                if isinstance(crd, fits.card.Card):
                    cards.append(crd)
                else:
                    cards.extend(crd)
            except KeyError as e:
                log.warning('{filename}    (HDU    {hdukey}):    Keyword    {kw}    not    found.'.format(filename=self.filename, hdukey=hdukey, kw=kw))
    return cards
